Skip to content

Commit f95620a

Browse files
committed
internal/plot: cosmetics
1 parent 26cd9d4 commit f95620a

File tree

3 files changed

+51
-55
lines changed

3 files changed

+51
-55
lines changed

internal/plot/layouts.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package plot
33
import "runtime/metrics"
44

55
var heapGlobalLayout = Scatter{
6-
Name: "TODO",
6+
Name: "TODO(set later)",
77
Title: "Heap (global)",
88
Type: "scatter",
99
Events: "lastgc",
@@ -39,7 +39,7 @@ var heapGlobalLayout = Scatter{
3939
}
4040

4141
var heapDetailslLayout = Scatter{
42-
Name: "TODO",
42+
Name: "TODO(set later)",
4343
Title: "Heap (details)",
4444
Type: "scatter",
4545
Events: "lastgc",
@@ -74,7 +74,7 @@ var heapDetailslLayout = Scatter{
7474
}
7575

7676
var liveObjectsLayout = Scatter{
77-
Name: "TODO",
77+
Name: "TODO(set later)",
7878
Title: "Live Objects in Heap",
7979
Type: "bar",
8080
Events: "lastgc",
@@ -94,7 +94,7 @@ var liveObjectsLayout = Scatter{
9494
}
9595

9696
var liveBytesLayout = Scatter{
97-
Name: "TODO",
97+
Name: "TODO(set later)",
9898
Title: "Live Bytes in Heap",
9999
Type: "bar",
100100
Events: "lastgc",
@@ -114,7 +114,7 @@ var liveBytesLayout = Scatter{
114114
}
115115

116116
var mspanMCacheLayout = Scatter{
117-
Name: "TODO",
117+
Name: "TODO(set later)",
118118
Title: "MSpan/MCache",
119119
Type: "scatter",
120120
Events: "lastgc",
@@ -150,7 +150,7 @@ var mspanMCacheLayout = Scatter{
150150
}
151151

152152
var goroutinesLayout = Scatter{
153-
Name: "TODO",
153+
Name: "TODO(set later)",
154154
Title: "Goroutines",
155155
Type: "scatter",
156156
Events: "lastgc",
@@ -187,7 +187,7 @@ func sizeClassesLayout(samples []metrics.Sample) Heatmap {
187187
buckets := downsampleBuckets(allocsBySize, 1)
188188

189189
return Heatmap{
190-
Name: "TODO",
190+
Name: "TODO(set later)",
191191
Title: "Size Classes",
192192
Type: "heatmap",
193193
UpdateFreq: 5,
@@ -219,7 +219,7 @@ func gcPausesLayout(samples []metrics.Sample) Heatmap {
219219
buckets := downsampleBuckets(gcpauses, histfactor)
220220

221221
return Heatmap{
222-
Name: "TODO",
222+
Name: "TODO(set later)",
223223
Title: "Stop-the-world Pause Latencies",
224224
Type: "heatmap",
225225
UpdateFreq: 5,
@@ -251,7 +251,7 @@ func runnableTimeLayout(samples []metrics.Sample) Heatmap {
251251
buckets := downsampleBuckets(schedlat, histfactor)
252252

253253
return Heatmap{
254-
Name: "TODO",
254+
Name: "TODO(set later)",
255255
Title: "Time Goroutines Spend in 'Runnable' state",
256256
Type: "heatmap",
257257
UpdateFreq: 5,
@@ -276,7 +276,7 @@ func runnableTimeLayout(samples []metrics.Sample) Heatmap {
276276
}
277277

278278
var schedEventsLayout = Scatter{
279-
Name: "TODO",
279+
Name: "TODO(set later)",
280280
Title: "Goroutine Scheduling Events",
281281
Type: "scatter",
282282
Events: "lastgc",
@@ -301,7 +301,7 @@ var schedEventsLayout = Scatter{
301301
}
302302

303303
var cgoLayout = Scatter{
304-
Name: "TODO",
304+
Name: "TODO(set later)",
305305
Title: "CGO Calls",
306306
Type: "bar",
307307
Layout: ScatterLayout{
@@ -320,7 +320,7 @@ var cgoLayout = Scatter{
320320
}
321321

322322
var gcStackSizeLayout = Scatter{
323-
Name: "TODO",
323+
Name: "TODO(set later)",
324324
Title: "Starting Size of Goroutines Stacks",
325325
Type: "scatter",
326326
Layout: ScatterLayout{
@@ -338,7 +338,7 @@ var gcStackSizeLayout = Scatter{
338338
}
339339

340340
var gcCyclesLayout = Scatter{
341-
Name: "TODO",
341+
Name: "TODO(set later)",
342342
Title: "Completed GC Cycles",
343343
Type: "bar",
344344
Layout: ScatterLayout{
@@ -363,7 +363,7 @@ var gcCyclesLayout = Scatter{
363363
}
364364

365365
var memoryClassesLayout = Scatter{
366-
Name: "TODO",
366+
Name: "TODO(set later)",
367367
Title: "Memory classes",
368368
Type: "scatter",
369369
Events: "lastgc",
@@ -399,7 +399,7 @@ var memoryClassesLayout = Scatter{
399399
}
400400

401401
var cpuClassesLayout = Scatter{
402-
Name: "TODO",
402+
Name: "TODO(set later)",
403403
Title: "CPU classes (GC)",
404404
Type: "scatter",
405405
Events: "lastgc",
@@ -443,7 +443,7 @@ All this metrics are overestimates, and not directly comparable to system CPU ti
443443
}
444444

445445
var mutexWaitLayout = Scatter{
446-
Name: "TODO",
446+
Name: "TODO(set later)",
447447
Title: "Time Goroutines Spend Blocked on Mutexes",
448448
Type: "scatter",
449449
Events: "lastgc",
@@ -467,7 +467,7 @@ This metric is useful for identifying global changes in lock contention. Collect
467467
}
468468

469469
var gcScanLayout = Scatter{
470-
Name: "TODO",
470+
Name: "TODO(set later)",
471471
Title: "GC Scan",
472472
Type: "bar",
473473
Events: "lastgc",

internal/plot/plots.go

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import (
77
)
88

99
type plotDesc struct {
10+
// make creates the state (support struct) for the plot.
11+
make func(indices ...int) metricsGetter
12+
1013
name string
1114
metrics []string
1215
layout any
13-
make func(indices ...int) runtimeMetric
1416
}
1517

1618
var (
@@ -194,10 +196,6 @@ func init() {
194196
layout: gcScanLayout,
195197
make: makeGCScan,
196198
},
197-
198-
// reserved time serie names
199-
{name: "timestamp", make: nil}, // x axis
200-
{name: "lastgc", make: nil}, // gc events (vertical lines)
201199
}
202200
}
203201

@@ -210,7 +208,7 @@ type heapGlobal struct {
210208
idxreleased int
211209
}
212210

213-
func makeHeapGlobal(indices ...int) runtimeMetric {
211+
func makeHeapGlobal(indices ...int) metricsGetter {
214212
return &heapGlobal{
215213
idxobj: indices[0],
216214
idxunused: indices[1],
@@ -244,7 +242,7 @@ type heapDetails struct {
244242
idxgoal int
245243
}
246244

247-
func makeHeapDetails(indices ...int) runtimeMetric {
245+
func makeHeapDetails(indices ...int) metricsGetter {
248246
return &heapDetails{
249247
idxobj: indices[0],
250248
idxunused: indices[1],
@@ -281,7 +279,7 @@ type liveObjects struct {
281279
idxobjects int
282280
}
283281

284-
func makeLiveObjects(indices ...int) runtimeMetric {
282+
func makeLiveObjects(indices ...int) metricsGetter {
285283
return &liveObjects{
286284
idxobjects: indices[0],
287285
}
@@ -301,7 +299,7 @@ type liveBytes struct {
301299
idxfrees int
302300
}
303301

304-
func makeLiveBytes(indices ...int) runtimeMetric {
302+
func makeLiveBytes(indices ...int) metricsGetter {
305303
return &liveBytes{
306304
idxallocs: indices[0],
307305
idxfrees: indices[1],
@@ -327,7 +325,7 @@ type mspanMcache struct {
327325
idxmcacheFree int
328326
}
329327

330-
func makeMSpanMCache(indices ...int) runtimeMetric {
328+
func makeMSpanMCache(indices ...int) metricsGetter {
331329
return &mspanMcache{
332330
idxmspanInuse: indices[0],
333331
idxmspanFree: indices[1],
@@ -355,7 +353,7 @@ type goroutines struct {
355353
idxgs int
356354
}
357355

358-
func makeGoroutines(indices ...int) runtimeMetric {
356+
func makeGoroutines(indices ...int) metricsGetter {
359357
return &goroutines{
360358
idxgs: indices[0],
361359
}
@@ -374,7 +372,7 @@ type sizeClasses struct {
374372
idxfrees int
375373
}
376374

377-
func makeSizeClasses(indices ...int) runtimeMetric {
375+
func makeSizeClasses(indices ...int) metricsGetter {
378376
return &sizeClasses{
379377
idxallocs: indices[0],
380378
idxfrees: indices[1],
@@ -404,7 +402,7 @@ type gcpauses struct {
404402
idxgcpauses int
405403
}
406404

407-
func makeGCPauses(indices ...int) runtimeMetric {
405+
func makeGCPauses(indices ...int) metricsGetter {
408406
return &gcpauses{
409407
idxgcpauses: indices[0],
410408
}
@@ -429,7 +427,7 @@ type runnableTime struct {
429427
idxschedlat int
430428
}
431429

432-
func makeRunnableTime(indices ...int) runtimeMetric {
430+
func makeRunnableTime(indices ...int) metricsGetter {
433431
return &runnableTime{
434432
idxschedlat: indices[0],
435433
}
@@ -454,7 +452,7 @@ type schedEvents struct {
454452
lasttot uint64
455453
}
456454

457-
func makeSchedEvents(indices ...int) runtimeMetric {
455+
func makeSchedEvents(indices ...int) metricsGetter {
458456
return &schedEvents{
459457
idxschedlat: indices[0],
460458
idxGomaxprocs: indices[1],
@@ -500,7 +498,7 @@ type cgo struct {
500498
lastgo2c uint64
501499
}
502500

503-
func makeCGO(indices ...int) runtimeMetric {
501+
func makeCGO(indices ...int) metricsGetter {
504502
return &cgo{
505503
idxgo2c: indices[0],
506504
lastgo2c: math.MaxUint64,
@@ -525,7 +523,7 @@ type gcStackSize struct {
525523
idxstack int
526524
}
527525

528-
func makeGCStackSize(indices ...int) runtimeMetric {
526+
func makeGCStackSize(indices ...int) metricsGetter {
529527
return &gcStackSize{
530528
idxstack: indices[0],
531529
}
@@ -546,7 +544,7 @@ type gcCycles struct {
546544
lastAuto, lastForced, lastTotal uint64
547545
}
548546

549-
func makeGCCycles(indices ...int) runtimeMetric {
547+
func makeGCCycles(indices ...int) metricsGetter {
550548
return &gcCycles{
551549
idxAutomatic: indices[0],
552550
idxForced: indices[1],
@@ -586,7 +584,7 @@ type memoryClasses struct {
586584
idxTotal int
587585
}
588586

589-
func makeMemoryClasses(indices ...int) runtimeMetric {
587+
func makeMemoryClasses(indices ...int) metricsGetter {
590588
return &memoryClasses{
591589
idxOSStacks: indices[0],
592590
idxOther: indices[1],
@@ -627,7 +625,7 @@ type cpuClassesGC struct {
627625
lastTotal float64
628626
}
629627

630-
func makeCPUClassesGC(indices ...int) runtimeMetric {
628+
func makeCPUClassesGC(indices ...int) metricsGetter {
631629
return &cpuClassesGC{
632630
idxMarkAssist: indices[0],
633631
idxMarkDedicated: indices[1],
@@ -688,7 +686,7 @@ type mutexWait struct {
688686
lastMutexWait float64
689687
}
690688

691-
func makeMutexWait(indices ...int) runtimeMetric {
689+
func makeMutexWait(indices ...int) metricsGetter {
692690
return &mutexWait{
693691
idxMutexWait: indices[0],
694692
}
@@ -722,7 +720,7 @@ type gcScan struct {
722720
idxStack int
723721
}
724722

725-
func makeGCScan(indices ...int) runtimeMetric {
723+
func makeGCScan(indices ...int) metricsGetter {
726724
return &gcScan{
727725
idxGlobals: indices[0],
728726
idxHeap: indices[1],

internal/plot/registry.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,27 @@ import (
1111
"time"
1212
)
1313

14-
type plotFunc func(l *List, name string) runtimeMetric
15-
1614
// IsReservedPlotName reports whether that name is reserved for Statsviz plots
1715
// and thus can't be chosen by user (for user plots).
1816
func IsReservedPlotName(name string) bool {
17+
if name == "timestamp" || name == "lastgc" {
18+
return true
19+
}
1920
return slices.ContainsFunc(plotDescs, func(pd plotDesc) bool {
2021
return pd.name == name
2122
})
2223
}
2324

24-
// TODO: rename this to something meaningful
25-
type runtimeMetric interface {
26-
values([]metrics.Sample) any
25+
// a metricsGetter extracts, from a sample of runtime metrics, a slice with all
26+
// the metrics necessary for a single plot.
27+
type metricsGetter interface {
28+
values([]metrics.Sample) any // []uint64 | []float64
2729
}
2830

2931
// List holds all the plots that statsviz knows about. Some plots might be
3032
// disabled, if they rely on metrics that are unknown to the current Go version.
3133
type List struct {
32-
rtPlots []rtplot
34+
rtPlots []runtimePlot
3335
userPlots []UserPlot
3436

3537
once sync.Once // ensure Config is built once
@@ -43,10 +45,10 @@ type List struct {
4345
samples []metrics.Sample
4446
}
4547

46-
type rtplot struct {
48+
type runtimePlot struct {
4749
name string
48-
rt runtimeMetric
49-
layout any
50+
rt metricsGetter
51+
layout any // Scatter | Heatmap
5052
}
5153

5254
func NewList(userPlots []UserPlot) (*List, error) {
@@ -70,17 +72,13 @@ func NewList(userPlots []UserPlot) (*List, error) {
7072
return pl, nil
7173
}
7274

73-
func (pl *List) enabledPlots() []rtplot {
74-
plots := make([]rtplot, 0, len(plotDescs))
75+
func (pl *List) enabledPlots() []runtimePlot {
76+
plots := make([]runtimePlot, 0, len(plotDescs))
7577

7678
for _, plot := range plotDescs {
77-
if plot.make == nil {
78-
continue
79-
}
80-
8179
indices, enabled := pl.indicesFor(plot.metrics...)
8280
if enabled {
83-
plots = append(plots, rtplot{
81+
plots = append(plots, runtimePlot{
8482
name: plot.name,
8583
rt: plot.make(indices...),
8684
layout: assignName(plot.layout, plot.name),

0 commit comments

Comments
 (0)