Skip to content

Commit 9259eee

Browse files
committed
internal/plots: add plots tags
1 parent 70d6b68 commit 9259eee

File tree

2 files changed

+27
-50
lines changed

2 files changed

+27
-50
lines changed

internal/plot/plots.go

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

99
type plotDesc struct {
10-
// make creates the state (support struct) for the plot.
11-
make func(indices ...int) metricsGetter
12-
1310
name string
11+
tags []string
1412
metrics []string
1513
layout any
14+
15+
// make creates the state (support struct) for the plot.
16+
make func(indices ...int) metricsGetter
1617
}
1718

1819
var (
@@ -36,18 +37,8 @@ func init() {
3637

3738
plotDescs = []plotDesc{
3839
{
39-
name: "heap-global",
40-
metrics: []string{
41-
"/memory/classes/heap/objects:bytes",
42-
"/memory/classes/heap/unused:bytes",
43-
"/memory/classes/heap/free:bytes",
44-
"/memory/classes/heap/released:bytes",
45-
},
46-
layout: heapGlobalLayout,
47-
make: makeHeapGlobal,
48-
},
49-
{
50-
name: "heap-details",
40+
name: "heap",
41+
tags: []string{"gc"},
5142
metrics: []string{
5243
"/memory/classes/heap/objects:bytes",
5344
"/memory/classes/heap/unused:bytes",
@@ -61,6 +52,7 @@ func init() {
6152
},
6253
{
6354
name: "live-objects",
55+
tags: []string{"gc"},
6456
metrics: []string{
6557
"/gc/heap/objects:objects",
6658
},
@@ -69,6 +61,7 @@ func init() {
6961
},
7062
{
7163
name: "live-bytes",
64+
tags: []string{"gc"},
7265
metrics: []string{
7366
"/gc/heap/allocs:bytes",
7467
"/gc/heap/frees:bytes",
@@ -78,6 +71,7 @@ func init() {
7871
},
7972
{
8073
name: "mspan-mcache",
74+
tags: []string{"gc"},
8175
metrics: []string{
8276
"/memory/classes/metadata/mspan/inuse:bytes",
8377
"/memory/classes/metadata/mspan/free:bytes",
@@ -89,6 +83,7 @@ func init() {
8983
},
9084
{
9185
name: "goroutines",
86+
tags: []string{"scheduler"},
9287
metrics: []string{
9388
"/sched/goroutines:goroutines",
9489
},
@@ -97,6 +92,7 @@ func init() {
9792
},
9893
{
9994
name: "size-classes",
95+
tags: []string{"gc"},
10096
metrics: []string{
10197
"/gc/heap/allocs-by-size:bytes",
10298
"/gc/heap/frees-by-size:bytes",
@@ -106,6 +102,7 @@ func init() {
106102
},
107103
{
108104
name: "gc-pauses",
105+
tags: []string{"scheduler"},
109106
metrics: []string{
110107
"/gc/pauses:seconds",
111108
},
@@ -114,6 +111,7 @@ func init() {
114111
},
115112
{
116113
name: "runnable-time",
114+
tags: []string{"scheduler"},
117115
metrics: []string{
118116
"/sched/latencies:seconds",
119117
},
@@ -122,6 +120,7 @@ func init() {
122120
},
123121
{
124122
name: "sched-events",
123+
tags: []string{"scheduler"},
125124
metrics: []string{
126125
"/sched/latencies:seconds",
127126
"/sched/gomaxprocs:threads",
@@ -131,6 +130,7 @@ func init() {
131130
},
132131
{
133132
name: "cgo",
133+
tags: []string{"misc"},
134134
metrics: []string{
135135
"/cgo/go-to-c-calls:calls",
136136
},
@@ -139,6 +139,7 @@ func init() {
139139
},
140140
{
141141
name: "gc-stack-size",
142+
tags: []string{"gc"},
142143
metrics: []string{
143144
"/gc/stack/starting-size:bytes",
144145
},
@@ -147,6 +148,7 @@ func init() {
147148
},
148149
{
149150
name: "gc-cycles",
151+
tags: []string{"gc"},
150152
metrics: []string{
151153
"/gc/cycles/automatic:gc-cycles",
152154
"/gc/cycles/forced:gc-cycles",
@@ -157,6 +159,7 @@ func init() {
157159
},
158160
{
159161
name: "memory-classes",
162+
tags: []string{"gc"},
160163
metrics: []string{
161164
"/memory/classes/os-stacks:bytes",
162165
"/memory/classes/other:bytes",
@@ -168,6 +171,7 @@ func init() {
168171
},
169172
{
170173
name: "cpu-classes-gc",
174+
tags: []string{"gc"},
171175
metrics: []string{
172176
"/cpu/classes/gc/mark/assist:cpu-seconds",
173177
"/cpu/classes/gc/mark/dedicated:cpu-seconds",
@@ -180,14 +184,16 @@ func init() {
180184
},
181185
{
182186
name: "mutex-wait",
187+
tags: []string{"misc"},
183188
metrics: []string{
184-
"/cpu/classes/gc/mark/assist:cpu-seconds",
189+
"/sync/mutex/wait/total:seconds",
185190
},
186191
layout: mutexWaitLayout,
187192
make: makeMutexWait,
188193
},
189194
{
190195
name: "gc-scan",
196+
tags: []string{"gc"},
191197
metrics: []string{
192198
"/gc/scan/globals:bytes",
193199
"/gc/scan/heap:bytes",
@@ -199,38 +205,6 @@ func init() {
199205
}
200206
}
201207

202-
// heap (global)
203-
204-
type heapGlobal struct {
205-
idxobj int
206-
idxunused int
207-
idxfree int
208-
idxreleased int
209-
}
210-
211-
func makeHeapGlobal(indices ...int) metricsGetter {
212-
return &heapGlobal{
213-
idxobj: indices[0],
214-
idxunused: indices[1],
215-
idxfree: indices[2],
216-
idxreleased: indices[3],
217-
}
218-
}
219-
220-
func (p *heapGlobal) values(samples []metrics.Sample) any {
221-
heapObjects := samples[p.idxobj].Value.Uint64()
222-
heapUnused := samples[p.idxunused].Value.Uint64()
223-
224-
heapInUse := heapObjects + heapUnused
225-
heapFree := samples[p.idxfree].Value.Uint64()
226-
heapReleased := samples[p.idxreleased].Value.Uint64()
227-
return []uint64{
228-
heapInUse,
229-
heapFree,
230-
heapReleased,
231-
}
232-
}
233-
234208
// heap (details)
235209

236210
type heapDetails struct {

internal/plot/registry.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,24 @@ func (pl *List) enabledPlots() []runtimePlot {
8181
plots = append(plots, runtimePlot{
8282
name: plot.name,
8383
rt: plot.make(indices...),
84-
layout: assignName(plot.layout, plot.name),
84+
layout: complete(plot.layout, plot.name, plot.tags),
8585
})
8686
}
8787
}
8888

8989
return plots
9090
}
9191

92-
func assignName(layout any, name string) any {
92+
// complete the layout with names and tags.
93+
func complete(layout any, name string, tags []string) any {
9394
switch layout := layout.(type) {
9495
case Scatter:
9596
layout.Name = name
97+
layout.Tags = tags
9698
return layout
9799
case Heatmap:
98100
layout.Name = name
101+
layout.Tags = tags
99102
return layout
100103
default:
101104
panic(fmt.Sprintf("unknown plot layout type %T", layout))

0 commit comments

Comments
 (0)