diff options
author | gary rong <garyrong0905@gmail.com> | 2018-09-17 20:32:34 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-09-17 20:32:34 +0800 |
commit | 5d1d1a808d92440a7c0efad77fa5527e4255e596 (patch) | |
tree | 5c083f2bf130abe21f37f024018b91912446c70c /metrics | |
parent | 41ac8dd803b646b5fa92354a983ee5df68253e2a (diff) | |
download | dexon-5d1d1a808d92440a7c0efad77fa5527e4255e596.tar.gz dexon-5d1d1a808d92440a7c0efad77fa5527e4255e596.tar.zst dexon-5d1d1a808d92440a7c0efad77fa5527e4255e596.zip |
consensus, ethdb, metrics: implement forced-meter (#17667)
Diffstat (limited to 'metrics')
-rw-r--r-- | metrics/ewma.go | 3 | ||||
-rw-r--r-- | metrics/meter.go | 43 |
2 files changed, 41 insertions, 5 deletions
diff --git a/metrics/ewma.go b/metrics/ewma.go index 3aecd4fa3..57c949e7d 100644 --- a/metrics/ewma.go +++ b/metrics/ewma.go @@ -17,9 +17,6 @@ type EWMA interface { // NewEWMA constructs a new EWMA with the given alpha. func NewEWMA(alpha float64) EWMA { - if !Enabled { - return NilEWMA{} - } return &StandardEWMA{alpha: alpha} } diff --git a/metrics/meter.go b/metrics/meter.go index 82b2141a6..58d170fae 100644 --- a/metrics/meter.go +++ b/metrics/meter.go @@ -29,6 +29,17 @@ func GetOrRegisterMeter(name string, r Registry) Meter { return r.GetOrRegister(name, NewMeter).(Meter) } +// GetOrRegisterMeterForced returns an existing Meter or constructs and registers a +// new StandardMeter no matter the global switch is enabled or not. +// Be sure to unregister the meter from the registry once it is of no use to +// allow for garbage collection. +func GetOrRegisterMeterForced(name string, r Registry) Meter { + if nil == r { + r = DefaultRegistry + } + return r.GetOrRegister(name, NewMeterForced).(Meter) +} + // NewMeter constructs a new StandardMeter and launches a goroutine. // Be sure to call Stop() once the meter is of no use to allow for garbage collection. func NewMeter() Meter { @@ -46,8 +57,23 @@ func NewMeter() Meter { return m } -// NewMeter constructs and registers a new StandardMeter and launches a -// goroutine. +// NewMeterForced constructs a new StandardMeter and launches a goroutine no matter +// the global switch is enabled or not. +// Be sure to call Stop() once the meter is of no use to allow for garbage collection. +func NewMeterForced() Meter { + m := newStandardMeter() + arbiter.Lock() + defer arbiter.Unlock() + arbiter.meters[m] = struct{}{} + if !arbiter.started { + arbiter.started = true + go arbiter.tick() + } + return m +} + +// NewRegisteredMeter constructs and registers a new StandardMeter +// and launches a goroutine. // Be sure to unregister the meter from the registry once it is of no use to // allow for garbage collection. func NewRegisteredMeter(name string, r Registry) Meter { @@ -59,6 +85,19 @@ func NewRegisteredMeter(name string, r Registry) Meter { return c } +// NewRegisteredMeterForced constructs and registers a new StandardMeter +// and launches a goroutine no matter the global switch is enabled or not. +// Be sure to unregister the meter from the registry once it is of no use to +// allow for garbage collection. +func NewRegisteredMeterForced(name string, r Registry) Meter { + c := NewMeterForced() + if nil == r { + r = DefaultRegistry + } + r.Register(name, c) + return c +} + // MeterSnapshot is a read-only copy of another Meter. type MeterSnapshot struct { count int64 |