Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 0d432c4

Browse files
committed
Partial workaround for meter during a clock jump
1 parent 2b57eb8 commit 0d432c4

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

meter.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,13 @@ func (m *StandardMeter) Snapshot() Meter {
190190
func (m *StandardMeter) updateSnapshot() {
191191
// should run with write lock held on m.lock
192192
snapshot := m.snapshot
193-
snapshot.rate1 = m.a1.Rate()
194-
snapshot.rate5 = m.a5.Rate()
195-
snapshot.rate15 = m.a15.Rate()
196-
snapshot.rateMean = float64(snapshot.count) / time.Since(m.startTime).Seconds()
193+
elapsed := time.Since(m.startTime).Seconds()
194+
if elapsed >= 0 {
195+
snapshot.rate1 = m.a1.Rate()
196+
snapshot.rate5 = m.a5.Rate()
197+
snapshot.rate15 = m.a15.Rate()
198+
snapshot.rateMean = float64(snapshot.count) / elapsed
199+
}
197200
}
198201

199202
func (m *StandardMeter) tick() {

0 commit comments

Comments
 (0)