]> Cypherpunks.ru repositories - gostls13.git/commitdiff
runtime/metrics: add /gc/heap/live:bytes
authorFelix Geisendörfer <felix.geisendoerfer@datadoghq.com>
Mon, 21 Nov 2022 21:41:54 +0000 (21:41 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 23 May 2023 19:06:00 +0000 (19:06 +0000)
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>
src/runtime/metrics.go
src/runtime/metrics/description.go
src/runtime/metrics/doc.go
src/runtime/metrics_test.go

index 4a51ae573f66306ba6fbcdc47f5aed58e4f7e99a..ad6348136ee1b5e5093f262b57a97fe53707ef33 100644 (file)
@@ -248,6 +248,13 @@ func initMetrics() {
                                out.scalar = in.sysStats.heapGoal
                        },
                },
+               "/gc/heap/live:bytes": {
+                       deps: makeStatDepSet(heapStatsDep),
+                       compute: func(in *statAggregate, out *metricValue) {
+                               out.kind = metricKindUint64
+                               out.scalar = gcController.heapMarked
+                       },
+               },
                "/gc/heap/objects:objects": {
                        deps: makeStatDepSet(heapStatsDep),
                        compute: func(in *statAggregate, out *metricValue) {
index 2d5b0f21955298f9de953994c0ffea4664d75aa7..f5b10202716b77a4c9bc80f07b77c875fa8d14f4 100644 (file)
@@ -245,6 +245,11 @@ var allDesc = []Description{
                Description: "Heap size target for the end of the GC cycle.",
                Kind:        KindUint64,
        },
+       {
+               Name:        "/gc/heap/live:bytes",
+               Description: "Heap memory occupied by live objects that were marked by the previous GC.",
+               Kind:        KindUint64,
+       },
        {
                Name:        "/gc/heap/objects:objects",
                Description: "Number of objects, live or unswept, occupying heap memory.",
index 34d2c09de64045b095b6201dfd19046c620317d2..fe0d1f58e9b34f979a3b50feb9bf01c3e254619d 100644 (file)
@@ -180,6 +180,10 @@ Below is the full list of supported metrics, ordered lexicographically.
        /gc/heap/goal:bytes
                Heap size target for the end of the GC cycle.
 
+       /gc/heap/live:bytes
+               Heap memory occupied by live objects that were marked by the
+               previous GC.
+
        /gc/heap/objects:objects
                Number of objects, live or unswept, occupying heap memory.
 
index d981c8ee00b65abcbd38d86a5e0b8d36aa1359e2..c1a991ead08ff7420801030b6442e66cf8001e1c 100644 (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":