mirror of
https://github.com/luxfi/evm.git
synced 2026-09-24 00:27:44 +00:00
27 lines
1.0 KiB
Go
27 lines
1.0 KiB
Go
// (c) 2025 Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
package core
|
|
|
|
import "github.com/luxfi/geth/metrics"
|
|
|
|
// getOrOverrideAsRegisteredCounter searches for a metric already registered
|
|
// with `name`. If a metric is found and it is a [metrics.Counter], it is returned. If a
|
|
// metric is found and it is not a [metrics.Counter], it is unregistered and replaced with
|
|
// a new registered [metrics.Counter]. If no metric is found, a new [metrics.Counter] is constructed
|
|
// and registered.
|
|
//
|
|
// This is necessary for a metric defined in libevm with the same name but a
|
|
// different type to what we expect.
|
|
func getOrOverrideAsRegisteredCounter(name string, r metrics.Registry) *metrics.Counter {
|
|
if r == nil {
|
|
r = metrics.DefaultRegistry
|
|
}
|
|
|
|
if c, ok := r.GetOrRegister(name, func() interface{} { return metrics.NewCounter() }).(*metrics.Counter); ok {
|
|
return c
|
|
}
|
|
// `name` must have already been registered to be any other type
|
|
r.Unregister(name)
|
|
return metrics.GetOrRegisterCounter(name, r)
|
|
}
|