Browse Source

Fixed #252 - guard against multiple registrations of runtime and debug stats - gofmt code...

eranharel 7 years ago
parent
commit
80818d207a
4 changed files with 12 additions and 12 deletions
  1. 1 1
      debug.go
  2. 4 4
      debug_test.go
  3. 2 2
      runtime.go
  4. 5 5
      runtime_test.go

+ 1 - 1
debug.go

@@ -2,8 +2,8 @@ package metrics
 
 
 import (
 import (
 	"runtime/debug"
 	"runtime/debug"
-	"time"
 	"sync"
 	"sync"
+	"time"
 )
 )
 
 
 var (
 var (

+ 4 - 4
debug_test.go

@@ -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.
 	zero := debugMetrics.GCStats.NumGC.Value() // Get a "zero" since GC may have run before these tests.
 	runtime.GC()
 	runtime.GC()
 	CaptureDebugGCStatsOnce(r)
 	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)
 		t.Errorf("NumGC got %d, expected 1", numGC)
 	}
 	}
 
 
 	RegisterDebugGCStats(r)
 	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)
 	}
 	}
-}
+}

+ 2 - 2
runtime.go

@@ -3,8 +3,8 @@ package metrics
 import (
 import (
 	"runtime"
 	"runtime"
 	"runtime/pprof"
 	"runtime/pprof"
-	"time"
 	"sync"
 	"sync"
+	"time"
 )
 )
 
 
 var (
 var (
@@ -50,7 +50,7 @@ var (
 	numGC       uint32
 	numGC       uint32
 	numCgoCalls int64
 	numCgoCalls int64
 
 
-	threadCreateProfile = pprof.Lookup("threadcreate")
+	threadCreateProfile        = pprof.Lookup("threadcreate")
 	registerRuntimeMetricsOnce = sync.Once{}
 	registerRuntimeMetricsOnce = sync.Once{}
 )
 )
 
 

+ 5 - 5
runtime_test.go

@@ -94,12 +94,12 @@ func TestRuntimeMemStatsDoubleRegister(t *testing.T) {
 	runtime.GC()
 	runtime.GC()
 	CaptureRuntimeMemStatsOnce(r)
 	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)
 	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)
 	}
 	}
-}
+}