@@ -29,6 +29,17 @@ func GetOrRegisterMeter(name string, r Registry) Meter {
2929 return r .GetOrRegister (name , NewMeter ).(Meter )
3030}
3131
32+ // GetOrRegisterMeterForced returns an existing Meter or constructs and registers a
33+ // new StandardMeter no matter the global switch is enabled or not.
34+ // Be sure to unregister the meter from the registry once it is of no use to
35+ // allow for garbage collection.
36+ func GetOrRegisterMeterForced (name string , r Registry ) Meter {
37+ if nil == r {
38+ r = DefaultRegistry
39+ }
40+ return r .GetOrRegister (name , NewMeterForced ).(Meter )
41+ }
42+
3243// NewMeter constructs a new StandardMeter and launches a goroutine.
3344// Be sure to call Stop() once the meter is of no use to allow for garbage collection.
3445func NewMeter () Meter {
@@ -46,8 +57,23 @@ func NewMeter() Meter {
4657 return m
4758}
4859
49- // NewMeter constructs and registers a new StandardMeter and launches a
50- // goroutine.
60+ // NewMeterForced constructs a new StandardMeter and launches a goroutine no matter
61+ // the global switch is enabled or not.
62+ // Be sure to call Stop() once the meter is of no use to allow for garbage collection.
63+ func NewMeterForced () Meter {
64+ m := newStandardMeter ()
65+ arbiter .Lock ()
66+ defer arbiter .Unlock ()
67+ arbiter .meters [m ] = struct {}{}
68+ if ! arbiter .started {
69+ arbiter .started = true
70+ go arbiter .tick ()
71+ }
72+ return m
73+ }
74+
75+ // NewRegisteredMeter constructs and registers a new StandardMeter
76+ // and launches a goroutine.
5177// Be sure to unregister the meter from the registry once it is of no use to
5278// allow for garbage collection.
5379func NewRegisteredMeter (name string , r Registry ) Meter {
@@ -59,6 +85,19 @@ func NewRegisteredMeter(name string, r Registry) Meter {
5985 return c
6086}
6187
88+ // NewRegisteredMeterForced constructs and registers a new StandardMeter
89+ // and launches a goroutine no matter the global switch is enabled or not.
90+ // Be sure to unregister the meter from the registry once it is of no use to
91+ // allow for garbage collection.
92+ func NewRegisteredMeterForced (name string , r Registry ) Meter {
93+ c := NewMeterForced ()
94+ if nil == r {
95+ r = DefaultRegistry
96+ }
97+ r .Register (name , c )
98+ return c
99+ }
100+
62101// MeterSnapshot is a read-only copy of another Meter.
63102type MeterSnapshot struct {
64103 count int64
0 commit comments