aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/metrics.go
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2020-08-06 15:44:27 +0000
committerMichael Knyszek <mknyszek@google.com>2020-10-26 18:29:18 +0000
commit07c3f65d53df7bb9f84bdbd2ab64c0ae12337e3e (patch)
tree78f694a0afbe886d65d7483a2205b0021bf58310 /src/runtime/metrics.go
parent74e566ed1dc52f7ef58093aff936a0931537a1ad (diff)
downloadgo-07c3f65d53df7bb9f84bdbd2ab64c0ae12337e3e.tar.gz
go-07c3f65d53df7bb9f84bdbd2ab64c0ae12337e3e.zip
runtime,runtime/metrics: add heap object count metric
For #37112. Change-Id: Idd3dd5c84215ddd1ab05c2e76e848aa0a4d40fb0 Reviewed-on: https://go-review.googlesource.com/c/go/+/247043 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>
Diffstat (limited to 'src/runtime/metrics.go')
-rw-r--r--src/runtime/metrics.go18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/runtime/metrics.go b/src/runtime/metrics.go
index 44b5a29751..cf619cca4b 100644
--- a/src/runtime/metrics.go
+++ b/src/runtime/metrics.go
@@ -38,6 +38,13 @@ func initMetrics() {
return
}
metrics = map[string]metricData{
+ "/gc/heap/objects:objects": {
+ deps: makeStatDepSet(heapStatsDep),
+ compute: func(in *statAggregate, out *metricValue) {
+ out.kind = metricKindUint64
+ out.scalar = in.heapStats.numObjects
+ },
+ },
"/memory/classes/heap/free:bytes": {
deps: makeStatDepSet(heapStatsDep),
compute: func(in *statAggregate, out *metricValue) {
@@ -210,9 +217,13 @@ func (s *statDepSet) has(d statDep) bool {
type heapStatsAggregate struct {
heapStatsDelta
+ // Derived from values in heapStatsDelta.
+
// inObjects is the bytes of memory occupied by objects,
- // derived from other values in heapStats.
inObjects uint64
+
+ // numObjects is the number of live objects in the heap.
+ numObjects uint64
}
// compute populates the heapStatsAggregate with values from the runtime.
@@ -221,8 +232,11 @@ func (a *heapStatsAggregate) compute() {
// Calculate derived stats.
a.inObjects = uint64(a.largeAlloc - a.largeFree)
+ a.numObjects = uint64(a.largeAllocCount - a.largeFreeCount)
for i := range a.smallAllocCount {
- a.inObjects += uint64(a.smallAllocCount[i]-a.smallFreeCount[i]) * uint64(class_to_size[i])
+ n := uint64(a.smallAllocCount[i] - a.smallFreeCount[i])
+ a.inObjects += n * uint64(class_to_size[i])
+ a.numObjects += n
}
}