Skip to content

Commit

Permalink
Swap active/inactive in the gatherer
Browse files Browse the repository at this point in the history
  • Loading branch information
axw committed Jul 1, 2019
1 parent 7cf9719 commit 1fa306d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
13 changes: 7 additions & 6 deletions breakdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,17 @@ func (m *breakdownMetricsMap) record(k breakdownMetricsKey, bt breakdownTiming)
return true
}

func (m *breakdownMetrics) swap() {
// gather is called by builtinMetricsGatherer to gather breakdown metrics.
func (m *breakdownMetrics) gather(out *Metrics) {
// Hold m.mu only long enough to swap m.active and m.inactive.
// This will be blocked up metric updates, but that's OK; only
// metrics gathering will be delayed. After swapping we do not
// need to hold m.mu, since nothing concurrently accesses
// m.inactive while the gatherer is iterating over it.
m.mu.Lock()
m.active, m.inactive = m.inactive, m.active
m.mu.Unlock()
}

// gather is called by builtinMetricsGatherer to gather breakdown metrics.
func (m *breakdownMetrics) gather(out *Metrics) {
// It is not necessary to hold m.mu, since nothing concurrently
// accesses m.inactive while the gatherer is iterating over it.
for hash, entries := range m.inactive.m {
for _, entry := range entries {
if entry.transaction.count > 0 {
Expand Down
1 change: 0 additions & 1 deletion tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,6 @@ func (t *Tracer) loop() {
if gatherMetrics {
gatheringMetrics = true
metrics.disabled = cfg.disabledMetrics
t.breakdownMetrics.swap()
t.gatherMetrics(ctx, cfg.metricsGatherers, &metrics, cfg.logger, gatheredMetrics)
if cfg.logger != nil {
cfg.logger.Debugf("gathering metrics")
Expand Down

0 comments on commit 1fa306d

Please sign in to comment.