@@ -7,6 +7,7 @@ package runtime
7
7
// Metrics implementation exported to runtime/metrics.
8
8
9
9
import (
10
+ "runtime/internal/atomic"
10
11
"unsafe"
11
12
)
12
13
@@ -38,6 +39,34 @@ func initMetrics() {
38
39
return
39
40
}
40
41
metrics = map [string ]metricData {
42
+ "/gc/cycles/automatic:gc-cycles" : {
43
+ deps : makeStatDepSet (sysStatsDep ),
44
+ compute : func (in * statAggregate , out * metricValue ) {
45
+ out .kind = metricKindUint64
46
+ out .scalar = in .sysStats .gcCyclesDone - in .sysStats .gcCyclesForced
47
+ },
48
+ },
49
+ "/gc/cycles/forced:gc-cycles" : {
50
+ deps : makeStatDepSet (sysStatsDep ),
51
+ compute : func (in * statAggregate , out * metricValue ) {
52
+ out .kind = metricKindUint64
53
+ out .scalar = in .sysStats .gcCyclesForced
54
+ },
55
+ },
56
+ "/gc/cycles/total:gc-cycles" : {
57
+ deps : makeStatDepSet (sysStatsDep ),
58
+ compute : func (in * statAggregate , out * metricValue ) {
59
+ out .kind = metricKindUint64
60
+ out .scalar = in .sysStats .gcCyclesDone
61
+ },
62
+ },
63
+ "/gc/heap/goal:bytes" : {
64
+ deps : makeStatDepSet (sysStatsDep ),
65
+ compute : func (in * statAggregate , out * metricValue ) {
66
+ out .kind = metricKindUint64
67
+ out .scalar = in .sysStats .heapGoal
68
+ },
69
+ },
41
70
"/gc/heap/objects:objects" : {
42
71
deps : makeStatDepSet (heapStatsDep ),
43
72
compute : func (in * statAggregate , out * metricValue ) {
@@ -248,14 +277,17 @@ func (a *heapStatsAggregate) compute() {
248
277
// heapStatsAggregate, means there could be some skew, but because of
249
278
// these stats are independent, there's no real consistency issue here.
250
279
type sysStatsAggregate struct {
251
- stacksSys uint64
252
- mSpanSys uint64
253
- mSpanInUse uint64
254
- mCacheSys uint64
255
- mCacheInUse uint64
256
- buckHashSys uint64
257
- gcMiscSys uint64
258
- otherSys uint64
280
+ stacksSys uint64
281
+ mSpanSys uint64
282
+ mSpanInUse uint64
283
+ mCacheSys uint64
284
+ mCacheInUse uint64
285
+ buckHashSys uint64
286
+ gcMiscSys uint64
287
+ otherSys uint64
288
+ heapGoal uint64
289
+ gcCyclesDone uint64
290
+ gcCyclesForced uint64
259
291
}
260
292
261
293
// compute populates the sysStatsAggregate with values from the runtime.
@@ -264,6 +296,9 @@ func (a *sysStatsAggregate) compute() {
264
296
a .buckHashSys = memstats .buckhash_sys .load ()
265
297
a .gcMiscSys = memstats .gcMiscSys .load ()
266
298
a .otherSys = memstats .other_sys .load ()
299
+ a .heapGoal = atomic .Load64 (& memstats .next_gc )
300
+ a .gcCyclesDone = uint64 (memstats .numgc )
301
+ a .gcCyclesForced = uint64 (memstats .numforcedgc )
267
302
268
303
systemstack (func () {
269
304
lock (& mheap_ .lock )
0 commit comments