Skip to content

Commit

Permalink
Fixed rcrowley#252 - guard against multiple registrations of runtime …
Browse files Browse the repository at this point in the history
…and debug stats - gofmt code...
  • Loading branch information
eranharel committed Dec 11, 2018
1 parent 615496d commit 80818d2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package metrics

import (
"runtime/debug"
"time"
"sync"
"time"
)

var (
Expand Down
8 changes: 4 additions & 4 deletions debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ func TestDebugGCStatsDoubleRegister(t *testing.T) {
zero := debugMetrics.GCStats.NumGC.Value() // Get a "zero" since GC may have run before these tests.
runtime.GC()
CaptureDebugGCStatsOnce(r)
if numGC := debugMetrics.GCStats.NumGC.Value(); 1 != numGC - zero {
if numGC := debugMetrics.GCStats.NumGC.Value(); 1 != numGC-zero {
t.Errorf("NumGC got %d, expected 1", numGC)
}

RegisterDebugGCStats(r)
if numGC := debugMetrics.GCStats.NumGC.Value(); 1 != numGC - zero {
t.Errorf("NumGC got %d, expected 1", numGC - zero)
if numGC := debugMetrics.GCStats.NumGC.Value(); 1 != numGC-zero {
t.Errorf("NumGC got %d, expected 1", numGC-zero)
}
}
}
4 changes: 2 additions & 2 deletions runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package metrics
import (
"runtime"
"runtime/pprof"
"time"
"sync"
"time"
)

var (
Expand Down Expand Up @@ -50,7 +50,7 @@ var (
numGC uint32
numCgoCalls int64

threadCreateProfile = pprof.Lookup("threadcreate")
threadCreateProfile = pprof.Lookup("threadcreate")
registerRuntimeMetricsOnce = sync.Once{}
)

Expand Down
10 changes: 5 additions & 5 deletions runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ func TestRuntimeMemStatsDoubleRegister(t *testing.T) {
runtime.GC()
CaptureRuntimeMemStatsOnce(r)

if count := runtimeMetrics.MemStats.NumGC.Value(); 1 != count - zero {
t.Errorf("NumGC got %d, expected 1", count - zero)
if count := runtimeMetrics.MemStats.NumGC.Value(); 1 != count-zero {
t.Errorf("NumGC got %d, expected 1", count-zero)
}

RegisterRuntimeMemStats(r)
if count := runtimeMetrics.MemStats.NumGC.Value(); 1 != count - zero {
t.Errorf("NumGC got %d, expected 1", count - zero)
if count := runtimeMetrics.MemStats.NumGC.Value(); 1 != count-zero {
t.Errorf("NumGC got %d, expected 1", count-zero)
}
}
}

0 comments on commit 80818d2

Please sign in to comment.