-
Notifications
You must be signed in to change notification settings - Fork 0
/
pprof.go
42 lines (38 loc) · 1.05 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
package pprof
import (
"errors"
"net/http/pprof"
"github.com/felixge/fgprof"
"github.com/gofiber/fiber/v2"
"github.com/pubgo/lava/core/debug"
)
func init() {
debug.Get("/gprof", debug.Wrap(fgprof.Handler()))
debug.Route("/pprof", func(r fiber.Router) {
r.Get("/", debug.WrapFunc(pprof.Index))
r.Get("/:name", func(ctx *fiber.Ctx) error {
var name = ctx.Params("name")
switch name {
case "cmdline":
return debug.WrapFunc(pprof.Cmdline)(ctx)
case "profile":
return debug.WrapFunc(pprof.Profile)(ctx)
case "symbol":
return debug.WrapFunc(pprof.Symbol)(ctx)
case "trace":
return debug.WrapFunc(pprof.Trace)(ctx)
case "allocs":
return debug.Wrap(pprof.Handler("allocs"))(ctx)
case "goroutine":
return debug.Wrap(pprof.Handler("goroutine"))(ctx)
case "heap":
return debug.Wrap(pprof.Handler("heap"))(ctx)
case "mutex":
return debug.Wrap(pprof.Handler("mutex"))(ctx)
case "threadcreate":
return debug.Wrap(pprof.Handler("threadcreate"))(ctx)
}
return errors.New("name not found")
})
})
}