forked from status-im/status-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profiler.go
40 lines (35 loc) · 935 Bytes
/
profiler.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
package profiling
import (
"fmt"
"net/http"
hpprof "net/http/pprof"
"github.com/ethereum/go-ethereum/log"
)
// Profiler runs and controls a HTTP pprof interface.
type Profiler struct {
server *http.Server
}
// NewProfiler creates an instance of the profiler with
// the given port.
func NewProfiler(port int) *Profiler {
mux := http.NewServeMux()
mux.HandleFunc("/debug/pprof/", hpprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", hpprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", hpprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", hpprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", hpprof.Trace)
p := Profiler{
server: &http.Server{
Addr: fmt.Sprintf(":%d", port),
Handler: mux,
},
}
return &p
}
// Go starts the HTTP pprof in the background.
func (p *Profiler) Go() {
go func() {
log.Info("debug server stopped", "err", p.server.ListenAndServe())
}()
log.Info("debug server started")
}