-
Notifications
You must be signed in to change notification settings - Fork 2
/
pprof.go
66 lines (51 loc) · 1.43 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
61
62
63
64
65
66
package pprof
import (
"context"
"github.com/americanas-go/ignite/labstack/echo.v4"
"github.com/americanas-go/log"
echopprof "github.com/hiko1129/echo-pprof"
)
// Register registers a new pprof plugin for echo server.
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)
}
// PProf represents pprof plugin for echo server.
type PProf struct {
options *Options
}
// NewPProfWithOptions returns a new pprof plugin with options.
func NewPProfWithOptions(options *Options) *PProf {
return &PProf{options: options}
}
// NewPProfWithConfigPath returns a new pprof plugin with options from config path.
func NewPProfWithConfigPath(path string) (*PProf, error) {
o, err := NewOptionsWithPath(path)
if err != nil {
return nil, err
}
return NewPProfWithOptions(o), nil
}
// NewPProf returns a new pprof plugin with default options.
func NewPProf() *PProf {
o, err := NewOptions()
if err != nil {
log.Fatalf(err.Error())
}
return NewPProfWithOptions(o)
}
// Register registers this pprof plugin for echo server.
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
}