mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
metrics: fix flaw re empty timer mean
This commit is contained in:
parent
abefcdc76d
commit
55c3396aac
1 changed files with 5 additions and 4 deletions
|
|
@ -80,11 +80,12 @@ type StandardResettingTimer struct {
|
||||||
func (t *StandardResettingTimer) Snapshot() ResettingTimerSnapshot {
|
func (t *StandardResettingTimer) Snapshot() ResettingTimerSnapshot {
|
||||||
t.mutex.Lock()
|
t.mutex.Lock()
|
||||||
defer t.mutex.Unlock()
|
defer t.mutex.Unlock()
|
||||||
snapshot := &resettingTimerSnapshot{
|
snapshot := &resettingTimerSnapshot{}
|
||||||
values: t.values,
|
if len(t.values) > 0 {
|
||||||
mean: float64(t.sum) / float64(len(t.values)),
|
snapshot.mean = float64(t.sum) / float64(len(t.values))
|
||||||
|
snapshot.values = t.values
|
||||||
|
t.values = make([]int64, 0, InitialResettingTimerSliceCap)
|
||||||
}
|
}
|
||||||
t.values = make([]int64, 0, InitialResettingTimerSliceCap)
|
|
||||||
t.sum = 0
|
t.sum = 0
|
||||||
return snapshot
|
return snapshot
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue