mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 07:37:20 +00:00
metrics: spin up meter ticker routine when enabling metric system (#31400)
Addresses https://github.com/ethereum/go-ethereum/issues/31244
This commit is contained in:
parent
7d99f7df00
commit
d25c3c32b2
2 changed files with 10 additions and 8 deletions
|
|
@ -131,19 +131,15 @@ var arbiter = meterTicker{meters: make(map[*Meter]struct{})}
|
|||
type meterTicker struct {
|
||||
mu sync.RWMutex
|
||||
|
||||
started bool
|
||||
meters map[*Meter]struct{}
|
||||
once sync.Once
|
||||
meters map[*Meter]struct{}
|
||||
}
|
||||
|
||||
// add adds another *Meter ot the arbiter, and starts the arbiter ticker.
|
||||
// add a *Meter to the arbiter
|
||||
func (ma *meterTicker) add(m *Meter) {
|
||||
ma.mu.Lock()
|
||||
defer ma.mu.Unlock()
|
||||
ma.meters[m] = struct{}{}
|
||||
if !ma.started {
|
||||
ma.started = true
|
||||
go ma.loop()
|
||||
}
|
||||
}
|
||||
|
||||
// remove removes a meter from the set of ticked meters.
|
||||
|
|
@ -153,7 +149,7 @@ func (ma *meterTicker) remove(m *Meter) {
|
|||
ma.mu.Unlock()
|
||||
}
|
||||
|
||||
// loop ticks meters on a 5 second interval.
|
||||
// loop ticks meters on a 5-second interval.
|
||||
func (ma *meterTicker) loop() {
|
||||
ticker := time.NewTicker(5 * time.Second)
|
||||
for range ticker.C {
|
||||
|
|
@ -167,3 +163,8 @@ func (ma *meterTicker) loop() {
|
|||
ma.mu.RUnlock()
|
||||
}
|
||||
}
|
||||
|
||||
// startMeterTickerLoop will start the arbiter ticker.
|
||||
func startMeterTickerLoop() {
|
||||
arbiter.once.Do(func() { go arbiter.loop() })
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ func Enabled() bool {
|
|||
// the program, before any metrics collection will happen.
|
||||
func Enable() {
|
||||
metricsEnabled = true
|
||||
startMeterTickerLoop()
|
||||
}
|
||||
|
||||
var threadCreateProfile = pprof.Lookup("threadcreate")
|
||||
|
|
|
|||
Loading…
Reference in a new issue