-
Notifications
You must be signed in to change notification settings - Fork 2
/
pprof.go
60 lines (45 loc) · 1.06 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
56
57
58
59
60
package pprof
import (
"context"
"github.com/americanas-go/ignite/labstack/echo.v4"
"github.com/americanas-go/log"
echopprof "github.com/hiko1129/echo-pprof"
)
func Register(ctx context.Context, server *echo.Server) error {
o, err := NewOptions()
if err != nil {
return nil
}
h := NewPProfWithOptions(o)
return h.Register(ctx, server)
}
type PProf struct {
options *Options
}
func NewPProfWithOptions(options *Options) *PProf {
return &PProf{options: options}
}
func NewPProfWithConfigPath(path string) (*PProf, error) {
o, err := NewOptionsWithPath(path)
if err != nil {
return nil, err
}
return NewPProfWithOptions(o), nil
}
func NewPProf() *PProf {
o, err := NewOptions()
if err != nil {
log.Fatalf(err.Error())
}
return NewPProfWithOptions(o)
}
func (i *PProf) Register(ctx context.Context, server *echo.Server) error {
if !i.options.Enabled {
return nil
}
logger := log.FromContext(ctx)
logger.Trace("configuring pprof in echo")
echopprof.Wrap(server.Instance())
logger.Debug("pprof configured with echo with success")
return nil
}