File tree 2 files changed +10
-8
lines changed
2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -131,19 +131,15 @@ var arbiter = meterTicker{meters: make(map[*Meter]struct{})}
131
131
type meterTicker struct {
132
132
mu sync.RWMutex
133
133
134
- started bool
135
- meters map [* Meter ]struct {}
134
+ once sync. Once
135
+ meters map [* Meter ]struct {}
136
136
}
137
137
138
- // add adds another *Meter ot the arbiter, and starts the arbiter ticker.
138
+ // add a *Meter to the arbiter
139
139
func (ma * meterTicker ) add (m * Meter ) {
140
140
ma .mu .Lock ()
141
141
defer ma .mu .Unlock ()
142
142
ma .meters [m ] = struct {}{}
143
- if ! ma .started {
144
- ma .started = true
145
- go ma .loop ()
146
- }
147
143
}
148
144
149
145
// remove removes a meter from the set of ticked meters.
@@ -153,7 +149,7 @@ func (ma *meterTicker) remove(m *Meter) {
153
149
ma .mu .Unlock ()
154
150
}
155
151
156
- // loop ticks meters on a 5 second interval.
152
+ // loop ticks meters on a 5- second interval.
157
153
func (ma * meterTicker ) loop () {
158
154
ticker := time .NewTicker (5 * time .Second )
159
155
for range ticker .C {
@@ -167,3 +163,8 @@ func (ma *meterTicker) loop() {
167
163
ma .mu .RUnlock ()
168
164
}
169
165
}
166
+
167
+ // startMeterTickerLoop will start the arbiter ticker.
168
+ func startMeterTickerLoop () {
169
+ arbiter .once .Do (func () { go arbiter .loop () })
170
+ }
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ func Enabled() bool {
30
30
// the program, before any metrics collection will happen.
31
31
func Enable () {
32
32
metricsEnabled = true
33
+ startMeterTickerLoop ()
33
34
}
34
35
35
36
var threadCreateProfile = pprof .Lookup ("threadcreate" )
You can’t perform that action at this time.
0 commit comments