-
Notifications
You must be signed in to change notification settings - Fork 9
/
option.go
77 lines (66 loc) · 2.37 KB
/
option.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
68
69
70
71
72
73
74
75
76
77
package autopprof
import (
"time"
"github.com/daangn/autopprof/report"
)
const (
defaultCPUThreshold = 0.75
defaultMemThreshold = 0.75
defaultGoroutineThreshold = 50000
defaultWatchInterval = 5 * time.Second
defaultCPUProfilingDuration = 10 * time.Second
defaultMinConsecutiveOverThreshold = 12 // min 1 minute. (12*5s)
)
// Option is the configuration for the autopprof.
type Option struct {
// DisableCPUProf disables the CPU profiling.
DisableCPUProf bool
// DisableMemProf disables the memory profiling.
DisableMemProf bool
// DisableGoroutineProf disables the goroutine profiling.
DisableGoroutineProf bool
// CPUThreshold is the cpu usage threshold (between 0 and 1)
// to trigger the cpu profiling.
// Autopprof will start the cpu profiling when the cpu usage
// is higher than this threshold.
CPUThreshold float64
// MemThreshold is the memory usage threshold (between 0 and 1)
// to trigger the heap profiling.
// Autopprof will start the heap profiling when the memory usage
// is higher than this threshold.
MemThreshold float64
// GoroutineThreshold is the goroutine count threshold to trigger the goroutine profiling.
// to trigger the goroutine profiling.
// Autopprof will start the goroutine profiling when the goroutine count
// is higher than this threshold.
GoroutineThreshold int
// deprecated: use reportAll instead.
// ReportBoth sets whether to trigger reports for both CPU and memory when either threshold is exceeded.
// If some profiling is disabled, exclude it.
ReportBoth bool
// ReportAll sets whether to trigger reports for all profiling types when any threshold is exceeded.
// If some profiling is disabled, exclude it.
ReportAll bool
// Reporter is the reporter to send the profiling report implementing
// the report.Reporter interface.
Reporter report.Reporter
}
// NOTE(mingrammer): testing the validate() is done in autopprof_test.go.
func (o Option) validate() error {
if o.DisableCPUProf && o.DisableMemProf && o.DisableGoroutineProf {
return ErrDisableAllProfiling
}
if o.CPUThreshold < 0 || o.CPUThreshold > 1 {
return ErrInvalidCPUThreshold
}
if o.MemThreshold < 0 || o.MemThreshold > 1 {
return ErrInvalidMemThreshold
}
if o.GoroutineThreshold < 0 {
return ErrInvalidGoroutineThreshold
}
if o.Reporter == nil {
return ErrNilReporter
}
return nil
}