Skip to content

Commit 2186909

Browse files
Gandemgopherbot
authored andcommitted
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. Fixes #62477. Change-Id: I67497347d50ed5c3ce1719a18714c062ec938cab Reviewed-on: https://go-review.googlesource.com/c/go/+/525595 Reviewed-by: Michael Knyszek <[email protected]> Auto-Submit: Michael Knyszek <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Reviewed-by: Felix Geisendörfer <[email protected]>
1 parent 4c5130a commit 2186909

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/runtime/metrics.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,24 +190,28 @@ func initMetrics() {
190190
},
191191
},
192192
"/gc/scan/globals:bytes": {
193+
deps: makeStatDepSet(gcStatsDep),
193194
compute: func(in *statAggregate, out *metricValue) {
194195
out.kind = metricKindUint64
195196
out.scalar = in.gcStats.globalsScan
196197
},
197198
},
198199
"/gc/scan/heap:bytes": {
200+
deps: makeStatDepSet(gcStatsDep),
199201
compute: func(in *statAggregate, out *metricValue) {
200202
out.kind = metricKindUint64
201203
out.scalar = in.gcStats.heapScan
202204
},
203205
},
204206
"/gc/scan/stack:bytes": {
207+
deps: makeStatDepSet(gcStatsDep),
205208
compute: func(in *statAggregate, out *metricValue) {
206209
out.kind = metricKindUint64
207210
out.scalar = in.gcStats.stackScan
208211
},
209212
},
210213
"/gc/scan/total:bytes": {
214+
deps: makeStatDepSet(gcStatsDep),
211215
compute: func(in *statAggregate, out *metricValue) {
212216
out.kind = metricKindUint64
213217
out.scalar = in.gcStats.totalScan
@@ -667,7 +671,7 @@ func (a *cpuStatsAggregate) compute() {
667671
// a.cpuStats.accumulate(nanotime(), gcphase == _GCmark)
668672
}
669673

670-
// cpuStatsAggregate represents various GC stats obtained from the runtime
674+
// gcStatsAggregate represents various GC stats obtained from the runtime
671675
// acquired together to avoid skew and inconsistencies.
672676
type gcStatsAggregate struct {
673677
heapScan uint64

src/runtime/metrics_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,9 @@ func TestReadMetricsConsistency(t *testing.T) {
405405
if gc.pauses < gc.numGC*2 {
406406
t.Errorf("fewer pauses than expected: got %d, want at least %d", gc.pauses, gc.numGC*2)
407407
}
408+
if totalScan.got <= 0 {
409+
t.Errorf("scannable GC space is empty: %d", totalScan.got)
410+
}
408411
if totalScan.got != totalScan.want {
409412
t.Errorf("/gc/scan/total:bytes doesn't line up with sum of /gc/scan*: total %d vs. sum %d", totalScan.got, totalScan.want)
410413
}

0 commit comments

Comments
 (0)