github.com/MetalBlockchain/metalgo@v1.11.9/utils/math/meter/meter.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package meter 5 6 import "time" 7 8 // Meter tracks a continuous exponential moving average of the % of time this 9 // meter has been running. 10 type Meter interface { 11 // Inc the meter, the read value will be monotonically increasing while 12 // the meter is running. 13 Inc(time.Time, float64) 14 15 // Dec the meter, the read value will be exponentially decreasing while the 16 // meter is off. 17 Dec(time.Time, float64) 18 19 // Read the current value of the meter, this can be used to approximate the 20 // percent of time the meter has been running recently. The definition of 21 // recently depends on the halflife of the decay function. 22 Read(time.Time) float64 23 24 // Returns the duration between [now] and when the value of this meter 25 // reaches [value], assuming that the number of cores running is always 0. 26 // If the value of this meter is already <= [value], returns the zero duration. 27 TimeUntil(now time.Time, value float64) time.Duration 28 }