aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNayef Ghattas <nayef.ghattas@datadoghq.com>2023-09-05 14:00:17 +0200
committerGopher Robot <gobot@golang.org>2023-09-11 20:06:42 +0000
commitcd66ca0636a55d301530c0d766a47f07c5423d0d (patch)
tree919252a92d041a93e0497b996c97e3d96fb6a063
parentd7a062680676c00adce792f72b4370462a9886c3 (diff)
downloadgo-cd66ca0636a55d301530c0d766a47f07c5423d0d.tar.gz
go-cd66ca0636a55d301530c0d766a47f07c5423d0d.zip
[release-branch.go1.21] runtime/metrics: fix /gc/scan/* metrics
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. For #62477. Fixes #62478. Change-Id: I67497347d50ed5c3ce1719a18714c062ec938cab Reviewed-on: https://go-review.googlesource.com/c/go/+/526116 Reviewed-by: Michael Pratt <mpratt@google.com> Auto-Submit: Heschi Kreinick <heschi@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
-rw-r--r--src/runtime/metrics.go6
-rw-r--r--src/runtime/metrics_test.go3
2 files changed, 8 insertions, 1 deletions
diff --git a/src/runtime/metrics.go b/src/runtime/metrics.go
index 8ef1b022cf..3d0f174133 100644
--- a/src/runtime/metrics.go
+++ b/src/runtime/metrics.go
@@ -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
diff --git a/src/runtime/metrics_test.go b/src/runtime/metrics_test.go
index a64e898739..cfb09a3929 100644
--- a/src/runtime/metrics_test.go
+++ b/src/runtime/metrics_test.go
@@ -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)
}