@@ -67,28 +67,28 @@ func (h *History) ThrashingForStat(stat string) ThrashingSlice {
67
67
68
68
ths := make (ThrashingSlice , numStores )
69
69
for storeIdx := range vsByStore {
70
- sl := vsByStore [storeIdx ]
71
- // HACK: instead of the slice directly, we measure the thrashing of a slice
72
- // that has all leading zeroes removed. This works around the fact that some
73
- // timeseries only show sensible values after an initial period of
74
- // inactivity. For example, CPU usage is zero until the first stats tick.
75
- // Without this hack, the large initial jump from zero to the first value
76
- // would be interpreted as variation.
77
- noLeadingZeroes := sl
78
- for i := 0 ; i < len (sl ); i ++ {
79
- if sl [i ] == 0 {
80
- noLeadingZeroes = sl [i + 1 :]
81
- continue
82
- }
83
- break
84
- }
85
- th := computeThrashing (noLeadingZeroes )
70
+ // HACK: we remove leading zeroes before computing the thrashin This works
71
+ // around the fact that some timeseries only show sensible values after an
72
+ // initial period of inactivity. For example, CPU usage is zero until the
73
+ // first stats tick. Without this hack, the large initial jump from zero to
74
+ // the first value would be interpreted as variation.
75
+ th := computeThrashing (stripLeaderingZeroes (vsByStore [storeIdx ]))
86
76
ths [storeIdx ] = th
87
77
}
88
78
ths .normalize ()
89
79
return ths
90
80
}
91
81
82
+ func stripLeaderingZeroes (vs []float64 ) []float64 {
83
+ for i := range vs {
84
+ if vs [i ] == 0 {
85
+ continue
86
+ }
87
+ return vs [i :]
88
+ }
89
+ return nil
90
+ }
91
+
92
92
// Thrashing returns a string representation of the thrashing for the given
93
93
// stat.
94
94
func (h * History ) Thrashing (stat string ) string {
0 commit comments