mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
36c5edd8d9
commit
d39a89fd58
6 changed files with 54 additions and 0 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue