aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/metrics_test.go
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2020-08-06 21:59:13 +0000
committerMichael Knyszek <mknyszek@google.com>2020-10-26 21:47:54 +0000
commitd39a89fd5843f535d634620d27110b320431f584 (patch)
treed44fd02351cc88c0d28e48465a3e5ac3bd056ff9 /src/runtime/metrics_test.go
parent36c5edd8d9e6c13af26733e5c820eae0598203fe (diff)
downloadgo-d39a89fd5843f535d634620d27110b320431f584.tar.gz
go-d39a89fd5843f535d634620d27110b320431f584.zip
runtime,runtime/metrics: add metric for distribution of GC pauses
For #37112. Change-Id: Ibb0425c9c582ae3da3b2662d5bbe830d7df9079c Reviewed-on: https://go-review.googlesource.com/c/go/+/247047 Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/metrics_test.go')
-rw-r--r--src/runtime/metrics_test.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/runtime/metrics_test.go b/src/runtime/metrics_test.go
index 1a30810544..7b3132bc30 100644
--- a/src/runtime/metrics_test.go
+++ b/src/runtime/metrics_test.go
@@ -90,6 +90,11 @@ func TestReadMetricsConsistency(t *testing.T) {
// things (e.g. allocating) so what we read can't reasonably compared
// to runtime values.
+ // Run a few GC cycles to get some of the stats to be non-zero.
+ runtime.GC()
+ runtime.GC()
+ runtime.GC()
+
// Read all the supported metrics through the metrics package.
descs, samples := prepareAllMetricsSamples()
metrics.Read(samples)
@@ -102,6 +107,10 @@ func TestReadMetricsConsistency(t *testing.T) {
alloc, free *metrics.Float64Histogram
total uint64
}
+ var gc struct {
+ numGC uint64
+ pauses uint64
+ }
for i := range samples {
kind := samples[i].Value.Kind()
if want := descs[samples[i].Name].Kind; kind != want {
@@ -128,6 +137,14 @@ func TestReadMetricsConsistency(t *testing.T) {
objects.alloc = samples[i].Value.Float64Histogram()
case "/gc/heap/frees-by-size:objects":
objects.free = samples[i].Value.Float64Histogram()
+ case "/gc/cycles:gc-cycles":
+ gc.numGC = samples[i].Value.Uint64()
+ case "/gc/pauses:seconds":
+ h := samples[i].Value.Float64Histogram()
+ gc.pauses = 0
+ for i := range h.Counts {
+ gc.pauses += h.Counts[i]
+ }
}
}
if totalVirtual.got != totalVirtual.want {
@@ -159,6 +176,11 @@ func TestReadMetricsConsistency(t *testing.T) {
}
}
}
+ // The current GC has at least 2 pauses per GC.
+ // Check to see if that value makes sense.
+ if gc.pauses < gc.numGC*2 {
+ t.Errorf("fewer pauses than expected: got %d, want at least %d", gc.pauses, gc.numGC*2)
+ }
}
func BenchmarkReadMetricsLatency(b *testing.B) {