Skip to content

Commit 0c433a8

Browse files
authored
Add go1.26 plots cleanup+finalizer queues (#143)
* internal/plot: add plots GC finalizers and cleanup queue * internal/plot: check described metrics exist
1 parent f07db71 commit 0c433a8

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

internal/plot/plot_gc_cleanups.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//go:build go1.26
2+
3+
package plot
4+
5+
import (
6+
"runtime/metrics"
7+
"time"
8+
)
9+
10+
var _ = register(description{
11+
metrics: []string{
12+
"/gc/cleanups/executed:cleanups",
13+
"/gc/cleanups/queued:cleanups",
14+
},
15+
getvalues: func() getvalues {
16+
return func(_ time.Time, samples []metrics.Sample) any {
17+
executed := samples[idx_gc_cleanups_executed_cleanups].Value.Uint64()
18+
queued := samples[idx_gc_cleanups_queued_cleanups].Value.Uint64()
19+
return []uint64{queued - executed}
20+
}
21+
},
22+
layout: Scatter{
23+
Name: "gc-cleanups",
24+
Tags: []tag{tagGC},
25+
Title: "GC Cleanups Queue",
26+
Type: "bar",
27+
Layout: ScatterLayout{
28+
BarMode: "stack",
29+
Yaxis: ScatterYAxis{
30+
Title: "cleanups",
31+
},
32+
},
33+
Subplots: []Subplot{
34+
{Unitfmt: "%{y}", Type: "bar", Name: "queue size"},
35+
},
36+
InfoText: `Approximate length of the cleanup functions queue (created by runtime.AddCleanup).
37+
Its <i>/gc/cleanups/queued:cleanups</i> - <i>/gc/cleanups/executed:cleanups</i>.
38+
Useful for detecting slow cleanups holding up the queue.
39+
`},
40+
})
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//go:build go1.26
2+
3+
package plot
4+
5+
import (
6+
"runtime/metrics"
7+
"time"
8+
)
9+
10+
var _ = register(description{
11+
metrics: []string{
12+
"/gc/finalizers/executed:finalizers",
13+
"/gc/finalizers/queued:finalizers",
14+
},
15+
getvalues: func() getvalues {
16+
return func(_ time.Time, samples []metrics.Sample) any {
17+
executed := samples[idx_gc_finalizers_executed_finalizers].Value.Uint64()
18+
queued := samples[idx_gc_finalizers_queued_finalizers].Value.Uint64()
19+
return []uint64{queued - executed}
20+
}
21+
},
22+
layout: Scatter{
23+
Name: "gc-finalizers",
24+
Tags: []tag{tagGC},
25+
Title: "GC Finalizers Queue",
26+
Type: "bar",
27+
Layout: ScatterLayout{
28+
BarMode: "stack",
29+
Yaxis: ScatterYAxis{
30+
Title: "finalizers",
31+
},
32+
},
33+
Subplots: []Subplot{
34+
{Unitfmt: "%{y}", Type: "bar", Name: "queue size"},
35+
},
36+
InfoText: `Length of the finalizer functions queue (created by runtime.AddFinalizer).
37+
Its <i>/gc/finalizers/queued:cleanups</i> - <i>/gc/finalizers/executed:cleanups</i>.
38+
Useful for detecting finalizers overwhelming the queue, either by being too slow, or by there being too many of them.
39+
`},
40+
})

internal/plot/registry.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ func (r *registry) register(desc description) {
8484
}
8585

8686
r.descriptions = append(r.descriptions, desc)
87+
88+
for _, metric := range desc.metrics {
89+
r.mustidx(metric)
90+
}
8791
}
8892

8993
func mustidx(metric string) int {

0 commit comments

Comments
 (0)