OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [net/] [rpc/] [debug.go] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2009 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
package rpc
6
 
7
/*
8
        Some HTML presented at http://machine:port/debug/rpc
9
        Lists services, their methods, and some statistics, still rudimentary.
10
*/
11
 
12
import (
13
        "fmt"
14
        "net/http"
15
        "sort"
16
        "text/template"
17
)
18
 
19
const debugText = `
20
        
21
        Services
22
        {{range .}}
23
        
24
        Service {{.Name}}
25
        
26
                
27
                
MethodCalls
28
                {{range .Method}}
29
                        
30
                        
{{.Name}}({{.Type.ArgType}}, {{.Type.ReplyType}}) error
31
                        
{{.Type.NumCalls}}
32
                        
33
                {{end}}
34
                
35
        {{end}}
36
        
37
        `
38
 
39
var debug = template.Must(template.New("RPC debug").Parse(debugText))
40
 
41
type debugMethod struct {
42
        Type *methodType
43
        Name string
44
}
45
 
46
type methodArray []debugMethod
47
 
48
type debugService struct {
49
        Service *service
50
        Name    string
51
        Method  methodArray
52
}
53
 
54
type serviceArray []debugService
55
 
56
func (s serviceArray) Len() int           { return len(s) }
57
func (s serviceArray) Less(i, j int) bool { return s[i].Name < s[j].Name }
58
func (s serviceArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
59
 
60
func (m methodArray) Len() int           { return len(m) }
61
func (m methodArray) Less(i, j int) bool { return m[i].Name < m[j].Name }
62
func (m methodArray) Swap(i, j int)      { m[i], m[j] = m[j], m[i] }
63
 
64
type debugHTTP struct {
65
        *Server
66
}
67
 
68
// Runs at /debug/rpc
69
func (server debugHTTP) ServeHTTP(w http.ResponseWriter, req *http.Request) {
70
        // Build a sorted version of the data.
71
        var services = make(serviceArray, len(server.serviceMap))
72
        i := 0
73
        server.mu.Lock()
74
        for sname, service := range server.serviceMap {
75
                services[i] = debugService{service, sname, make(methodArray, len(service.method))}
76
                j := 0
77
                for mname, method := range service.method {
78
                        services[i].Method[j] = debugMethod{method, mname}
79
                        j++
80
                }
81
                sort.Sort(services[i].Method)
82
                i++
83
        }
84
        server.mu.Unlock()
85
        sort.Sort(services)
86
        err := debug.Execute(w, services)
87
        if err != nil {
88
                fmt.Fprintln(w, "rpc: error executing template:", err.Error())
89
        }
90
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.