-
Notifications
You must be signed in to change notification settings - Fork 98
/
register.go
67 lines (60 loc) · 1.44 KB
/
register.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
67
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package debug
import (
"net/http"
"net/http/pprof"
)
// Options used to provide configuration options
type Options struct {
CmdLine bool
Profile bool
Symbol bool
Trace bool
}
// DefaultOptions returns default options configuration
func DefaultOptions() *Options {
return &Options{
CmdLine: true,
Profile: true,
Symbol: true,
Trace: true,
}
}
// RegisterEndpoint used to register the different debug endpoints
func RegisterEndpoint(register func(string, http.Handler) error, options *Options) error {
err := register("/debug/pprof", http.HandlerFunc(pprof.Index))
if err != nil {
return err
}
if options == nil {
options = DefaultOptions()
}
if options.CmdLine {
err := register("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
if err != nil {
return err
}
}
if options.Profile {
err := register("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
if err != nil {
return err
}
}
if options.Symbol {
err := register("/debug/pprof/symobol", http.HandlerFunc(pprof.Symbol))
if err != nil {
return err
}
}
if options.Trace {
err := register("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))
if err != nil {
return err
}
}
return nil
}