-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
pyroscope.go
60 lines (47 loc) · 1.62 KB
/
pyroscope.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 logger
import (
"runtime"
"github.com/pyroscope-io/client/pyroscope"
"github.com/smartcontractkit/chainlink/core/static"
)
// PyroscopeConfig represents the expected configuration for Pyroscope to properly work
type PyroscopeConfig interface {
PyroscopeServerAddress() string
PyroscopeAuthToken() string
PyroscopeEnvironment() string
AutoPprofBlockProfileRate() int
AutoPprofMutexProfileFraction() int
}
// StartPyroscope starts continuous profiling of the Chainlink Node
func StartPyroscope(cfg PyroscopeConfig) (*pyroscope.Profiler, error) {
runtime.SetBlockProfileRate(cfg.AutoPprofBlockProfileRate())
runtime.SetMutexProfileFraction(cfg.AutoPprofMutexProfileFraction())
sha, ver := static.Short()
return pyroscope.Start(pyroscope.Config{
// Maybe configurable to identify the specific NOP - TBD
ApplicationName: "chainlink-node",
ServerAddress: cfg.PyroscopeServerAddress(),
AuthToken: cfg.PyroscopeAuthToken(),
// We disable logging the profiling info, it will be in the Pyroscope instance anyways...
Logger: nil,
Tags: map[string]string{
"SHA": sha,
"Version": ver,
"Environment": cfg.PyroscopeEnvironment(),
},
ProfileTypes: []pyroscope.ProfileType{
// these profile types are enabled by default:
pyroscope.ProfileCPU,
pyroscope.ProfileAllocObjects,
pyroscope.ProfileAllocSpace,
pyroscope.ProfileInuseObjects,
pyroscope.ProfileInuseSpace,
// these profile types are optional:
pyroscope.ProfileGoroutines,
pyroscope.ProfileMutexCount,
pyroscope.ProfileMutexDuration,
pyroscope.ProfileBlockCount,
pyroscope.ProfileBlockDuration,
},
})
}