aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorholisticode <holistic.computing@gmail.com>2018-10-16 22:22:51 +0800
committerAnton Evangelatov <anton.evangelatov@gmail.com>2018-10-16 22:22:51 +0800
commit4466c7b971837bded610dd2225ddc6065c0cb3c3 (patch)
treef3a31ad52ca3211583d83bc9e2f5b849a08181a2
parent2868acd80b05e3dfca9f32c19372f22849e40eaf (diff)
downloadgo-tangerine-4466c7b971837bded610dd2225ddc6065c0cb3c3.tar.gz
go-tangerine-4466c7b971837bded610dd2225ddc6065c0cb3c3.tar.zst
go-tangerine-4466c7b971837bded610dd2225ddc6065c0cb3c3.zip
metrics: added NewCounterForced (#17919)
-rw-r--r--metrics/counter.go34
1 files changed, 33 insertions, 1 deletions
diff --git a/metrics/counter.go b/metrics/counter.go
index c7f2b4bd3..2f78c90d5 100644
--- a/metrics/counter.go
+++ b/metrics/counter.go
@@ -1,6 +1,8 @@
package metrics
-import "sync/atomic"
+import (
+ "sync/atomic"
+)
// Counters hold an int64 value that can be incremented and decremented.
type Counter interface {
@@ -20,6 +22,17 @@ func GetOrRegisterCounter(name string, r Registry) Counter {
return r.GetOrRegister(name, NewCounter).(Counter)
}
+// GetOrRegisterCounterForced returns an existing Counter or constructs and registers a
+// new Counter no matter the global switch is enabled or not.
+// Be sure to unregister the counter from the registry once it is of no use to
+// allow for garbage collection.
+func GetOrRegisterCounterForced(name string, r Registry) Counter {
+ if nil == r {
+ r = DefaultRegistry
+ }
+ return r.GetOrRegister(name, NewCounterForced).(Counter)
+}
+
// NewCounter constructs a new StandardCounter.
func NewCounter() Counter {
if !Enabled {
@@ -28,6 +41,12 @@ func NewCounter() Counter {
return &StandardCounter{0}
}
+// NewCounterForced constructs a new StandardCounter and returns it no matter if
+// the global switch is enabled or not.
+func NewCounterForced() Counter {
+ return &StandardCounter{0}
+}
+
// NewRegisteredCounter constructs and registers a new StandardCounter.
func NewRegisteredCounter(name string, r Registry) Counter {
c := NewCounter()
@@ -38,6 +57,19 @@ func NewRegisteredCounter(name string, r Registry) Counter {
return c
}
+// NewRegisteredCounterForced constructs and registers a new StandardCounter
+// and launches a goroutine no matter the global switch is enabled or not.
+// Be sure to unregister the counter from the registry once it is of no use to
+// allow for garbage collection.
+func NewRegisteredCounterForced(name string, r Registry) Counter {
+ c := NewCounterForced()
+ if nil == r {
+ r = DefaultRegistry
+ }
+ r.Register(name, c)
+ return c
+}
+
// CounterSnapshot is a read-only copy of another Counter.
type CounterSnapshot int64