]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/metrics: add /gc/gogc:percent
authorFelix Geisendörfer <felix.geisendoerfer@datadoghq.com>
Tue, 23 May 2023 09:26:22 +0000 (11:26 +0200)
committerGopher Robot <gobot@golang.org>
Tue, 23 May 2023 19:14:05 +0000 (19:14 +0000)
For #56857

Change-Id: I7e7d2ea3e6ab59291a4cd867c680605ad75bd21f
Reviewed-on: https://go-review.googlesource.com/c/go/+/497317
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Felix Geisendörfer <felix.geisendoerfer@datadoghq.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
src/runtime/metrics.go
src/runtime/metrics/description.go
src/runtime/metrics/doc.go
src/runtime/metrics_test.go

index 9308a784b706cb01956d55e622884044610f5e81..4931a0ef8b8ba0a624345582b33d542d530137d7 100644 (file)
@@ -254,6 +254,12 @@ func initMetrics() {
                                out.scalar = uint64(gcController.memoryLimit.Load())
                        },
                },
+               "/gc/gogc:percent": {
+                       compute: func(in *statAggregate, out *metricValue) {
+                               out.kind = metricKindUint64
+                               out.scalar = uint64(gcController.gcPercent.Load())
+                       },
+               },
                "/gc/heap/live:bytes": {
                        deps: makeStatDepSet(heapStatsDep),
                        compute: func(in *statAggregate, out *metricValue) {
index e9c8ccc0fe1e05f2da0d5e3b516586c56c81a841..e3eb87b353b02c8dad73f2f07a0bdceeae40c258 100644 (file)
@@ -193,6 +193,13 @@ var allDesc = []Description{
                Kind:        KindUint64,
                Cumulative:  true,
        },
+       {
+               Name: "/gc/gogc:percent",
+               Description: "Heap size target percentage configured by the user, otherwise 100. This " +
+                       "value is set by the GOGC environment variable, and the runtime/debug.SetGCPercent " +
+                       "function.",
+               Kind: KindUint64,
+       },
        {
                Name: "/gc/gomemlimit:bytes",
                Description: "Go runtime memory limit configured by the user, otherwise " +
index 61326ed1dfabaf816515afbdc5231c826989c221..f95177edc85436094415209fec796175140be61c 100644 (file)
@@ -147,6 +147,11 @@ Below is the full list of supported metrics, ordered lexicographically.
        /gc/cycles/total:gc-cycles
                Count of all completed GC cycles.
 
+       /gc/gogc:percent
+               Heap size target percentage configured by the user, otherwise
+               100. This value is set by the GOGC environment variable, and the
+               runtime/debug.SetGCPercent function.
+
        /gc/gomemlimit:bytes
                Go runtime memory limit configured by the user, otherwise
                math.MaxInt64. This value is set by the GOMEMLIMIT environment
index 19888376a4f65b61521d96775fb94bc4785db31b..4b58914032ad803cda27f8205140db084f2d23bf 100644 (file)
@@ -37,6 +37,11 @@ func TestReadMetrics(t *testing.T) {
        oldLimit := debug.SetMemoryLimit(limit)
        defer debug.SetMemoryLimit(oldLimit)
 
+       // Set an GC percent to check the metric for it
+       gcPercent := 99
+       oldGCPercent := debug.SetGCPercent(gcPercent)
+       defer debug.SetGCPercent(oldGCPercent)
+
        // Tests whether readMetrics produces values aligning
        // with ReadMemStats while the world is stopped.
        var mstats runtime.MemStats
@@ -150,6 +155,8 @@ func TestReadMetrics(t *testing.T) {
                        checkUint64(t, name, samples[i].Value.Uint64(), mstats.HeapObjects)
                case "/gc/heap/goal:bytes":
                        checkUint64(t, name, samples[i].Value.Uint64(), mstats.NextGC)
+               case "/gc/gogc:percent":
+                       checkUint64(t, name, samples[i].Value.Uint64(), uint64(gcPercent))
                case "/gc/cycles/automatic:gc-cycles":
                        checkUint64(t, name, samples[i].Value.Uint64(), uint64(mstats.NumGC-mstats.NumForcedGC))
                case "/gc/cycles/forced:gc-cycles":