mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
metrics: spin up ticker routine only if metrics is enabled
This commit is contained in:
parent
939a804146
commit
c0cd847f8a
1 changed files with 7 additions and 4 deletions
|
|
@ -139,10 +139,16 @@ type meterTicker struct {
|
|||
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()
|
||||
|
||||
// Avoid starting the ticker routine if metrics are disabled,
|
||||
// as all created meters will remain inactive.
|
||||
if Enabled() {
|
||||
go ma.loop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -157,9 +163,6 @@ func (ma *meterTicker) remove(m *Meter) {
|
|||
func (ma *meterTicker) loop() {
|
||||
ticker := time.NewTicker(5 * time.Second)
|
||||
for range ticker.C {
|
||||
if !metricsEnabled {
|
||||
continue
|
||||
}
|
||||
ma.mu.RLock()
|
||||
for meter := range ma.meters {
|
||||
meter.tick()
|
||||
|
|
|
|||
Loading…
Reference in a new issue