Skip to content

Commit 6865464

Browse files
committed
static: merge useMetric with mapMetricsToIndices
1 parent 86ffeaf commit 6865464

File tree

3 files changed

+56
-107
lines changed

3 files changed

+56
-107
lines changed

internal/plot/plots.go

Lines changed: 34 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ import (
77
)
88

99
func init() {
10-
// lastgc and timestamp are both special cases.
11-
12-
// lastgc draws vertical lines represeting GCs on certain plots.
13-
useMetrics("lastgc")
14-
// timestamp is the metric is the data for the time axis used on all plots.
15-
useMetrics("timestamp")
16-
1710
registerPlotFunc(makeHeapGlobalPlot)
1811
registerPlotFunc(makeHeapDetailsPlot)
1912
registerPlotFunc(makeLiveObjectsPlot)
@@ -36,12 +29,6 @@ func init() {
3629
/*
3730
* heap (global)
3831
*/
39-
var _ = useMetrics("heap-global",
40-
"/memory/classes/heap/objects:bytes",
41-
"/memory/classes/heap/unused:bytes",
42-
"/memory/classes/heap/free:bytes",
43-
"/memory/classes/heap/released:bytes",
44-
)
4532

4633
type heapGlobal struct {
4734
enabled bool
@@ -53,7 +40,8 @@ type heapGlobal struct {
5340
}
5441

5542
func makeHeapGlobalPlot(idxs map[string]int) runtimeMetric {
56-
indices, allFound := metricIndices(idxs,
43+
indices, allFound := mapMetricsToIndices(idxs,
44+
"heap-global",
5745
"/memory/classes/heap/objects:bytes",
5846
"/memory/classes/heap/unused:bytes",
5947
"/memory/classes/heap/free:bytes",
@@ -124,14 +112,6 @@ func (p *heapGlobal) values(samples []metrics.Sample) any {
124112
/*
125113
* heap (details)
126114
*/
127-
var _ = useMetrics("heap-details",
128-
"/memory/classes/heap/objects:bytes",
129-
"/memory/classes/heap/unused:bytes",
130-
"/memory/classes/heap/free:bytes",
131-
"/memory/classes/heap/released:bytes",
132-
"/memory/classes/heap/stacks:bytes",
133-
"/gc/heap/goal:bytes",
134-
)
135115

136116
type heapDetails struct {
137117
enabled bool
@@ -145,7 +125,8 @@ type heapDetails struct {
145125
}
146126

147127
func makeHeapDetailsPlot(idxs map[string]int) runtimeMetric {
148-
indices, allFound := metricIndices(idxs,
128+
indices, allFound := mapMetricsToIndices(idxs,
129+
"heap-details",
149130
"/memory/classes/heap/objects:bytes",
150131
"/memory/classes/heap/unused:bytes",
151132
"/memory/classes/heap/free:bytes",
@@ -226,7 +207,6 @@ func (p *heapDetails) values(samples []metrics.Sample) any {
226207
/*
227208
* live objects
228209
*/
229-
var _ = useMetrics("live-objects", "/gc/heap/objects:objects")
230210

231211
type liveObjects struct {
232212
enabled bool
@@ -235,7 +215,8 @@ type liveObjects struct {
235215
}
236216

237217
func makeLiveObjectsPlot(idxs map[string]int) runtimeMetric {
238-
indices, allFound := metricIndices(idxs,
218+
indices, allFound := mapMetricsToIndices(idxs,
219+
"live-objects",
239220
"/gc/heap/objects:objects",
240221
)
241222

@@ -277,10 +258,6 @@ func (p *liveObjects) values(samples []metrics.Sample) any {
277258
/*
278259
* live bytes
279260
*/
280-
var _ = useMetrics("live-bytes",
281-
"/gc/heap/allocs:bytes",
282-
"/gc/heap/frees:bytes",
283-
)
284261

285262
type liveBytes struct {
286263
enabled bool
@@ -290,7 +267,8 @@ type liveBytes struct {
290267
}
291268

292269
func makeLiveBytesPlot(idxs map[string]int) runtimeMetric {
293-
indices, allFound := metricIndices(idxs,
270+
indices, allFound := mapMetricsToIndices(idxs,
271+
"live-bytes",
294272
"/gc/heap/allocs:bytes",
295273
"/gc/heap/frees:bytes",
296274
)
@@ -335,12 +313,6 @@ func (p *liveBytes) values(samples []metrics.Sample) any {
335313
/*
336314
* mspan mcache
337315
*/
338-
var _ = useMetrics("mspan-mcache",
339-
"/memory/classes/metadata/mspan/inuse:bytes",
340-
"/memory/classes/metadata/mspan/free:bytes",
341-
"/memory/classes/metadata/mcache/inuse:bytes",
342-
"/memory/classes/metadata/mcache/free:bytes",
343-
)
344316

345317
type mspanMcache struct {
346318
enabled bool
@@ -352,7 +324,8 @@ type mspanMcache struct {
352324
}
353325

354326
func makeMSpanMCachePlot(idxs map[string]int) runtimeMetric {
355-
indices, allFound := metricIndices(idxs,
327+
indices, allFound := mapMetricsToIndices(idxs,
328+
"mspan-mcache",
356329
"/memory/classes/metadata/mspan/inuse:bytes",
357330
"/memory/classes/metadata/mspan/free:bytes",
358331
"/memory/classes/metadata/mcache/inuse:bytes",
@@ -422,7 +395,6 @@ func (p *mspanMcache) values(samples []metrics.Sample) any {
422395
/*
423396
* goroutines
424397
*/
425-
var _ = useMetrics("goroutines", "/sched/goroutines:goroutines")
426398

427399
type goroutines struct {
428400
enabled bool
@@ -431,7 +403,8 @@ type goroutines struct {
431403
}
432404

433405
func makeGoroutinesPlot(idxs map[string]int) runtimeMetric {
434-
indices, allFound := metricIndices(idxs,
406+
indices, allFound := mapMetricsToIndices(idxs,
407+
"goroutines",
435408
"/sched/goroutines:goroutines",
436409
)
437410

@@ -470,10 +443,6 @@ func (p *goroutines) values(samples []metrics.Sample) any {
470443
/*
471444
* size classes
472445
*/
473-
var _ = useMetrics("size-classes",
474-
"/gc/heap/allocs-by-size:bytes",
475-
"/gc/heap/frees-by-size:bytes",
476-
)
477446

478447
type sizeClasses struct {
479448
enabled bool
@@ -484,7 +453,8 @@ type sizeClasses struct {
484453
}
485454

486455
func makeSizeClassesPlot(idxs map[string]int) runtimeMetric {
487-
indices, allFound := metricIndices(idxs,
456+
indices, allFound := mapMetricsToIndices(idxs,
457+
"size-classes",
488458
"/gc/heap/allocs-by-size:bytes",
489459
"/gc/heap/frees-by-size:bytes",
490460
)
@@ -556,7 +526,6 @@ func (p *sizeClasses) values(samples []metrics.Sample) any {
556526
/*
557527
* gc pauses
558528
*/
559-
var _ = useMetrics("gc-pauses", "/gc/pauses:seconds")
560529

561530
type gcpauses struct {
562531
enabled bool
@@ -567,7 +536,8 @@ type gcpauses struct {
567536
}
568537

569538
func makeGCPausesPlot(idxs map[string]int) runtimeMetric {
570-
indices, allFound := metricIndices(idxs,
539+
indices, allFound := mapMetricsToIndices(idxs,
540+
"gc-pauses",
571541
"/gc/pauses:seconds",
572542
)
573543

@@ -619,7 +589,6 @@ func (p *gcpauses) values(samples []metrics.Sample) any {
619589
/*
620590
* time spent in runnable state
621591
*/
622-
var _ = useMetrics("runnable-time", "/sched/latencies:seconds")
623592

624593
type runnableTime struct {
625594
enabled bool
@@ -630,7 +599,8 @@ type runnableTime struct {
630599
}
631600

632601
func makeRunnableTimePlot(idxs map[string]int) runtimeMetric {
633-
indices, allFound := metricIndices(idxs,
602+
indices, allFound := mapMetricsToIndices(idxs,
603+
"runnable-time",
634604
"/sched/latencies:seconds",
635605
)
636606

@@ -684,10 +654,6 @@ func (p *runnableTime) values(samples []metrics.Sample) any {
684654
/*
685655
* scheduling events
686656
*/
687-
var _ = useMetrics("sched-events",
688-
"/sched/latencies:seconds",
689-
"/sched/gomaxprocs:threads",
690-
)
691657

692658
type schedEvents struct {
693659
enabled bool
@@ -698,7 +664,8 @@ type schedEvents struct {
698664
}
699665

700666
func makeSchedEventsPlot(idxs map[string]int) runtimeMetric {
701-
indices, allFound := metricIndices(idxs,
667+
indices, allFound := mapMetricsToIndices(idxs,
668+
"sched-events",
702669
"/sched/latencies:seconds",
703670
"/sched/gomaxprocs:threads",
704671
)
@@ -772,7 +739,6 @@ func (p *schedEvents) values(samples []metrics.Sample) any {
772739
/*
773740
* cgo
774741
*/
775-
var _ = useMetrics("cgo", "/cgo/go-to-c-calls:calls")
776742

777743
type cgo struct {
778744
enabled bool
@@ -781,7 +747,8 @@ type cgo struct {
781747
}
782748

783749
func makeCGOPlot(idxs map[string]int) runtimeMetric {
784-
indices, allFound := metricIndices(idxs,
750+
indices, allFound := mapMetricsToIndices(idxs,
751+
"cgo",
785752
"/cgo/go-to-c-calls:calls",
786753
)
787754

@@ -829,15 +796,15 @@ func (p *cgo) values(samples []metrics.Sample) any {
829796
/*
830797
* gc stack size
831798
*/
832-
var _ = useMetrics("gc-stack-size", "/gc/stack/starting-size:bytes")
833799

834800
type gcStackSize struct {
835801
enabled bool
836802
idxstack int
837803
}
838804

839805
func makeGCStackSizePlot(idxs map[string]int) runtimeMetric {
840-
indices, allFound := metricIndices(idxs,
806+
indices, allFound := mapMetricsToIndices(idxs,
807+
"gc-stack-size",
841808
"/gc/stack/starting-size:bytes",
842809
)
843810

@@ -876,11 +843,6 @@ func (p *gcStackSize) values(samples []metrics.Sample) any {
876843
/*
877844
* GC cycles
878845
*/
879-
var _ = useMetrics("gc-cycles",
880-
"/gc/cycles/automatic:gc-cycles",
881-
"/gc/cycles/forced:gc-cycles",
882-
"/gc/cycles/total:gc-cycles",
883-
)
884846

885847
type gcCycles struct {
886848
enabled bool
@@ -893,7 +855,8 @@ type gcCycles struct {
893855
}
894856

895857
func makeGCCyclesPlot(idxs map[string]int) runtimeMetric {
896-
indices, allFound := metricIndices(idxs,
858+
indices, allFound := mapMetricsToIndices(idxs,
859+
"gc-cycles",
897860
"/gc/cycles/automatic:gc-cycles",
898861
"/gc/cycles/forced:gc-cycles",
899862
"/gc/cycles/total:gc-cycles",
@@ -963,12 +926,6 @@ func (p *gcCycles) values(samples []metrics.Sample) any {
963926
/*
964927
* mspan mcache
965928
*/
966-
var _ = useMetrics("memory-classes",
967-
"/memory/classes/os-stacks:bytes",
968-
"/memory/classes/other:bytes",
969-
"/memory/classes/profiling/buckets:bytes",
970-
"/memory/classes/total:bytes",
971-
)
972929

973930
type memoryClasses struct {
974931
enabled bool
@@ -980,7 +937,8 @@ type memoryClasses struct {
980937
}
981938

982939
func makeMemoryClassesPlot(idxs map[string]int) runtimeMetric {
983-
indices, allFound := metricIndices(idxs,
940+
indices, allFound := mapMetricsToIndices(idxs,
941+
"memory-classes",
984942
"/memory/classes/os-stacks:bytes",
985943
"/memory/classes/other:bytes",
986944
"/memory/classes/profiling/buckets:bytes",
@@ -1050,13 +1008,6 @@ func (p *memoryClasses) values(samples []metrics.Sample) any {
10501008
/*
10511009
* cpu classes (gc)
10521010
*/
1053-
var _ = useMetrics("cpu-classes-gc",
1054-
"/cpu/classes/gc/mark/assist:cpu-seconds",
1055-
"/cpu/classes/gc/mark/dedicated:cpu-seconds",
1056-
"/cpu/classes/gc/mark/idle:cpu-seconds",
1057-
"/cpu/classes/gc/pause:cpu-seconds",
1058-
"/cpu/classes/gc/total:cpu-seconds",
1059-
)
10601011

10611012
type cpuClassesGC struct {
10621013
enabled bool
@@ -1077,7 +1028,8 @@ type cpuClassesGC struct {
10771028
}
10781029

10791030
func makeCPUClassesGCPlot(idxs map[string]int) runtimeMetric {
1080-
indices, allFound := metricIndices(idxs,
1031+
indices, allFound := mapMetricsToIndices(idxs,
1032+
"cpu-classes-gc",
10811033
"/cpu/classes/gc/mark/assist:cpu-seconds",
10821034
"/cpu/classes/gc/mark/dedicated:cpu-seconds",
10831035
"/cpu/classes/gc/mark/idle:cpu-seconds",
@@ -1186,10 +1138,6 @@ func (p *cpuClassesGC) values(samples []metrics.Sample) any {
11861138
/*
11871139
* mutex wait
11881140
*/
1189-
var _ = useMetrics("mutex-wait",
1190-
"/sync/mutex/wait/total:seconds",
1191-
)
1192-
11931141
type mutexWait struct {
11941142
enabled bool
11951143
idxMutexWait int
@@ -1199,7 +1147,8 @@ type mutexWait struct {
11991147
}
12001148

12011149
func makeMutexWaitPlot(idxs map[string]int) runtimeMetric {
1202-
indices, allFound := metricIndices(idxs,
1150+
indices, allFound := mapMetricsToIndices(idxs,
1151+
"mutex-wait",
12031152
"/cpu/classes/gc/mark/assist:cpu-seconds",
12041153
)
12051154

@@ -1258,12 +1207,6 @@ func (p *mutexWait) values(samples []metrics.Sample) any {
12581207
/*
12591208
* gc scan
12601209
*/
1261-
var _ = useMetrics("gc-scan",
1262-
"/gc/scan/globals:bytes",
1263-
"/gc/scan/heap:bytes",
1264-
"/gc/scan/stack:bytes",
1265-
"/gc/scan/total:bytes",
1266-
)
12671210

12681211
type gcScan struct {
12691212
enabled bool
@@ -1274,7 +1217,8 @@ type gcScan struct {
12741217
}
12751218

12761219
func makeGCScanPlot(idxs map[string]int) runtimeMetric {
1277-
indices, allFound := metricIndices(idxs,
1220+
indices, allFound := mapMetricsToIndices(idxs,
1221+
"gc-scan",
12781222
"/gc/scan/globals:bytes",
12791223
"/gc/scan/heap:bytes",
12801224
"/gc/scan/stack:bytes",

internal/plot/plots_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ func kindstr(k metrics.ValueKind) string {
2323
}
2424

2525
func TestUnusedRuntimeMetrics(t *testing.T) {
26+
// Creating a config compiles the list of metrics used by Statsviz.
27+
l, err := NewList(nil)
28+
if err != nil {
29+
t.Fatal(err)
30+
}
31+
_ = l.Config()
32+
2633
// This "test" can't fail. It just prints which of the metrics exported by
2734
// runtime/metrics are not used in any Statsviz plot.
2835
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)

0 commit comments

Comments
 (0)