github.com/ethereum/go-ethereum@v1.16.1/metrics/gauge_float64.go (about) 1 package metrics 2 3 import ( 4 "math" 5 "sync/atomic" 6 ) 7 8 // GetOrRegisterGaugeFloat64 returns an existing GaugeFloat64 or constructs and registers a 9 // new GaugeFloat64. 10 func GetOrRegisterGaugeFloat64(name string, r Registry) *GaugeFloat64 { 11 return getOrRegister(name, NewGaugeFloat64, r) 12 } 13 14 // GaugeFloat64Snapshot is a read-only copy of a GaugeFloat64. 15 type GaugeFloat64Snapshot float64 16 17 // Value returns the value at the time the snapshot was taken. 18 func (g GaugeFloat64Snapshot) Value() float64 { return float64(g) } 19 20 // NewGaugeFloat64 constructs a new GaugeFloat64. 21 func NewGaugeFloat64() *GaugeFloat64 { 22 return new(GaugeFloat64) 23 } 24 25 // NewRegisteredGaugeFloat64 constructs and registers a new GaugeFloat64. 26 func NewRegisteredGaugeFloat64(name string, r Registry) *GaugeFloat64 { 27 c := NewGaugeFloat64() 28 if nil == r { 29 r = DefaultRegistry 30 } 31 r.Register(name, c) 32 return c 33 } 34 35 // GaugeFloat64 hold a float64 value that can be set arbitrarily. 36 type GaugeFloat64 atomic.Uint64 37 38 // Snapshot returns a read-only copy of the gauge. 39 func (g *GaugeFloat64) Snapshot() GaugeFloat64Snapshot { 40 v := math.Float64frombits((*atomic.Uint64)(g).Load()) 41 return GaugeFloat64Snapshot(v) 42 } 43 44 // Update updates the gauge's value. 45 func (g *GaugeFloat64) Update(v float64) { 46 (*atomic.Uint64)(g).Store(math.Float64bits(v)) 47 }