-
Notifications
You must be signed in to change notification settings - Fork 0
/
prof.go
59 lines (48 loc) · 1.25 KB
/
prof.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
56
57
58
59
package ginx
import (
"github.com/gin-gonic/gin"
"net/http/pprof"
)
type ProfX struct {
*GinX
}
func (s *ProfX) handleIndex(c *gin.Context) {
pprof.Index(c.Writer, c.Request)
}
func (s *ProfX) handleCmdLine(c *gin.Context) {
pprof.Cmdline(c.Writer, c.Request)
}
func (s *ProfX) handleProfile(c *gin.Context) {
pprof.Profile(c.Writer, c.Request)
}
func (s *ProfX) handleSymbol(c *gin.Context) {
pprof.Symbol(c.Writer, c.Request)
}
func (s *ProfX) handleTrace(c *gin.Context) {
pprof.Trace(c.Writer, c.Request)
}
func (s *ProfX) genHandle(name string) gin.HandlerFunc {
return func(c *gin.Context) {
var f = pprof.Handler(name)
f.ServeHTTP(c.Writer, c.Request)
}
}
func (s *ProfX) setupRoutine() {
s.GET("/", s.handleIndex)
s.GET("/cmdline", s.handleCmdLine)
s.GET("/profile", s.handleProfile)
s.GET("/symbol", s.handleSymbol)
s.GET("/trace", s.handleTrace)
s.GET("/goroutine", s.genHandle(`goroutine`))
s.GET("/heap", s.genHandle(`heap`))
s.GET("/threadcreate", s.genHandle(`threadcreate`))
s.GET("/block", s.genHandle(`block`))
s.GET("/mutex", s.genHandle(`mutex`))
s.GET("/allocs", s.genHandle(`allocs`))
}
func NewProfX(addr string, opts ...OptionFn) *ProfX {
var p = &ProfX{}
p.GinX = New(addr, opts...)
p.setupRoutine()
return p
}