]> Cypherpunks.ru repositories - gostls13.git/commitdiff
runtime/metrics: fix /gc/scan/* metrics
authorNayef Ghattas <nayef.ghattas@datadoghq.com>
Tue, 5 Sep 2023 12:00:17 +0000 (14:00 +0200)
committerGopher Robot <gobot@golang.org>
Wed, 6 Sep 2023 15:44:45 +0000 (15:44 +0000)
In the existing implementation, all /gc/scan/* metrics are
always equal to 0 due to the dependency on gcStatDep not being
set. This leads to gcStatAggregate always containing zeros, and
always reporting 0 for those metrics.

Also, add a test to ensure that /gc/scan/* metrics are not empty.

Fixes #62477.

Change-Id: I67497347d50ed5c3ce1719a18714c062ec938cab
Reviewed-on: https://go-review.googlesource.com/c/go/+/525595
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Felix Geisendörfer <felix.geisendoerfer@datadoghq.com>
src/runtime/metrics.go
src/runtime/metrics_test.go

index 8ef1b022cfdc6519b6bfe8dbdf9179b6deff6f6c..3d0f1741334a1d1aa8c2f1826d26f3c992a2f0ae 100644 (file)
@@ -190,24 +190,28 @@ func initMetrics() {
                        },
                },
                "/gc/scan/globals:bytes": {
+                       deps: makeStatDepSet(gcStatsDep),
                        compute: func(in *statAggregate, out *metricValue) {
                                out.kind = metricKindUint64
                                out.scalar = in.gcStats.globalsScan
                        },
                },
                "/gc/scan/heap:bytes": {
+                       deps: makeStatDepSet(gcStatsDep),
                        compute: func(in *statAggregate, out *metricValue) {
                                out.kind = metricKindUint64
                                out.scalar = in.gcStats.heapScan
                        },
                },
                "/gc/scan/stack:bytes": {
+                       deps: makeStatDepSet(gcStatsDep),
                        compute: func(in *statAggregate, out *metricValue) {
                                out.kind = metricKindUint64
                                out.scalar = in.gcStats.stackScan
                        },
                },
                "/gc/scan/total:bytes": {
+                       deps: makeStatDepSet(gcStatsDep),
                        compute: func(in *statAggregate, out *metricValue) {
                                out.kind = metricKindUint64
                                out.scalar = in.gcStats.totalScan
@@ -667,7 +671,7 @@ func (a *cpuStatsAggregate) compute() {
        // a.cpuStats.accumulate(nanotime(), gcphase == _GCmark)
 }
 
-// cpuStatsAggregate represents various GC stats obtained from the runtime
+// gcStatsAggregate represents various GC stats obtained from the runtime
 // acquired together to avoid skew and inconsistencies.
 type gcStatsAggregate struct {
        heapScan    uint64
index a64e898739731a500e135392e362f098b512f843..cfb09a392919dcd3ed14e9e42e21c027074c2b39 100644 (file)
@@ -405,6 +405,9 @@ func TestReadMetricsConsistency(t *testing.T) {
        if gc.pauses < gc.numGC*2 {
                t.Errorf("fewer pauses than expected: got %d, want at least %d", gc.pauses, gc.numGC*2)
        }
+       if totalScan.got <= 0 {
+               t.Errorf("scannable GC space is empty: %d", totalScan.got)
+       }
        if totalScan.got != totalScan.want {
                t.Errorf("/gc/scan/total:bytes doesn't line up with sum of /gc/scan*: total %d vs. sum %d", totalScan.got, totalScan.want)
        }