mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 14:16:44 +00:00
restore original, make new private
This commit is contained in:
parent
75b3e77eda
commit
83c5e78595
12 changed files with 23 additions and 19 deletions
|
|
@ -7,7 +7,7 @@ import (
|
||||||
// GetOrRegisterCounter returns an existing Counter or constructs and registers
|
// GetOrRegisterCounter returns an existing Counter or constructs and registers
|
||||||
// a new Counter.
|
// a new Counter.
|
||||||
func GetOrRegisterCounter(name string, r Registry) *Counter {
|
func GetOrRegisterCounter(name string, r Registry) *Counter {
|
||||||
return GetOrRegister(name, NewCounter, r)
|
return getOrRegister(name, NewCounter, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCounter constructs a new Counter.
|
// NewCounter constructs a new Counter.
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
// GetOrRegisterCounterFloat64 returns an existing *CounterFloat64 or constructs and registers
|
// GetOrRegisterCounterFloat64 returns an existing *CounterFloat64 or constructs and registers
|
||||||
// a new CounterFloat64.
|
// a new CounterFloat64.
|
||||||
func GetOrRegisterCounterFloat64(name string, r Registry) *CounterFloat64 {
|
func GetOrRegisterCounterFloat64(name string, r Registry) *CounterFloat64 {
|
||||||
return GetOrRegister(name, NewCounterFloat64, r)
|
return getOrRegister(name, NewCounterFloat64, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCounterFloat64 constructs a new CounterFloat64.
|
// NewCounterFloat64 constructs a new CounterFloat64.
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ func (g GaugeSnapshot) Value() int64 { return int64(g) }
|
||||||
// GetOrRegisterGauge returns an existing Gauge or constructs and registers a
|
// GetOrRegisterGauge returns an existing Gauge or constructs and registers a
|
||||||
// new Gauge.
|
// new Gauge.
|
||||||
func GetOrRegisterGauge(name string, r Registry) *Gauge {
|
func GetOrRegisterGauge(name string, r Registry) *Gauge {
|
||||||
return GetOrRegister(name, NewGauge, r)
|
return getOrRegister(name, NewGauge, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGauge constructs a new Gauge.
|
// NewGauge constructs a new Gauge.
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
// GetOrRegisterGaugeFloat64 returns an existing GaugeFloat64 or constructs and registers a
|
// GetOrRegisterGaugeFloat64 returns an existing GaugeFloat64 or constructs and registers a
|
||||||
// new GaugeFloat64.
|
// new GaugeFloat64.
|
||||||
func GetOrRegisterGaugeFloat64(name string, r Registry) *GaugeFloat64 {
|
func GetOrRegisterGaugeFloat64(name string, r Registry) *GaugeFloat64 {
|
||||||
return GetOrRegister(name, NewGaugeFloat64, r)
|
return getOrRegister(name, NewGaugeFloat64, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GaugeFloat64Snapshot is a read-only copy of a GaugeFloat64.
|
// GaugeFloat64Snapshot is a read-only copy of a GaugeFloat64.
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ func (val GaugeInfoValue) String() string {
|
||||||
// GetOrRegisterGaugeInfo returns an existing GaugeInfo or constructs and registers a
|
// GetOrRegisterGaugeInfo returns an existing GaugeInfo or constructs and registers a
|
||||||
// new GaugeInfo.
|
// new GaugeInfo.
|
||||||
func GetOrRegisterGaugeInfo(name string, r Registry) *GaugeInfo {
|
func GetOrRegisterGaugeInfo(name string, r Registry) *GaugeInfo {
|
||||||
return GetOrRegister(name, NewGaugeInfo, r)
|
return getOrRegister(name, NewGaugeInfo, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGaugeInfo constructs a new GaugeInfo.
|
// NewGaugeInfo constructs a new GaugeInfo.
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,13 @@ type Histogram interface {
|
||||||
// GetOrRegisterHistogram returns an existing Histogram or constructs and
|
// GetOrRegisterHistogram returns an existing Histogram or constructs and
|
||||||
// registers a new StandardHistogram.
|
// registers a new StandardHistogram.
|
||||||
func GetOrRegisterHistogram(name string, r Registry, s Sample) Histogram {
|
func GetOrRegisterHistogram(name string, r Registry, s Sample) Histogram {
|
||||||
return GetOrRegister(name, func() Histogram { return NewHistogram(s) }, r).(Histogram)
|
return getOrRegister(name, func() Histogram { return NewHistogram(s) }, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOrRegisterHistogramLazy returns an existing Histogram or constructs and
|
// GetOrRegisterHistogramLazy returns an existing Histogram or constructs and
|
||||||
// registers a new StandardHistogram.
|
// registers a new StandardHistogram.
|
||||||
func GetOrRegisterHistogramLazy(name string, r Registry, s func() Sample) Histogram {
|
func GetOrRegisterHistogramLazy(name string, r Registry, s func() Sample) Histogram {
|
||||||
return GetOrRegister(name, func() Histogram { return NewHistogram(s()) }, r).(Histogram)
|
return getOrRegister(name, func() Histogram { return NewHistogram(s()) }, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHistogram constructs a new StandardHistogram from a Sample.
|
// NewHistogram constructs a new StandardHistogram from a Sample.
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import (
|
||||||
// Be sure to unregister the meter from the registry once it is of no use to
|
// Be sure to unregister the meter from the registry once it is of no use to
|
||||||
// allow for garbage collection.
|
// allow for garbage collection.
|
||||||
func GetOrRegisterMeter(name string, r Registry) *Meter {
|
func GetOrRegisterMeter(name string, r Registry) *Meter {
|
||||||
return GetOrRegister(name, NewMeter, r)
|
return getOrRegister(name, NewMeter, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMeter constructs a new Meter and launches a goroutine.
|
// NewMeter constructs a new Meter and launches a goroutine.
|
||||||
|
|
|
||||||
|
|
@ -327,7 +327,11 @@ func Get(name string) interface{} {
|
||||||
|
|
||||||
// GetOrRegister gets an existing metric or creates and registers a new one. Threadsafe
|
// GetOrRegister gets an existing metric or creates and registers a new one. Threadsafe
|
||||||
// alternative to calling Get and Register on failure.
|
// alternative to calling Get and Register on failure.
|
||||||
func GetOrRegister[T any](name string, ctor func() T, r Registry) T {
|
func GetOrRegister(name string, i func() interface{}) interface{} {
|
||||||
|
return DefaultRegistry.GetOrRegister(name, i)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getOrRegister[T any](name string, ctor func() T, r Registry) T {
|
||||||
if r == nil {
|
if r == nil {
|
||||||
r = DefaultRegistry
|
r = DefaultRegistry
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ func benchmarkRegistryGetOrRegisterParallel(b *testing.B, amount int) {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
GetOrRegister("foo", NewMeter, r)
|
GetOrRegisterMeter("foo", r)
|
||||||
}
|
}
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
@ -98,8 +98,8 @@ func TestRegistryGetOrRegister(t *testing.T) {
|
||||||
r := NewRegistry()
|
r := NewRegistry()
|
||||||
|
|
||||||
// First metric wins with GetOrRegister
|
// First metric wins with GetOrRegister
|
||||||
c1 := GetOrRegister("foo", NewCounter, r)
|
c1 := GetOrRegisterCounter("foo", r)
|
||||||
c2 := GetOrRegister("foo", NewCounter, r)
|
c2 := GetOrRegisterCounter("foo", r)
|
||||||
if c1 != c2 {
|
if c1 != c2 {
|
||||||
t.Fatal("counters should've matched")
|
t.Fatal("counters should've matched")
|
||||||
}
|
}
|
||||||
|
|
@ -123,8 +123,8 @@ func TestRegistryGetOrRegisterWithLazyInstantiation(t *testing.T) {
|
||||||
r := NewRegistry()
|
r := NewRegistry()
|
||||||
|
|
||||||
// First metric wins with GetOrRegister
|
// First metric wins with GetOrRegister
|
||||||
c1 := GetOrRegister("foo", NewCounter, r)
|
c1 := GetOrRegisterCounter("foo", r)
|
||||||
c2 := GetOrRegister("foo", NewCounter, r)
|
c2 := GetOrRegisterCounter("foo", r)
|
||||||
if c1 != c2 {
|
if c1 != c2 {
|
||||||
t.Fatal("counters should've matched")
|
t.Fatal("counters should've matched")
|
||||||
}
|
}
|
||||||
|
|
@ -165,7 +165,7 @@ func TestPrefixedChildRegistryGetOrRegister(t *testing.T) {
|
||||||
r := NewRegistry()
|
r := NewRegistry()
|
||||||
pr := NewPrefixedChildRegistry(r, "prefix.")
|
pr := NewPrefixedChildRegistry(r, "prefix.")
|
||||||
|
|
||||||
_ = GetOrRegister("foo", NewCounter, pr)
|
_ = GetOrRegisterCounter("foo", pr)
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
r.Each(func(name string, m interface{}) {
|
r.Each(func(name string, m interface{}) {
|
||||||
|
|
@ -182,7 +182,7 @@ func TestPrefixedChildRegistryGetOrRegister(t *testing.T) {
|
||||||
func TestPrefixedRegistryGetOrRegister(t *testing.T) {
|
func TestPrefixedRegistryGetOrRegister(t *testing.T) {
|
||||||
r := NewPrefixedRegistry("prefix.")
|
r := NewPrefixedRegistry("prefix.")
|
||||||
|
|
||||||
_ = GetOrRegister("foo", NewCounter, r)
|
_ = GetOrRegisterCounter("foo", r)
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
r.Each(func(name string, m interface{}) {
|
r.Each(func(name string, m interface{}) {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
// GetOrRegisterResettingTimer returns an existing ResettingTimer or constructs and registers a
|
// GetOrRegisterResettingTimer returns an existing ResettingTimer or constructs and registers a
|
||||||
// new ResettingTimer.
|
// new ResettingTimer.
|
||||||
func GetOrRegisterResettingTimer(name string, r Registry) *ResettingTimer {
|
func GetOrRegisterResettingTimer(name string, r Registry) *ResettingTimer {
|
||||||
return GetOrRegister(name, NewResettingTimer, r)
|
return getOrRegister(name, NewResettingTimer, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRegisteredResettingTimer constructs and registers a new ResettingTimer.
|
// NewRegisteredResettingTimer constructs and registers a new ResettingTimer.
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
func getOrRegisterRuntimeHistogram(name string, scale float64, r Registry) *runtimeHistogram {
|
func getOrRegisterRuntimeHistogram(name string, scale float64, r Registry) *runtimeHistogram {
|
||||||
constructor := func() Histogram { return newRuntimeHistogram(scale) }
|
constructor := func() Histogram { return newRuntimeHistogram(scale) }
|
||||||
return GetOrRegister(name, constructor, r).(*runtimeHistogram)
|
return getOrRegister(name, constructor, r).(*runtimeHistogram)
|
||||||
}
|
}
|
||||||
|
|
||||||
// runtimeHistogram wraps a runtime/metrics histogram.
|
// runtimeHistogram wraps a runtime/metrics histogram.
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
// Be sure to unregister the meter from the registry once it is of no use to
|
// Be sure to unregister the meter from the registry once it is of no use to
|
||||||
// allow for garbage collection.
|
// allow for garbage collection.
|
||||||
func GetOrRegisterTimer(name string, r Registry) *Timer {
|
func GetOrRegisterTimer(name string, r Registry) *Timer {
|
||||||
return GetOrRegister(name, NewTimer, r)
|
return getOrRegister(name, NewTimer, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCustomTimer constructs a new Timer from a Histogram and a Meter.
|
// NewCustomTimer constructs a new Timer from a Histogram and a Meter.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue