-
Notifications
You must be signed in to change notification settings - Fork 0
/
pprof.go
55 lines (47 loc) · 1.68 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
46
47
48
49
50
51
52
53
54
55
package plum
import (
"net/http"
"net/http/pprof"
)
const (
// DefaultPrefix url prefix of pprof
DefaultPrefix = "/debug/pprof"
)
func getPrefix(prefixOptions ...string) string {
prefix := DefaultPrefix
if len(prefixOptions) > 0 {
prefix = prefixOptions[0]
}
return prefix
}
// RoutePerf the standard HandlerFuncs from the net/http/pprof package with
// the provided gin.GrouterGroup. prefixOptions is a optional. If not prefixOptions,
// the default path prefix is used, otherwise first prefixOptions will be path prefix.
func RoutePerf(rg *Router, prefixOptions ...string) {
prefix := getPrefix(prefixOptions...)
prefixRouter := rg.Group(prefix)
{
prefixRouter.GET("/", pprofHandlerFunc(pprof.Index))
prefixRouter.GET("/cmdline", pprofHandlerFunc(pprof.Cmdline))
prefixRouter.GET("/profile", pprofHandlerFunc(pprof.Profile))
prefixRouter.POST("/symbol", pprofHandlerFunc(pprof.Symbol))
prefixRouter.GET("/symbol", pprofHandlerFunc(pprof.Symbol))
prefixRouter.GET("/trace", pprofHandlerFunc(pprof.Trace))
prefixRouter.GET("/allocs", pprofHandler(pprof.Handler("allocs")))
prefixRouter.GET("/block", pprofHandler(pprof.Handler("block")))
prefixRouter.GET("/goroutine", pprofHandler(pprof.Handler("goroutine")))
prefixRouter.GET("/heap", pprofHandler(pprof.Handler("heap")))
prefixRouter.GET("/mutex", pprofHandler(pprof.Handler("mutex")))
prefixRouter.GET("/threadcreate", pprofHandler(pprof.Handler("threadcreate")))
}
}
func pprofHandlerFunc(h http.HandlerFunc) HandlerFunc {
return func(ctx *Context) {
h.ServeHTTP(ctx.Writer, ctx.Request)
}
}
func pprofHandler(h http.Handler) HandlerFunc {
return func(ctx *Context) {
h.ServeHTTP(ctx.Writer, ctx.Request)
}
}