benchforge 0.1.11 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +99 -294
- package/bin/benchforge +1 -2
- package/dist/AnalyzeArchive-8NCJhmhS.mjs +145 -0
- package/dist/AnalyzeArchive-8NCJhmhS.mjs.map +1 -0
- package/dist/BenchMatrix-BZVrBB_h.mjs +1050 -0
- package/dist/BenchMatrix-BZVrBB_h.mjs.map +1 -0
- package/dist/{BenchRunner-BzyUfiyB.d.mts → BenchRunner-DglX1NOn.d.mts} +119 -66
- package/dist/CoverageSampler-D5T9DRqe.mjs +27 -0
- package/dist/CoverageSampler-D5T9DRqe.mjs.map +1 -0
- package/dist/Formatters-BWj3d4sv.mjs +95 -0
- package/dist/Formatters-BWj3d4sv.mjs.map +1 -0
- package/dist/{HeapSampler-B8dtKHn1.mjs → HeapSampler-Dq-hpXem.mjs} +4 -4
- package/dist/HeapSampler-Dq-hpXem.mjs.map +1 -0
- package/dist/RunBenchCLI-C17DrJz8.mjs +3075 -0
- package/dist/RunBenchCLI-C17DrJz8.mjs.map +1 -0
- package/dist/StatisticalUtils-BD92crgM.mjs +255 -0
- package/dist/StatisticalUtils-BD92crgM.mjs.map +1 -0
- package/dist/TimeSampler-Ds8n7l2B.mjs +29 -0
- package/dist/TimeSampler-Ds8n7l2B.mjs.map +1 -0
- package/dist/ViewerServer-BJhdnxlN.mjs +639 -0
- package/dist/ViewerServer-BJhdnxlN.mjs.map +1 -0
- package/dist/ViewerServer-CuMNdNBz.mjs +2 -0
- package/dist/bin/benchforge.mjs +4 -5
- package/dist/bin/benchforge.mjs.map +1 -1
- package/dist/index.d.mts +711 -558
- package/dist/index.mjs +98 -3
- package/dist/index.mjs.map +1 -0
- package/dist/runners/WorkerScript.d.mts +12 -4
- package/dist/runners/WorkerScript.mjs +77 -105
- package/dist/runners/WorkerScript.mjs.map +1 -1
- package/dist/viewer/assets/CIPlot-BkOvMoMa.js +1 -0
- package/dist/viewer/assets/HistogramKde-CmSyUFY0.js +1 -0
- package/dist/viewer/assets/LegendUtils-BJpbn_jr.js +55 -0
- package/dist/viewer/assets/SampleTimeSeries-C4VBhXr3.js +1 -0
- package/dist/viewer/assets/index-Br9bp_cX.js +153 -0
- package/dist/viewer/assets/index-NzXXe_CC.css +1 -0
- package/dist/viewer/index.html +19 -0
- package/dist/viewer/speedscope/LICENSE +21 -0
- package/dist/viewer/speedscope/SourceCodePro-Regular.ttf-ILST5JV6.woff2 +0 -0
- package/dist/viewer/speedscope/favicon-16x16-V2DMIAZS.js +2 -0
- package/dist/viewer/speedscope/favicon-16x16-V2DMIAZS.js.map +7 -0
- package/dist/viewer/speedscope/favicon-16x16-VSI62OPJ.png +0 -0
- package/dist/viewer/speedscope/favicon-32x32-3EB2YCUY.png +0 -0
- package/dist/viewer/speedscope/favicon-32x32-THY3JDJL.js +2 -0
- package/dist/viewer/speedscope/favicon-32x32-THY3JDJL.js.map +7 -0
- package/dist/viewer/speedscope/favicon-FOKUP5Y5.ico +0 -0
- package/dist/viewer/speedscope/favicon-M34RF7BI.js +2 -0
- package/dist/viewer/speedscope/favicon-M34RF7BI.js.map +7 -0
- package/dist/viewer/speedscope/file-format-schema.json +274 -0
- package/dist/viewer/speedscope/index.html +19 -0
- package/dist/viewer/speedscope/jfrview_bg-BLJXNNQB.wasm +0 -0
- package/dist/viewer/speedscope/perf-vertx-stacks-01-collapsed-all-ZNUIGAJL.txt +199 -0
- package/dist/viewer/speedscope/release.txt +3 -0
- package/dist/viewer/speedscope/source-code-pro.LICENSE.md +93 -0
- package/dist/viewer/speedscope/speedscope-GHPHNKXC.css +2 -0
- package/dist/viewer/speedscope/speedscope-GHPHNKXC.css.map +7 -0
- package/dist/viewer/speedscope/speedscope-QZFMJ7VP.js +212 -0
- package/dist/viewer/speedscope/speedscope-QZFMJ7VP.js.map +7 -0
- package/package.json +52 -27
- package/src/bin/benchforge.ts +2 -2
- package/src/cli/AnalyzeArchive.ts +232 -0
- package/src/cli/BrowserBench.ts +322 -0
- package/src/cli/CliArgs.ts +164 -51
- package/src/cli/CliExport.ts +179 -0
- package/src/cli/CliOptions.ts +147 -0
- package/src/cli/CliReport.ts +197 -0
- package/src/cli/FilterBenchmarks.ts +18 -30
- package/src/cli/RunBenchCLI.ts +132 -866
- package/src/cli/SuiteRunner.ts +160 -0
- package/src/cli/ViewerServer.ts +282 -0
- package/src/export/AllocExport.ts +121 -0
- package/src/export/ArchiveExport.ts +146 -0
- package/src/export/ArchiveFormat.ts +50 -0
- package/src/export/CoverageExport.ts +148 -0
- package/src/export/EditorUri.ts +10 -0
- package/src/export/PerfettoExport.ts +64 -99
- package/src/export/SpeedscopeTypes.ts +98 -0
- package/src/export/TimeExport.ts +115 -0
- package/src/index.ts +86 -67
- package/src/matrix/BenchMatrix.ts +230 -0
- package/src/matrix/CaseLoader.ts +8 -6
- package/src/matrix/MatrixDirRunner.ts +153 -0
- package/src/matrix/MatrixFilter.ts +49 -47
- package/src/matrix/MatrixInlineRunner.ts +50 -0
- package/src/matrix/MatrixReport.ts +90 -250
- package/src/matrix/VariantLoader.ts +5 -5
- package/src/profiling/browser/BenchLoop.ts +51 -0
- package/src/profiling/browser/BrowserCDP.ts +133 -0
- package/src/profiling/browser/BrowserGcStats.ts +33 -0
- package/src/profiling/browser/BrowserProfiler.ts +160 -0
- package/src/profiling/browser/CdpClient.ts +82 -0
- package/src/profiling/browser/CdpPage.ts +138 -0
- package/src/profiling/browser/ChromeLauncher.ts +158 -0
- package/src/profiling/browser/ChromeTraceEvent.ts +28 -0
- package/src/profiling/browser/PageLoadMode.ts +61 -0
- package/src/profiling/node/CoverageSampler.ts +27 -0
- package/src/profiling/node/CoverageTypes.ts +23 -0
- package/src/profiling/node/HeapSampleReport.ts +261 -0
- package/src/{heap-sample → profiling/node}/HeapSampler.ts +1 -2
- package/src/{heap-sample → profiling/node}/ResolvedProfile.ts +18 -9
- package/src/profiling/node/TimeSampler.ts +57 -0
- package/src/report/BenchmarkReport.ts +146 -0
- package/src/report/Colors.ts +9 -0
- package/src/report/Formatters.ts +110 -0
- package/src/report/GcSections.ts +151 -0
- package/src/{GitUtils.ts → report/GitUtils.ts} +18 -19
- package/src/report/HtmlReport.ts +223 -0
- package/src/report/ParseStats.ts +73 -0
- package/src/report/StandardSections.ts +147 -0
- package/src/report/ViewerSections.ts +286 -0
- package/src/report/text/TableReport.ts +253 -0
- package/src/report/text/TextReport.ts +123 -0
- package/src/runners/AdaptiveWrapper.ts +116 -236
- package/src/runners/BenchRunner.ts +20 -15
- package/src/{Benchmark.ts → runners/BenchmarkSpec.ts} +5 -6
- package/src/runners/CreateRunner.ts +5 -7
- package/src/runners/GcStats.ts +47 -50
- package/src/{MeasuredResults.ts → runners/MeasuredResults.ts} +43 -37
- package/src/runners/MergeBatches.ts +123 -0
- package/src/{NodeGC.ts → runners/NodeGC.ts} +2 -3
- package/src/runners/RunnerOrchestrator.ts +127 -243
- package/src/runners/RunnerUtils.ts +75 -1
- package/src/runners/SampleStats.ts +100 -0
- package/src/runners/TimingRunner.ts +244 -0
- package/src/runners/TimingUtils.ts +3 -2
- package/src/runners/WorkerScript.ts +135 -151
- package/src/stats/BootstrapDifference.ts +282 -0
- package/src/{PermutationTest.ts → stats/PermutationTest.ts} +8 -17
- package/src/stats/StatisticalUtils.ts +445 -0
- package/src/{tests → test}/AdaptiveConvergence.test.ts +10 -10
- package/src/test/AdaptiveRunner.test.ts +39 -41
- package/src/{tests → test}/AdaptiveSampling.test.ts +9 -9
- package/src/test/AdaptiveStatistics.integration.ts +2 -2
- package/src/{tests → test}/BenchMatrix.test.ts +19 -16
- package/src/test/BenchmarkReport.test.ts +63 -13
- package/src/test/BrowserBench.e2e.test.ts +186 -17
- package/src/test/BrowserBench.test.ts +10 -5
- package/src/test/BuildTimeSection.test.ts +130 -0
- package/src/test/CapSamples.test.ts +82 -0
- package/src/test/CoverageExport.test.ts +115 -0
- package/src/test/CoverageSampler.test.ts +33 -0
- package/src/test/HeapAttribution.test.ts +14 -14
- package/src/{tests → test}/MatrixFilter.test.ts +1 -1
- package/src/{tests → test}/MatrixReport.test.ts +1 -1
- package/src/test/PermutationTest.test.ts +1 -1
- package/src/{tests → test}/RealDataValidation.test.ts +6 -6
- package/src/test/RunBenchCLI.test.ts +39 -38
- package/src/test/RunnerOrchestrator.test.ts +12 -12
- package/src/test/StatisticalUtils.test.ts +48 -12
- package/src/{table-util/test → test}/TableReport.test.ts +2 -2
- package/src/test/TestUtils.ts +12 -7
- package/src/test/TimeExport.test.ts +139 -0
- package/src/test/TimeSampler.test.ts +37 -0
- package/src/test/ViewerLive.e2e.test.ts +159 -0
- package/src/test/ViewerStatic.static.e2e.test.ts +137 -0
- package/src/{tests → test}/fixtures/baseline/impl.ts +1 -1
- package/src/{tests → test}/fixtures/bevy30-samples.ts +3 -1
- package/src/test/fixtures/cases/asyncCases.ts +9 -0
- package/src/{tests → test}/fixtures/cases/cases.ts +5 -2
- package/src/test/fixtures/cases/variants/product.ts +2 -0
- package/src/test/fixtures/cases/variants/sum.ts +2 -0
- package/src/test/fixtures/discover/fast.ts +1 -0
- package/src/{tests → test}/fixtures/discover/slow.ts +1 -1
- package/src/test/fixtures/invalid/bad.ts +1 -0
- package/src/test/fixtures/loader/fast.ts +1 -0
- package/src/{tests → test}/fixtures/loader/slow.ts +1 -1
- package/src/test/fixtures/loader/stateful.ts +2 -0
- package/src/test/fixtures/stateful/stateful.ts +2 -0
- package/src/test/fixtures/variants/extra.ts +1 -0
- package/src/test/fixtures/variants/impl.ts +1 -0
- package/src/test/fixtures/worker/fast.ts +1 -0
- package/src/{tests → test}/fixtures/worker/slow.ts +1 -1
- package/src/viewer/DateFormat.ts +30 -0
- package/src/viewer/Helpers.ts +23 -0
- package/src/viewer/LineData.ts +120 -0
- package/src/viewer/Providers.ts +191 -0
- package/src/viewer/ReportData.ts +123 -0
- package/src/viewer/State.ts +49 -0
- package/src/viewer/Theme.ts +15 -0
- package/src/viewer/components/App.tsx +73 -0
- package/src/viewer/components/DropZone.tsx +71 -0
- package/src/viewer/components/LazyPlot.ts +33 -0
- package/src/viewer/components/SamplesPanel.tsx +214 -0
- package/src/viewer/components/Shell.tsx +26 -0
- package/src/viewer/components/SourcePanel.tsx +216 -0
- package/src/viewer/components/SummaryPanel.tsx +332 -0
- package/src/viewer/components/TabBar.tsx +131 -0
- package/src/viewer/components/TabContent.tsx +46 -0
- package/src/viewer/components/ThemeToggle.tsx +50 -0
- package/src/viewer/index.html +20 -0
- package/src/viewer/main.tsx +4 -0
- package/src/viewer/plots/CIPlot.ts +313 -0
- package/src/{html/browser → viewer/plots}/HistogramKde.ts +33 -38
- package/src/viewer/plots/LegendUtils.ts +134 -0
- package/src/viewer/plots/PlotTypes.ts +85 -0
- package/src/viewer/plots/RenderPlots.ts +230 -0
- package/src/viewer/plots/SampleTimeSeries.ts +306 -0
- package/src/viewer/plots/SvgHelpers.ts +136 -0
- package/src/viewer/plots/TimeSeriesMarks.ts +319 -0
- package/src/viewer/report.css +427 -0
- package/src/viewer/shell.css +357 -0
- package/src/viewer/tsconfig.json +11 -0
- package/dist/BrowserHeapSampler-B6asLKWQ.mjs +0 -202
- package/dist/BrowserHeapSampler-B6asLKWQ.mjs.map +0 -1
- package/dist/GcStats-wX7Xyblu.mjs +0 -77
- package/dist/GcStats-wX7Xyblu.mjs.map +0 -1
- package/dist/HeapSampler-B8dtKHn1.mjs.map +0 -1
- package/dist/TimingUtils-DwOwkc8G.mjs +0 -597
- package/dist/TimingUtils-DwOwkc8G.mjs.map +0 -1
- package/dist/browser/index.js +0 -914
- package/dist/src-B-DDaCa9.mjs +0 -3108
- package/dist/src-B-DDaCa9.mjs.map +0 -1
- package/src/BenchMatrix.ts +0 -380
- package/src/BenchmarkReport.ts +0 -161
- package/src/HtmlDataPrep.ts +0 -148
- package/src/StandardSections.ts +0 -261
- package/src/StatisticalUtils.ts +0 -175
- package/src/TypeUtil.ts +0 -8
- package/src/browser/BrowserGcStats.ts +0 -44
- package/src/browser/BrowserHeapSampler.ts +0 -271
- package/src/export/JsonExport.ts +0 -103
- package/src/export/JsonFormat.ts +0 -91
- package/src/export/SpeedscopeExport.ts +0 -202
- package/src/heap-sample/HeapSampleReport.ts +0 -269
- package/src/html/HtmlReport.ts +0 -131
- package/src/html/HtmlTemplate.ts +0 -284
- package/src/html/Types.ts +0 -88
- package/src/html/browser/CIPlot.ts +0 -287
- package/src/html/browser/LegendUtils.ts +0 -163
- package/src/html/browser/RenderPlots.ts +0 -263
- package/src/html/browser/SampleTimeSeries.ts +0 -389
- package/src/html/browser/Types.ts +0 -96
- package/src/html/browser/index.ts +0 -1
- package/src/html/index.ts +0 -17
- package/src/runners/BasicRunner.ts +0 -364
- package/src/table-util/ConvergenceFormatters.ts +0 -19
- package/src/table-util/Formatters.ts +0 -157
- package/src/table-util/README.md +0 -70
- package/src/table-util/TableReport.ts +0 -293
- package/src/tests/fixtures/cases/asyncCases.ts +0 -7
- package/src/tests/fixtures/cases/variants/product.ts +0 -2
- package/src/tests/fixtures/cases/variants/sum.ts +0 -2
- package/src/tests/fixtures/discover/fast.ts +0 -1
- package/src/tests/fixtures/invalid/bad.ts +0 -1
- package/src/tests/fixtures/loader/fast.ts +0 -1
- package/src/tests/fixtures/loader/stateful.ts +0 -2
- package/src/tests/fixtures/stateful/stateful.ts +0 -2
- package/src/tests/fixtures/variants/extra.ts +0 -1
- package/src/tests/fixtures/variants/impl.ts +0 -1
- package/src/tests/fixtures/worker/fast.ts +0 -1
- /package/src/{table-util/test → test}/TableValueExtractor.test.ts +0 -0
- /package/src/{table-util/test → test}/TableValueExtractor.ts +0 -0
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import * as Plot from "@observablehq/plot";
|
|
2
|
+
import * as d3 from "d3";
|
|
3
|
+
import { optStatusNames } from "../../runners/MeasuredResults.ts";
|
|
4
|
+
import { buildLegend, type LegendItem } from "./LegendUtils.ts";
|
|
5
|
+
import {
|
|
6
|
+
type FlatGcEvent,
|
|
7
|
+
type FlatPausePoint,
|
|
8
|
+
getTimeUnit,
|
|
9
|
+
type HeapPoint,
|
|
10
|
+
plotLayout,
|
|
11
|
+
type TimeSeriesPoint,
|
|
12
|
+
} from "./PlotTypes.ts";
|
|
13
|
+
import {
|
|
14
|
+
buildLegendItems,
|
|
15
|
+
gcMark,
|
|
16
|
+
type HeapScale,
|
|
17
|
+
heapAxisMarks,
|
|
18
|
+
heapMarks,
|
|
19
|
+
type PlotContext,
|
|
20
|
+
pauseMarks,
|
|
21
|
+
type SampleData,
|
|
22
|
+
sampleDotMarks,
|
|
23
|
+
} from "./TimeSeriesMarks.ts";
|
|
24
|
+
|
|
25
|
+
/** Controls which data series are visible in the time series plot */
|
|
26
|
+
export interface SeriesVisibility {
|
|
27
|
+
baseline: boolean;
|
|
28
|
+
heap: boolean;
|
|
29
|
+
baselineHeap: boolean;
|
|
30
|
+
rejected: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type HeapPlotPoint = { sample: number; y: number };
|
|
34
|
+
|
|
35
|
+
interface MarkParams {
|
|
36
|
+
ctx: PlotContext;
|
|
37
|
+
heapData: HeapPlotPoint[];
|
|
38
|
+
baselineHeapData: HeapPlotPoint[];
|
|
39
|
+
heapScale: HeapScale | undefined;
|
|
40
|
+
gcEvents: FlatGcEvent[];
|
|
41
|
+
pausePoints: FlatPausePoint[];
|
|
42
|
+
legendItems: LegendItem[];
|
|
43
|
+
showRejected: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const defaultVisibility: SeriesVisibility = {
|
|
47
|
+
baseline: true,
|
|
48
|
+
heap: true,
|
|
49
|
+
baselineHeap: false,
|
|
50
|
+
rejected: true,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** Time series plot with samples, GC events, heap overlay, and opt tiers */
|
|
54
|
+
export function createSampleTimeSeries(
|
|
55
|
+
timeSeries: TimeSeriesPoint[],
|
|
56
|
+
gcEvents: FlatGcEvent[] = [],
|
|
57
|
+
pausePoints: FlatPausePoint[] = [],
|
|
58
|
+
heapSeries: HeapPoint[] = [],
|
|
59
|
+
baselineHeapSeries: HeapPoint[] = [],
|
|
60
|
+
visibility: SeriesVisibility = defaultVisibility,
|
|
61
|
+
): SVGSVGElement | HTMLElement {
|
|
62
|
+
const filtered = visibility.baseline
|
|
63
|
+
? timeSeries
|
|
64
|
+
: timeSeries.filter(d => !d.isBaseline);
|
|
65
|
+
const ctx = buildPlotContext(filtered);
|
|
66
|
+
const series = prepareSeriesData(
|
|
67
|
+
ctx,
|
|
68
|
+
heapSeries,
|
|
69
|
+
baselineHeapSeries,
|
|
70
|
+
visibility,
|
|
71
|
+
gcEvents,
|
|
72
|
+
pausePoints,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
return Plot.plot({
|
|
76
|
+
...plotLayout,
|
|
77
|
+
x: {
|
|
78
|
+
label: "Iteration",
|
|
79
|
+
labelAnchor: "center",
|
|
80
|
+
labelOffset: 45,
|
|
81
|
+
grid: true,
|
|
82
|
+
domain: [ctx.xMin, ctx.xMax],
|
|
83
|
+
},
|
|
84
|
+
y: {
|
|
85
|
+
label: `Time (${ctx.unitSuffix})`,
|
|
86
|
+
labelAnchor: "top",
|
|
87
|
+
labelArrow: false,
|
|
88
|
+
grid: true,
|
|
89
|
+
domain: [ctx.yMin, ctx.yMax],
|
|
90
|
+
tickFormat: ctx.formatValue,
|
|
91
|
+
},
|
|
92
|
+
color: { legend: false, scheme: "observable10" },
|
|
93
|
+
marks: buildMarks({ ctx, ...series, gcEvents, pausePoints }),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Derive scales, units, and metadata from time series data */
|
|
98
|
+
function buildPlotContext(timeSeries: TimeSeriesPoint[]): PlotContext {
|
|
99
|
+
const benchmarks = [...new Set(timeSeries.map(d => d.benchmark))];
|
|
100
|
+
const sampleData = buildSampleData(timeSeries);
|
|
101
|
+
const values = sampleData.map(d => d.value);
|
|
102
|
+
const { unitSuffix, convertValue, formatValue } = getTimeUnit(values);
|
|
103
|
+
const convertedData: SampleData[] = sampleData.map(d => ({
|
|
104
|
+
...d,
|
|
105
|
+
displayValue: convertValue(d.value),
|
|
106
|
+
}));
|
|
107
|
+
const { yMin, yMax } = computeYRange(convertedData.map(d => d.displayValue));
|
|
108
|
+
let xMin = d3.min(convertedData, d => d.sample)!;
|
|
109
|
+
let xMax = d3.max(convertedData, d => d.sample)!;
|
|
110
|
+
if (xMin === xMax) {
|
|
111
|
+
xMin -= 0.5;
|
|
112
|
+
xMax += 0.5;
|
|
113
|
+
}
|
|
114
|
+
const hasWarmup = convertedData.some(d => d.isWarmup);
|
|
115
|
+
const hasRejected = convertedData.some(d => d.isRejected);
|
|
116
|
+
const baselineNames = new Set(
|
|
117
|
+
convertedData.filter(d => d.isBaseline).map(d => d.benchmark),
|
|
118
|
+
);
|
|
119
|
+
const optTiers = [
|
|
120
|
+
...new Set(
|
|
121
|
+
convertedData.filter(d => d.optTier && !d.isWarmup).map(d => d.optTier!),
|
|
122
|
+
),
|
|
123
|
+
];
|
|
124
|
+
return {
|
|
125
|
+
convertedData,
|
|
126
|
+
xMin,
|
|
127
|
+
xMax,
|
|
128
|
+
yMin,
|
|
129
|
+
yMax,
|
|
130
|
+
unitSuffix,
|
|
131
|
+
formatValue,
|
|
132
|
+
convertValue,
|
|
133
|
+
hasWarmup,
|
|
134
|
+
hasRejected,
|
|
135
|
+
baselineNames,
|
|
136
|
+
optTiers,
|
|
137
|
+
benchmarks,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Prepare heap, legend, and visibility state for the time series plot */
|
|
142
|
+
function prepareSeriesData(
|
|
143
|
+
ctx: PlotContext,
|
|
144
|
+
heapSeries: HeapPoint[],
|
|
145
|
+
baselineHeapSeries: HeapPoint[],
|
|
146
|
+
visibility: SeriesVisibility,
|
|
147
|
+
gcEvents: FlatGcEvent[],
|
|
148
|
+
pausePoints: FlatPausePoint[],
|
|
149
|
+
) {
|
|
150
|
+
const visibleHeap = [
|
|
151
|
+
...(visibility.heap ? heapSeries : []),
|
|
152
|
+
...(visibility.baselineHeap ? baselineHeapSeries : []),
|
|
153
|
+
];
|
|
154
|
+
const heapScale = computeHeapScale(visibleHeap, ctx.yMin, ctx.yMax);
|
|
155
|
+
const heapData =
|
|
156
|
+
heapScale && visibility.heap ? prepareHeapData(heapSeries, heapScale) : [];
|
|
157
|
+
const baselineHeapData =
|
|
158
|
+
heapScale && visibility.baselineHeap
|
|
159
|
+
? prepareHeapData(baselineHeapSeries, heapScale)
|
|
160
|
+
: [];
|
|
161
|
+
const showRejected = visibility.rejected && ctx.hasRejected;
|
|
162
|
+
const legendItems = buildLegendItems({
|
|
163
|
+
hasWarmup: ctx.hasWarmup,
|
|
164
|
+
gcCount: gcEvents.length,
|
|
165
|
+
pauseCount: pausePoints.length,
|
|
166
|
+
hasHeap: heapData.length > 0,
|
|
167
|
+
hasBaselineHeap: baselineHeapData.length > 0,
|
|
168
|
+
hasRejected: showRejected,
|
|
169
|
+
optTiers: ctx.optTiers,
|
|
170
|
+
benchmarks: ctx.benchmarks,
|
|
171
|
+
baselineNames: ctx.baselineNames,
|
|
172
|
+
});
|
|
173
|
+
return { heapScale, heapData, baselineHeapData, showRejected, legendItems };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Assemble all Observable Plot marks for the time series chart */
|
|
177
|
+
function buildMarks(p: MarkParams): Plot.Markish[] {
|
|
178
|
+
const { ctx, heapData, baselineHeapData, heapScale } = p;
|
|
179
|
+
const { gcEvents, pausePoints, legendItems, showRejected } = p;
|
|
180
|
+
const dashStyle = { stroke: "#999", strokeWidth: 1, strokeDasharray: "4,4" };
|
|
181
|
+
const warmupRule = ctx.hasWarmup ? [Plot.ruleX([0], dashStyle)] : [];
|
|
182
|
+
const { xMin, xMax, yMin, yMax } = ctx;
|
|
183
|
+
return [
|
|
184
|
+
...heapMarks(baselineHeapData, yMin, "#fcd34d"),
|
|
185
|
+
...heapMarks(heapData, yMin, "#93c5fd"),
|
|
186
|
+
...heapAxisMarks(heapScale, xMax, xMin),
|
|
187
|
+
...warmupRule,
|
|
188
|
+
gcMark(gcEvents, yMin, ctx.convertValue),
|
|
189
|
+
...pauseMarks(pausePoints, yMin, yMax),
|
|
190
|
+
...sampleDotMarks(ctx, showRejected, lttb),
|
|
191
|
+
Plot.ruleY([yMin], { stroke: "black", strokeWidth: 1 }),
|
|
192
|
+
...buildLegend({ xMin, xMax, yMin, yMax }, legendItems),
|
|
193
|
+
];
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** Convert TimeSeriesPoint data to SampleData with opt tier names */
|
|
197
|
+
function buildSampleData(
|
|
198
|
+
timeSeries: TimeSeriesPoint[],
|
|
199
|
+
): Omit<SampleData, "displayValue">[] {
|
|
200
|
+
return timeSeries.map(d => ({
|
|
201
|
+
benchmark: d.benchmark,
|
|
202
|
+
sample: d.iteration,
|
|
203
|
+
value: d.value,
|
|
204
|
+
isBaseline: d.isBaseline || false,
|
|
205
|
+
isWarmup: d.isWarmup || false,
|
|
206
|
+
isRejected: d.isRejected || false,
|
|
207
|
+
optTier:
|
|
208
|
+
d.optStatus !== undefined
|
|
209
|
+
? optStatusNames[d.optStatus] || "unknown"
|
|
210
|
+
: null,
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Pad Y range and snap yMin to a round number for clean axis ticks */
|
|
215
|
+
function computeYRange(values: number[]) {
|
|
216
|
+
const dataMin = d3.min(values)!;
|
|
217
|
+
const dataMax = d3.max(values)!;
|
|
218
|
+
const range = dataMax - dataMin;
|
|
219
|
+
let yMin = dataMin - range * 0.15;
|
|
220
|
+
const mag = 10 ** Math.floor(Math.log10(Math.abs(yMin)));
|
|
221
|
+
yMin = Math.floor(yMin / mag) * mag;
|
|
222
|
+
if (dataMin > 0 && yMin < 0) yMin = 0;
|
|
223
|
+
return { yMin, yMax: dataMax + range * 0.05 };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Compute scale to map heap byte values into the bottom 25% of the Y axis */
|
|
227
|
+
function computeHeapScale(
|
|
228
|
+
allHeap: HeapPoint[],
|
|
229
|
+
yMin: number,
|
|
230
|
+
yMax: number,
|
|
231
|
+
): HeapScale | undefined {
|
|
232
|
+
if (allHeap.length === 0) return undefined;
|
|
233
|
+
const heapMinBytes = d3.min(allHeap, d => d.value)!;
|
|
234
|
+
const heapRangeBytes = d3.max(allHeap, d => d.value)! - heapMinBytes || 1;
|
|
235
|
+
return {
|
|
236
|
+
heapMinBytes,
|
|
237
|
+
heapRangeBytes,
|
|
238
|
+
scale: ((yMax - yMin) * 0.25) / heapRangeBytes,
|
|
239
|
+
yMin,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Map heap byte values to the time-series Y scale and downsample via LTTB */
|
|
244
|
+
function prepareHeapData(
|
|
245
|
+
heapSeries: HeapPoint[],
|
|
246
|
+
hs: HeapScale,
|
|
247
|
+
): HeapPlotPoint[] {
|
|
248
|
+
if (heapSeries.length === 0) return [];
|
|
249
|
+
const mapped = heapSeries.map(d => ({
|
|
250
|
+
sample: d.iteration,
|
|
251
|
+
y: hs.yMin + (d.value - hs.heapMinBytes) * hs.scale,
|
|
252
|
+
}));
|
|
253
|
+
return lttb(
|
|
254
|
+
mapped,
|
|
255
|
+
500,
|
|
256
|
+
d => d.sample,
|
|
257
|
+
d => d.y,
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** LTTB downsampling: select n points that best preserve visual shape */
|
|
262
|
+
function lttb<T>(
|
|
263
|
+
data: T[],
|
|
264
|
+
n: number,
|
|
265
|
+
getX: (d: T) => number,
|
|
266
|
+
getY: (d: T) => number,
|
|
267
|
+
): T[] {
|
|
268
|
+
if (data.length <= n) return data;
|
|
269
|
+
const bucketSize = (data.length - 2) / (n - 2);
|
|
270
|
+
const result: T[] = [data[0]];
|
|
271
|
+
for (let i = 0; i < n - 2; i++) {
|
|
272
|
+
const bStart = Math.floor(i * bucketSize) + 1;
|
|
273
|
+
const bEnd = Math.floor((i + 1) * bucketSize) + 1;
|
|
274
|
+
const nStart = bEnd;
|
|
275
|
+
const nEnd = Math.min(
|
|
276
|
+
Math.floor((i + 2) * bucketSize) + 1,
|
|
277
|
+
data.length - 1,
|
|
278
|
+
);
|
|
279
|
+
let avgX = 0;
|
|
280
|
+
let avgY = 0;
|
|
281
|
+
for (let j = nStart; j < nEnd; j++) {
|
|
282
|
+
avgX += getX(data[j]);
|
|
283
|
+
avgY += getY(data[j]);
|
|
284
|
+
}
|
|
285
|
+
const cnt = nEnd - nStart || 1;
|
|
286
|
+
avgX /= cnt;
|
|
287
|
+
avgY /= cnt;
|
|
288
|
+
const prev = result[result.length - 1];
|
|
289
|
+
const px = getX(prev);
|
|
290
|
+
const py = getY(prev);
|
|
291
|
+
let maxArea = -1;
|
|
292
|
+
let maxIdx = bStart;
|
|
293
|
+
for (let j = bStart; j < bEnd; j++) {
|
|
294
|
+
const area = Math.abs(
|
|
295
|
+
(px - avgX) * (getY(data[j]) - py) - (px - getX(data[j])) * (avgY - py),
|
|
296
|
+
);
|
|
297
|
+
if (area > maxArea) {
|
|
298
|
+
maxArea = area;
|
|
299
|
+
maxIdx = j;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
result.push(data[maxIdx]);
|
|
303
|
+
}
|
|
304
|
+
result.push(data[data.length - 1]);
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
export const svgNS = "http://www.w3.org/2000/svg";
|
|
2
|
+
|
|
3
|
+
const toKebab = (k: string) => k.replace(/[A-Z]/g, c => "-" + c.toLowerCase());
|
|
4
|
+
const svgEl = (tag: string) => document.createElementNS(svgNS, tag);
|
|
5
|
+
|
|
6
|
+
/** Apply camelCase attributes to an SVG element, converting to kebab-case */
|
|
7
|
+
export function setAttrs(el: SVGElement, attrs: Record<string, string>): void {
|
|
8
|
+
for (const [k, v] of Object.entries(attrs)) el.setAttribute(toKebab(k), v);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Create an SVG root element with viewBox. */
|
|
12
|
+
export function createSvg(w: number, h: number): SVGSVGElement {
|
|
13
|
+
const svg = document.createElementNS(svgNS, "svg");
|
|
14
|
+
svg.setAttribute("width", String(w));
|
|
15
|
+
svg.setAttribute("height", String(h));
|
|
16
|
+
if (w && h) svg.setAttribute("viewBox", `0 0 ${w} ${h}`);
|
|
17
|
+
return svg;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function rect(
|
|
21
|
+
x: number,
|
|
22
|
+
y: number,
|
|
23
|
+
w: number,
|
|
24
|
+
h: number,
|
|
25
|
+
attrs: Record<string, string>,
|
|
26
|
+
): SVGRectElement {
|
|
27
|
+
const el = document.createElementNS(svgNS, "rect");
|
|
28
|
+
el.setAttribute("x", String(x));
|
|
29
|
+
el.setAttribute("y", String(y));
|
|
30
|
+
el.setAttribute("width", String(w));
|
|
31
|
+
el.setAttribute("height", String(h));
|
|
32
|
+
setAttrs(el, attrs);
|
|
33
|
+
return el;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function line(
|
|
37
|
+
x1: number,
|
|
38
|
+
y1: number,
|
|
39
|
+
x2: number,
|
|
40
|
+
y2: number,
|
|
41
|
+
attrs: Record<string, string>,
|
|
42
|
+
): SVGLineElement {
|
|
43
|
+
const el = document.createElementNS(svgNS, "line");
|
|
44
|
+
el.setAttribute("x1", String(x1));
|
|
45
|
+
el.setAttribute("y1", String(y1));
|
|
46
|
+
el.setAttribute("x2", String(x2));
|
|
47
|
+
el.setAttribute("y2", String(y2));
|
|
48
|
+
setAttrs(el, attrs);
|
|
49
|
+
return el;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function text(
|
|
53
|
+
x: number,
|
|
54
|
+
y: number,
|
|
55
|
+
content: string,
|
|
56
|
+
anchor = "start",
|
|
57
|
+
size = "9",
|
|
58
|
+
fill = "#666",
|
|
59
|
+
weight = "400",
|
|
60
|
+
): SVGTextElement {
|
|
61
|
+
const el = document.createElementNS(svgNS, "text");
|
|
62
|
+
el.setAttribute("x", String(x));
|
|
63
|
+
el.setAttribute("y", String(y));
|
|
64
|
+
el.setAttribute("text-anchor", anchor);
|
|
65
|
+
el.setAttribute("font-size", size);
|
|
66
|
+
el.setAttribute("font-weight", weight);
|
|
67
|
+
el.setAttribute("fill", fill);
|
|
68
|
+
el.textContent = content;
|
|
69
|
+
return el;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function path(d: string, attrs: Record<string, string>): SVGPathElement {
|
|
73
|
+
const el = document.createElementNS(svgNS, "path");
|
|
74
|
+
el.setAttribute("d", d);
|
|
75
|
+
setAttrs(el, attrs);
|
|
76
|
+
return el;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Add a turbulence displacement filter for a sketchy/wobbly look */
|
|
80
|
+
export function ensureSketchFilter(svg: SVGSVGElement): string {
|
|
81
|
+
const id = "ci-sketch";
|
|
82
|
+
if (svg.querySelector(`#${id}`)) return id;
|
|
83
|
+
const defs = ensureDefs(svg);
|
|
84
|
+
const filter = svgEl("filter");
|
|
85
|
+
setAttrs(filter, { id, x: "-5%", y: "-5%", width: "110%", height: "110%" });
|
|
86
|
+
const turb = svgEl("feTurbulence");
|
|
87
|
+
setAttrs(turb, {
|
|
88
|
+
type: "turbulence",
|
|
89
|
+
baseFrequency: "0.06",
|
|
90
|
+
numOctaves: "4",
|
|
91
|
+
seed: "1",
|
|
92
|
+
result: "noise",
|
|
93
|
+
});
|
|
94
|
+
const disp = svgEl("feDisplacementMap");
|
|
95
|
+
setAttrs(disp, {
|
|
96
|
+
in: "SourceGraphic",
|
|
97
|
+
in2: "noise",
|
|
98
|
+
scale: "10",
|
|
99
|
+
xChannelSelector: "R",
|
|
100
|
+
yChannelSelector: "G",
|
|
101
|
+
});
|
|
102
|
+
filter.appendChild(turb);
|
|
103
|
+
filter.appendChild(disp);
|
|
104
|
+
defs.appendChild(filter);
|
|
105
|
+
return id;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Add a diagonal hatch pattern to the SVG defs, reusing if already present */
|
|
109
|
+
export function ensureHatchPattern(svg: SVGSVGElement): string {
|
|
110
|
+
const id = "margin-hatch";
|
|
111
|
+
if (svg.querySelector(`#${id}`)) return id;
|
|
112
|
+
const defs = ensureDefs(svg);
|
|
113
|
+
const pattern = svgEl("pattern");
|
|
114
|
+
setAttrs(pattern, {
|
|
115
|
+
id,
|
|
116
|
+
patternUnits: "userSpaceOnUse",
|
|
117
|
+
width: "5",
|
|
118
|
+
height: "5",
|
|
119
|
+
patternTransform: "rotate(45)",
|
|
120
|
+
});
|
|
121
|
+
const stripe = svgEl("line");
|
|
122
|
+
setAttrs(stripe, { x1: "0", y1: "0", x2: "0", y2: "5" });
|
|
123
|
+
stripe.classList.add("margin-hatch-stroke");
|
|
124
|
+
pattern.appendChild(stripe);
|
|
125
|
+
defs.appendChild(pattern);
|
|
126
|
+
return id;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function ensureDefs(svg: SVGSVGElement): SVGDefsElement {
|
|
130
|
+
let defs = svg.querySelector("defs") as SVGDefsElement | null;
|
|
131
|
+
if (!defs) {
|
|
132
|
+
defs = document.createElementNS(svgNS, "defs") as SVGDefsElement;
|
|
133
|
+
svg.insertBefore(defs, svg.firstChild);
|
|
134
|
+
}
|
|
135
|
+
return defs;
|
|
136
|
+
}
|