-
Notifications
You must be signed in to change notification settings - Fork 26
/
pprof.go
45 lines (39 loc) · 1.19 KB
/
pprof.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package yee
import (
"net/http"
"net/http/pprof"
)
const DefaultPrefix = "/debug/pprof"
func getPrefix(prefixOptions string) string {
prefix := DefaultPrefix
if len(prefixOptions) > 1 {
prefix = "/debug" + prefixOptions
}
return prefix
}
func WrapF(f http.HandlerFunc) HandlerFunc {
return func(c Context) (err error) {
f(c.Response(), c.Request())
return nil
}
}
func WrapH(h http.Handler) HandlerFunc {
return func(c Context) (err error) {
h.ServeHTTP(c.Response(), c.Request())
return nil
}
}
func (c *Core) Pprof() {
c.GET(getPrefix("/"), WrapF(pprof.Index))
c.GET(getPrefix("/cmdline"), WrapF(pprof.Cmdline))
c.GET(getPrefix("/profile"), WrapF(pprof.Profile))
c.POST(getPrefix("/symbol"), WrapF(pprof.Symbol))
c.GET(getPrefix("/symbol"), WrapF(pprof.Symbol))
c.GET(getPrefix("/trace"), WrapF(pprof.Trace))
c.GET(getPrefix("/allocs"), WrapH(pprof.Handler("allocs")))
c.GET(getPrefix("/block"), WrapH(pprof.Handler("block")))
c.GET(getPrefix("/goroutine"), WrapH(pprof.Handler("goroutine")))
c.GET(getPrefix("/heap"), WrapH(pprof.Handler("heap")))
c.GET(getPrefix("/mutex"), WrapH(pprof.Handler("mutex")))
c.GET(getPrefix("/threadcreate"), WrapH(pprof.Handler("threadcreate")))
}