-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvmstats.go
46 lines (39 loc) · 1 KB
/
vmstats.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
package evms
import (
"time"
"sync/atomic"
"github.com/theQRL/gozvmlab/utils"
)
type VmStat struct {
// Some metrics
tracingSpeedWMA utils.SlidingAverage
longestTracingTime time.Duration
numExecs atomic.Uint64
}
// TraceDone marks the tracing speed metric, and returns 'true' if the test is
// 'slow'.
func (stat *VmStat) TraceDone(start time.Time) (time.Duration, bool) {
numexecs := stat.numExecs.Add(1)
duration := time.Since(start)
stat.tracingSpeedWMA.Add(int(duration))
if duration > stat.longestTracingTime {
stat.longestTracingTime = duration
// Don't count the first 500 runs, let it accumulate.
if numexecs > 500 {
return duration, true
}
}
return duration, false
}
func (stat *VmStat) Stats() []any {
return []interface{}{
"execSpeed", time.Duration(stat.tracingSpeedWMA.Avg()).Round(100 * time.Microsecond),
"longest", stat.longestTracingTime,
"count", stat.numExecs.Load(),
}
}
type tracingResult struct {
Slow bool
ExecTime time.Duration
Cmd string
}