Skip to content

Commit 262b708

Browse files
committed
resources: make maxsamples configurable
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 509cfa3 commit 262b708

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

executor/resources/monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (r *cgroupRecord) Start() {
5151
if stat, err := r.monitor.proc.Stat(); err == nil {
5252
r.startCPUStat = &stat.CPUTotal
5353
}
54-
s := NewSampler(2*time.Second, r.sample)
54+
s := NewSampler(2*time.Second, 10, r.sample)
5555
r.sampler = s.Record()
5656
r.closeSampler = s.Close
5757
}

executor/resources/sampler.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type WithTimestamp interface {
1212
type Sampler[T WithTimestamp] struct {
1313
mu sync.RWMutex
1414
minInterval time.Duration
15+
maxSamples int
1516
callback func(ts time.Time) (T, error)
1617
doneOnce sync.Once
1718
done chan struct{}
@@ -57,9 +58,10 @@ func (s *Sub[T]) Close(captureLast bool) ([]T, error) {
5758
return out, nil
5859
}
5960

60-
func NewSampler[T WithTimestamp](minInterval time.Duration, cb func(time.Time) (T, error)) *Sampler[T] {
61+
func NewSampler[T WithTimestamp](minInterval time.Duration, maxSamples int, cb func(time.Time) (T, error)) *Sampler[T] {
6162
s := &Sampler[T]{
6263
minInterval: minInterval,
64+
maxSamples: maxSamples,
6365
callback: cb,
6466
done: make(chan struct{}),
6567
subs: make(map[*Sub[T]]struct{}),
@@ -115,7 +117,7 @@ func (s *Sampler[T]) run() {
115117
ss.err = nil
116118
}
117119
dur := ss.last.Sub(ss.first)
118-
if time.Duration(ss.interval)*10 <= dur {
120+
if time.Duration(ss.interval)*time.Duration(s.maxSamples) <= dur {
119121
ss.interval *= 2
120122
}
121123
}

executor/resources/sys.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func NewSysSampler() (*Sampler[*types.SysSample], error) {
1616
return nil, err
1717
}
1818

19-
return NewSampler(2*time.Second, func(tm time.Time) (*types.SysSample, error) {
19+
return NewSampler(2*time.Second, 20, func(tm time.Time) (*types.SysSample, error) {
2020
return sampleSys(procfs, tm)
2121
}), nil
2222
}

0 commit comments

Comments
 (0)