@@ -48,6 +48,9 @@ type options struct {
48
48
// move may result of the system crash.
49
49
CPUMaxPercent int
50
50
51
+ // cpu sampling time
52
+ CPUSamplingTime time.Duration
53
+
51
54
// if write lock is held mean holmes's
52
55
// configuration is being modified.
53
56
L * sync.RWMutex
@@ -173,6 +176,7 @@ func newOptions() *options {
173
176
threadOpts : newThreadOptions (),
174
177
CollectInterval : defaultInterval ,
175
178
intervalResetting : make (chan struct {}, 1 ),
179
+ CPUSamplingTime : defaultCPUSamplingTime ,
176
180
DumpOptions : & DumpOptions {
177
181
DumpPath : defaultDumpPath ,
178
182
DumpProfileType : defaultDumpProfileType ,
@@ -230,6 +234,26 @@ func WithCPUMax(max int) Option {
230
234
})
231
235
}
232
236
237
+ // WithCPUSamplingTime set cpu sampling time
238
+ func WithCPUSamplingTime (duration string ) Option {
239
+ return optionFunc (func (opts * options ) (err error ) {
240
+ // CPUSamplingTime wouldn't be zero value, because it
241
+ // will be initialized as defaultInterval at newOptions()
242
+ newDuration , err := time .ParseDuration (duration )
243
+ if err != nil {
244
+ return
245
+ }
246
+
247
+ if newDuration <= 0 {
248
+ newDuration = defaultInterval
249
+ }
250
+
251
+ opts .CPUSamplingTime = newDuration
252
+
253
+ return
254
+ })
255
+ }
256
+
233
257
// WithBinaryDump set dump mode to binary.
234
258
func WithBinaryDump () Option {
235
259
return withDumpProfileType (binaryDump )
@@ -320,8 +344,8 @@ func (base *typeOption) Set(min, abs, diff int, coolDown time.Duration) {
320
344
321
345
// newMemOptions
322
346
// enable the heap dumper, should dump if one of the following requirements is matched
323
- // 1. memory usage > TriggerMin && memory usage diff > TriggerDiff
324
- // 2. memory usage > TriggerAbs.
347
+ // 1. memory usage > TriggerMin && memory usage diff > TriggerDiff
348
+ // 2. memory usage > TriggerAbs.
325
349
func newMemOptions () * typeOption {
326
350
return newTypeOpts (
327
351
defaultMemTriggerMin ,
@@ -341,8 +365,9 @@ func WithMemDump(min int, diff int, abs int, coolDown time.Duration) Option {
341
365
342
366
// newGCHeapOptions
343
367
// enable the heap dumper, should dump if one of the following requirements is matched
344
- // 1. GC heap usage > TriggerMin && GC heap usage diff > TriggerDiff
345
- // 2. GC heap usage > TriggerAbs
368
+ // 1. GC heap usage > TriggerMin && GC heap usage diff > TriggerDiff
369
+ // 2. GC heap usage > TriggerAbs
370
+ //
346
371
// in percent.
347
372
func newGCHeapOptions () * typeOption {
348
373
return newTypeOpts (
@@ -398,8 +423,9 @@ func WithThreadDump(min, diff, abs int, coolDown time.Duration) Option {
398
423
// newCPUOptions
399
424
// enable the cpu dumper, should dump if one of the following requirements is matched
400
425
// in percent
401
- // 1. cpu usage > CPUTriggerMin && cpu usage diff > CPUTriggerDiff
402
- // 2. cpu usage > CPUTriggerAbs
426
+ // 1. cpu usage > CPUTriggerMin && cpu usage diff > CPUTriggerDiff
427
+ // 2. cpu usage > CPUTriggerAbs
428
+ //
403
429
// in percent.
404
430
func newCPUOptions () * typeOption {
405
431
return newTypeOpts (
0 commit comments