-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathoverhead.go
62 lines (49 loc) · 1.34 KB
/
overhead.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
package benches
import (
"context"
"sort"
"time"
"github.com/estesp/bucketbench/stats"
log "github.com/sirupsen/logrus"
)
const (
procMetricsSampleInterval = 500 * time.Millisecond
)
// OverheadBench runs CustomBench benchmarks and measure memory and cpu usage of a container daemon
type OverheadBench struct {
*CustomBench
cgroupPath string
}
// Run executes the benchmark iterations against a specific engine driver type
// for a specified number of iterations
func (b *OverheadBench) Run(ctx context.Context, threads, iterations int, commands []string) error {
sampler, err := stats.NewSampler(b.driver, b.cgroupPath)
if err != nil {
log.WithError(err).Error("failed to create stats sampler")
return err
}
var metrics []RunStatistics
ticker := time.NewTicker(procMetricsSampleInterval)
go func() {
for range ticker.C {
result, err := sampler.Query()
if err != nil {
log.WithError(err).Error("stats sample failed")
continue
}
stat := RunStatistics{
Timestamp: time.Now().UTC(),
Daemon: result,
}
metrics = append(metrics, stat)
}
}()
err = b.CustomBench.Run(ctx, threads, iterations, commands)
// Stop gathering metrics
ticker.Stop()
b.stats = append(b.stats, metrics...)
sort.Slice(b.stats, func(i, j int) bool {
return b.stats[i].Timestamp.Before(b.stats[j].Timestamp)
})
return err
}