mirror of
https://github.com/luxfi/evm.git
synced 2026-09-24 00:27:44 +00:00
32 lines
1.0 KiB
Go
32 lines
1.0 KiB
Go
// Copyright (C) 2019-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 geth 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 i := r.Get(name); i != nil {
|
|
if c, ok := i.(*metrics.Counter); ok {
|
|
return c
|
|
}
|
|
// `name` must have already been registered to be any other type
|
|
r.Unregister(name)
|
|
}
|
|
c := metrics.NewCounter()
|
|
r.Register(name, c)
|
|
return c
|
|
}
|