runtime/metrics: add /gc/heap/live:bytes

For #56857

Change-Id: I0622af974783ab435e91b9fb3c1ba43f256ee4ac
Reviewed-on: https://go-review.googlesource.com/c/go/+/497315
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Felix Geisendörfer <felix.geisendoerfer@datadoghq.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
Felix Geisendörfer 2022-11-21 21:41:54 +00:00 committed by Gopher Robot
parent 8366497625
commit ef2bb813c8
4 changed files with 26 additions and 0 deletions

View file

@ -28,6 +28,9 @@ func prepareAllMetricsSamples() (map[string]metrics.Description, []metrics.Sampl
}
func TestReadMetrics(t *testing.T) {
// Run a GC cycle to get some of the stats to be non-zero.
runtime.GC()
// Tests whether readMetrics produces values aligning
// with ReadMemStats while the world is stopped.
var mstats runtime.MemStats
@ -128,6 +131,13 @@ func TestReadMetrics(t *testing.T) {
mallocs = samples[i].Value.Uint64()
case "/gc/heap/frees:objects":
frees = samples[i].Value.Uint64()
case "/gc/heap/live:bytes":
if live := samples[i].Value.Uint64(); live > mstats.HeapAlloc {
t.Errorf("live bytes: %d > heap alloc: %d", live, mstats.HeapAlloc)
} else if live == 0 {
// Might happen if we don't call runtime.GC() above.
t.Error("live bytes is 0")
}
case "/gc/heap/objects:objects":
checkUint64(t, name, samples[i].Value.Uint64(), mstats.HeapObjects)
case "/gc/heap/goal:bytes":