Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/runtime/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ func initMetrics() {
out.scalar = in.sysStats.heapGoal
},
},
"/gc/heap/live:bytes": {
deps: makeStatDepSet(heapStatsDep),
compute: func(in *statAggregate, out *metricValue) {
out.kind = metricKindUint64
out.scalar = gcController.heapMarked
},
},
"/gc/heap/objects:objects": {
deps: makeStatDepSet(heapStatsDep),
compute: func(in *statAggregate, out *metricValue) {
Expand Down
5 changes: 5 additions & 0 deletions src/runtime/metrics/description.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ var allDesc = []Description{
Description: "Heap size target for the end of the GC cycle.",
Kind: KindUint64,
},
{
Name: "/gc/heap/live:bytes",
Description: "Heap memory occupied by live objects that were marked by the previous GC.",
Kind: KindUint64,
},
{
Name: "/gc/heap/objects:objects",
Description: "Number of objects, live or unswept, occupying heap memory.",
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/metrics/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ Below is the full list of supported metrics, ordered lexicographically.
/gc/heap/goal:bytes
Heap size target for the end of the GC cycle.

/gc/heap/live:bytes
Heap memory occupied by live objects that were marked by the previous GC.

/gc/heap/objects:objects
Number of objects, live or unswept, occupying heap memory.

Expand Down
6 changes: 6 additions & 0 deletions src/runtime/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func TestReadMetricsConsistency(t *testing.T) {
allocs, frees uint64
allocdBytes, freedBytes uint64
total, totalBytes uint64
liveBytes uint64
}
var gc struct {
numGC uint64
Expand Down Expand Up @@ -248,6 +249,8 @@ func TestReadMetricsConsistency(t *testing.T) {
totalVirtual.got = samples[i].Value.Uint64()
case "/memory/classes/heap/objects:bytes":
objects.totalBytes = samples[i].Value.Uint64()
case "/gc/heap/live:bytes":
objects.liveBytes = samples[i].Value.Uint64()
case "/gc/heap/objects:objects":
objects.total = samples[i].Value.Uint64()
case "/gc/heap/allocs:bytes":
Expand Down Expand Up @@ -313,6 +316,9 @@ func TestReadMetricsConsistency(t *testing.T) {
if got, want := objects.allocs-objects.frees, objects.total; got != want {
t.Errorf("mismatch between object alloc/free tallies and total: got %d, want %d", got, want)
}
if objects.liveBytes > objects.totalBytes {
t.Errorf("liveBytes bytes: %d > totalBytes: %d", objects.liveBytes, objects.totalBytes)
}
if got, want := objects.allocdBytes-objects.freedBytes, objects.totalBytes; got != want {
t.Errorf("mismatch between object alloc/free tallies and total: got %d, want %d", got, want)
}
Expand Down