|
|
@@ -6,6 +6,29 @@ import (
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
+func TestRuntimeMemStatsDoubleRegister(t *testing.T) {
|
|
|
+ r := NewRegistry()
|
|
|
+ RegisterRuntimeMemStats(r)
|
|
|
+ storedGauge := r.Get("runtime.MemStats.LastGC").(Gauge)
|
|
|
+
|
|
|
+ runtime.GC()
|
|
|
+ CaptureRuntimeMemStatsOnce(r)
|
|
|
+
|
|
|
+ firstGC := storedGauge.Value()
|
|
|
+ if 0 == firstGC {
|
|
|
+ t.Errorf("firstGC got %d, expected timestamp > 0", firstGC)
|
|
|
+ }
|
|
|
+
|
|
|
+ time.Sleep(time.Millisecond)
|
|
|
+
|
|
|
+ RegisterRuntimeMemStats(r)
|
|
|
+ runtime.GC()
|
|
|
+ CaptureRuntimeMemStatsOnce(r)
|
|
|
+ if lastGC := storedGauge.Value(); firstGC == lastGC {
|
|
|
+ t.Errorf("lastGC got %d, expected a higher timestamp value", lastGC)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func BenchmarkRuntimeMemStats(b *testing.B) {
|
|
|
r := NewRegistry()
|
|
|
RegisterRuntimeMemStats(r)
|
|
|
@@ -86,20 +109,3 @@ func testRuntimeMemStatsBlocking(ch chan int) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-func TestRuntimeMemStatsDoubleRegister(t *testing.T) {
|
|
|
- r := NewRegistry()
|
|
|
- RegisterRuntimeMemStats(r)
|
|
|
- zero := runtimeMetrics.MemStats.NumGC.Value() // Get a "zero" since GC may have run before these tests.
|
|
|
- runtime.GC()
|
|
|
- CaptureRuntimeMemStatsOnce(r)
|
|
|
-
|
|
|
- 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)
|
|
|
- }
|
|
|
-}
|