Skip to content

Commit 0aba6cd

Browse files
committed
internal/plot: rewrite in a more declarative way (WIP)
1 parent eae81d3 commit 0aba6cd

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

internal/plot/layouts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ var memoryClassesLayout = Scatter{
397397
<i>Profiling buckets</i> is <b>/memory/classes/profiling/buckets</b>, memory that is used by the stack trace hash map used for profiling.
398398
<i>Total</i> is <b>/memory/classes/total</b>, all memory mapped by the Go runtime into the current process as read-write.`,
399399
}
400+
400401
var cpuClassesLayout = Scatter{
401402
Name: "TODO",
402403
Title: "CPU classes (GC)",

internal/plot/plots.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func init() {
5656
"/gc/heap/goal:bytes",
5757
},
5858
layout: heapDetailslLayout,
59-
make: makeHeapGlobal,
59+
make: makeHeapDetails,
6060
},
6161
{
6262
name: "live-objects",
@@ -412,6 +412,11 @@ func makeGCPauses(indices ...int) runtimeMetric {
412412
}
413413

414414
func (p *gcpauses) values(samples []metrics.Sample) any {
415+
if p.histfactor == 0 {
416+
gcpauses := samples[p.idxgcpauses].Value.Float64Histogram()
417+
p.histfactor = downsampleFactor(len(gcpauses.Buckets), maxBuckets)
418+
}
419+
415420
gcpauses := samples[p.idxgcpauses].Value.Float64Histogram()
416421
return downsampleCounts(gcpauses, p.histfactor, p.counts[:])
417422
}
@@ -432,6 +437,11 @@ func makeRunnableTime(indices ...int) runtimeMetric {
432437
}
433438

434439
func (p *runnableTime) values(samples []metrics.Sample) any {
440+
if p.histfactor == 0 {
441+
schedlat := samples[p.idxschedlat].Value.Float64Histogram()
442+
p.histfactor = downsampleFactor(len(schedlat.Buckets), maxBuckets)
443+
}
444+
435445
schedlat := samples[p.idxschedlat].Value.Float64Histogram()
436446

437447
return downsampleCounts(schedlat, p.histfactor, p.counts[:])

internal/plot/registry.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,33 @@ func enabledPlots() []rtplot {
7777
if plot.make == nil {
7878
continue
7979
}
80+
8081
indices, enabled := indicesFor(plot.metrics...)
8182
if enabled {
8283
plots = append(plots, rtplot{
8384
name: plot.name,
8485
rt: plot.make(indices...),
85-
layout: plot.layout,
86+
layout: assignName(plot.layout, plot.name),
8687
})
8788
}
8889
}
8990

9091
return plots
9192
}
9293

94+
func assignName(layout any, name string) any {
95+
switch layout := layout.(type) {
96+
case Scatter:
97+
layout.Name = name
98+
return layout
99+
case Heatmap:
100+
layout.Name = name
101+
return layout
102+
default:
103+
panic(fmt.Sprintf("unknown plot layout type %T", layout))
104+
}
105+
}
106+
93107
func (pl *List) Config() *Config {
94108
pl.once.Do(func() {
95109
pl.rtPlots = enabledPlots()
@@ -168,8 +182,8 @@ func (pl *List) WriteValues(w io.Writer) error {
168182
return nil
169183
}
170184

171-
// mapMetricsToIndices retrieves indices for the specified metrics, returning
172-
// both the indices and whether all metrics were found.
185+
// indicesFor retrieves indices for the specified metrics, and a boolean
186+
// indicating whether they were all found.
173187
func indicesFor(metricNames ...string) ([]int, bool) {
174188
indices := make([]int, len(metricNames))
175189
allFound := true

0 commit comments

Comments
 (0)