mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime,runtime/metrics: add heap goal and GC cycle metrics
This change adds three new metrics: the heap goal, GC cycle count, and forced GC count. These metrics are identical to their MemStats counterparts. For #37112. Change-Id: I5a5e8dd550c0d646e5dcdbdf38274895e27cdd88 Reviewed-on: https://go-review.googlesource.com/c/go/+/247044 Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
parent
07c3f65d53
commit
a8b28ebc87
4 changed files with 86 additions and 8 deletions
|
|
@ -7,6 +7,7 @@ package runtime
|
|||
// Metrics implementation exported to runtime/metrics.
|
||||
|
||||
import (
|
||||
"runtime/internal/atomic"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
|
@ -38,6 +39,34 @@ func initMetrics() {
|
|||
return
|
||||
}
|
||||
metrics = map[string]metricData{
|
||||
"/gc/cycles/automatic:gc-cycles": {
|
||||
deps: makeStatDepSet(sysStatsDep),
|
||||
compute: func(in *statAggregate, out *metricValue) {
|
||||
out.kind = metricKindUint64
|
||||
out.scalar = in.sysStats.gcCyclesDone - in.sysStats.gcCyclesForced
|
||||
},
|
||||
},
|
||||
"/gc/cycles/forced:gc-cycles": {
|
||||
deps: makeStatDepSet(sysStatsDep),
|
||||
compute: func(in *statAggregate, out *metricValue) {
|
||||
out.kind = metricKindUint64
|
||||
out.scalar = in.sysStats.gcCyclesForced
|
||||
},
|
||||
},
|
||||
"/gc/cycles/total:gc-cycles": {
|
||||
deps: makeStatDepSet(sysStatsDep),
|
||||
compute: func(in *statAggregate, out *metricValue) {
|
||||
out.kind = metricKindUint64
|
||||
out.scalar = in.sysStats.gcCyclesDone
|
||||
},
|
||||
},
|
||||
"/gc/heap/goal:bytes": {
|
||||
deps: makeStatDepSet(sysStatsDep),
|
||||
compute: func(in *statAggregate, out *metricValue) {
|
||||
out.kind = metricKindUint64
|
||||
out.scalar = in.sysStats.heapGoal
|
||||
},
|
||||
},
|
||||
"/gc/heap/objects:objects": {
|
||||
deps: makeStatDepSet(heapStatsDep),
|
||||
compute: func(in *statAggregate, out *metricValue) {
|
||||
|
|
@ -248,14 +277,17 @@ func (a *heapStatsAggregate) compute() {
|
|||
// heapStatsAggregate, means there could be some skew, but because of
|
||||
// these stats are independent, there's no real consistency issue here.
|
||||
type sysStatsAggregate struct {
|
||||
stacksSys uint64
|
||||
mSpanSys uint64
|
||||
mSpanInUse uint64
|
||||
mCacheSys uint64
|
||||
mCacheInUse uint64
|
||||
buckHashSys uint64
|
||||
gcMiscSys uint64
|
||||
otherSys uint64
|
||||
stacksSys uint64
|
||||
mSpanSys uint64
|
||||
mSpanInUse uint64
|
||||
mCacheSys uint64
|
||||
mCacheInUse uint64
|
||||
buckHashSys uint64
|
||||
gcMiscSys uint64
|
||||
otherSys uint64
|
||||
heapGoal uint64
|
||||
gcCyclesDone uint64
|
||||
gcCyclesForced uint64
|
||||
}
|
||||
|
||||
// compute populates the sysStatsAggregate with values from the runtime.
|
||||
|
|
@ -264,6 +296,9 @@ func (a *sysStatsAggregate) compute() {
|
|||
a.buckHashSys = memstats.buckhash_sys.load()
|
||||
a.gcMiscSys = memstats.gcMiscSys.load()
|
||||
a.otherSys = memstats.other_sys.load()
|
||||
a.heapGoal = atomic.Load64(&memstats.next_gc)
|
||||
a.gcCyclesDone = uint64(memstats.numgc)
|
||||
a.gcCyclesForced = uint64(memstats.numforcedgc)
|
||||
|
||||
systemstack(func() {
|
||||
lock(&mheap_.lock)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue