Skip to content

Commit 80ddb15

Browse files
committed
internal/plot: simplify description
1 parent b508341 commit 80ddb15

25 files changed

+62
-91
lines changed

internal/plot/list.go

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,21 @@ func IsReservedPlotName(name string) bool {
1818
return true
1919
}
2020
return slices.ContainsFunc(registry, func(pd description) bool {
21-
return pd.name == name
21+
return nameFromLayout(pd.layout) == name
2222
})
2323
}
2424

25+
func nameFromLayout(layout any) string {
26+
switch layout := layout.(type) {
27+
case Scatter:
28+
return layout.Name
29+
case Heatmap:
30+
return layout.Name
31+
default:
32+
panic(fmt.Sprintf("unknown plot layout type %T", layout))
33+
}
34+
}
35+
2536
// getvalues extracts, from a sample of runtime metrics, a slice with all
2637
// the metrics necessary for a single plot.
2738
type getvalues func(time.Time, []metrics.Sample) any
@@ -78,26 +89,11 @@ func (pl *List) enabledPlots() []runtimePlot {
7889
continue
7990
}
8091

81-
switch layout := plot.layout.(type) {
82-
case Scatter:
83-
layout.Name = plot.name
84-
layout.Tags = plot.tags
85-
plots = append(plots, runtimePlot{
86-
name: plot.name,
87-
getvals: plot.getvalues(),
88-
layout: layout,
89-
})
90-
case Heatmap:
91-
layout.Name = plot.name
92-
layout.Tags = plot.tags
93-
plots = append(plots, runtimePlot{
94-
name: plot.name,
95-
getvals: plot.getvalues(),
96-
layout: layout,
97-
})
98-
default:
99-
panic(fmt.Sprintf("unknown plot layout type %T", layout))
100-
}
92+
plots = append(plots, runtimePlot{
93+
name: nameFromLayout(plot.layout),
94+
getvals: plot.getvalues(),
95+
layout: plot.layout,
96+
})
10197
}
10298

10399
return plots

internal/plot/plot_cgo.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
)
77

88
var _ = register(description{
9-
name: "cgo",
10-
tags: []tag{tagMisc},
119
metrics: []string{
1210
"/cgo/go-to-c-calls:calls",
1311
},
@@ -22,7 +20,8 @@ var _ = register(description{
2220
}
2321
},
2422
layout: Scatter{
25-
Name: "TODO(set later)",
23+
Name: "cgo",
24+
Tags: []string{tagMisc},
2625
Title: "CGO Calls",
2726
Type: "bar",
2827
Layout: ScatterLayout{

internal/plot/plot_cpu_gc.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
)
77

88
var _ = register(description{
9-
name: "cpu-gc",
10-
tags: []tag{tagCPU, tagGC},
119
metrics: []string{
1210
"/cpu/classes/gc/mark/assist:cpu-seconds",
1311
"/cpu/classes/gc/mark/dedicated:cpu-seconds",
@@ -35,7 +33,8 @@ var _ = register(description{
3533
}
3634
},
3735
layout: Scatter{
38-
Name: "TODO(set later)",
36+
Name: "cpu-gc",
37+
Tags: []tag{tagCPU, tagGC},
3938
Title: "CPU (Garbage Collector)",
4039
Type: "scatter",
4140
Events: "lastgc",

internal/plot/plot_cpu_overall.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
)
77

88
var _ = register(description{
9-
name: "cpu-overall",
10-
tags: []tag{tagCPU},
119
metrics: []string{
1210
"/cpu/classes/user:cpu-seconds",
1311
"/cpu/classes/scavenge/total:cpu-seconds",
@@ -39,7 +37,8 @@ var _ = register(description{
3937
}
4038
},
4139
layout: Scatter{
42-
Name: "TODO(set later)",
40+
Name: "cpu-overall",
41+
Tags: []tag{tagCPU},
4342
Title: "CPU (Overall)",
4443
Type: "bar",
4544
Events: "lastgc",

internal/plot/plot_cpu_scavenger.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
)
77

88
var _ = register(description{
9-
name: "cpu-scavenger",
10-
tags: []tag{tagCPU, tagGC},
119
metrics: []string{
1210
"/cpu/classes/scavenge/assist:cpu-seconds",
1311
"/cpu/classes/scavenge/background:cpu-seconds",
@@ -26,7 +24,8 @@ var _ = register(description{
2624
}
2725
},
2826
layout: Scatter{
29-
Name: "TODO(set later)",
27+
Name: "cpu-scavenger",
28+
Tags: []tag{tagCPU, tagGC},
3029
Title: "CPU (Scavenger)",
3130
Type: "bar",
3231
Events: "lastgc",

internal/plot/plot_gc.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
)
88

99
var _ = register(description{
10-
name: "garbage collection",
11-
tags: []tag{tagGC},
1210
metrics: []string{
1311
"/gc/gomemlimit:bytes",
1412
"/gc/heap/live:bytes",
@@ -38,6 +36,7 @@ var _ = register(description{
3836
},
3937
layout: Scatter{
4038
Name: "garbage collection",
39+
Tags: []tag{tagGC},
4140
Title: "GC Memory Summary",
4241
Type: "scatter",
4342
Events: "lastgc",

internal/plot/plot_gc_cycles.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
)
77

88
var _ = register(description{
9-
name: "gc-cycles",
10-
tags: []tag{tagGC},
119
metrics: []string{
1210
"/gc/cycles/automatic:gc-cycles",
1311
"/gc/cycles/forced:gc-cycles",
@@ -27,7 +25,8 @@ var _ = register(description{
2725
}
2826
},
2927
layout: Scatter{
30-
Name: "TODO(set later)",
28+
Name: "gc-cycles",
29+
Tags: []tag{tagGC},
3130
Title: "Completed GC Cycles",
3231
Type: "bar",
3332
Layout: ScatterLayout{

internal/plot/plot_gc_scan.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
)
77

88
var _ = register(description{
9-
name: "gc-scan",
10-
tags: []tag{tagGC},
119
metrics: []string{
1210
"/gc/scan/globals:bytes",
1311
"/gc/scan/heap:bytes",
@@ -23,7 +21,8 @@ var _ = register(description{
2321
}
2422
},
2523
layout: Scatter{
26-
Name: "TODO(set later)",
24+
Name: "gc-scan",
25+
Tags: []tag{tagGC},
2726
Title: "GC Scan",
2827
Type: "bar",
2928
Events: "lastgc",

internal/plot/plot_goroutines.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
)
99

1010
var _ = register(description{
11-
name: "goroutines",
12-
tags: []tag{tagScheduler},
1311
metrics: []string{
1412
"/sched/goroutines:goroutines",
1513
"/sched/goroutines-created:goroutines",
@@ -34,7 +32,8 @@ var _ = register(description{
3432
},
3533

3634
layout: Scatter{
37-
Name: "TODO(set later)",
35+
Name: "goroutines",
36+
Tags: []tag{tagScheduler},
3837
Title: "Goroutines",
3938
Type: "scatter",
4039
Layout: ScatterLayout{

internal/plot/plot_gs_stack_size.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
)
77

88
var _ = register(description{
9-
name: "gc-stack-size",
10-
tags: []tag{tagGC},
119
metrics: []string{
1210
"/gc/stack/starting-size:bytes",
1311
},
@@ -18,7 +16,8 @@ var _ = register(description{
1816
}
1917
},
2018
layout: Scatter{
21-
Name: "TODO(set later)",
19+
Name: "gc-stack-size",
20+
Tags: []tag{tagGC},
2221
Title: "Goroutines stack starting size",
2322
Type: "scatter",
2423
Layout: ScatterLayout{

0 commit comments

Comments
 (0)