Skip to content

Commit 0987a08

Browse files
committed
change use of data.js
1 parent e0390c8 commit 0987a08

File tree

7 files changed

+241
-234
lines changed

7 files changed

+241
-234
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/html/data.js
2+
/html/flamegraphs.js

devops/scripts/benchmarks/benches/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ def run_bench(
195195
raise
196196

197197
if self.traceable(TracingType.FLAMEGRAPH) and run_flamegraph and perf_data_file:
198-
svg_file = get_flamegraph().handle_output(self.name(), perf_data_file)
198+
svg_file = get_flamegraph().handle_output(
199+
self.name(), perf_data_file, self.get_suite_name()
200+
)
199201
log.info(f"FlameGraph generated: {svg_file}")
200202

201203
if use_stdout:

devops/scripts/benchmarks/html/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns"></script>
1515
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-annotation"></script>
1616
<script src="data.js"></script>
17+
<script src="flamegraphs.js"></script>
1718
<script src="config.js"></script>
1819
<script src="chart-annotations.js"></script>
1920
<script src="scripts.js"></script>

devops/scripts/benchmarks/html/scripts.js

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ function createRunElement(name) {
114114
}
115115

116116
function addSelectedRun() {
117+
if (!runSelect) return; // Safety check for DOM element
117118
const selectedRun = runSelect.value;
118119
if (selectedRun && !activeRuns.has(selectedRun)) {
119120
activeRuns.add(selectedRun);
@@ -1331,12 +1332,19 @@ function initializeCharts() {
13311332
console.log('Layer comparisons data processed:', layerComparisonsData.length, 'items');
13321333

13331334
allRunNames = [...new Set(loadedBenchmarkRuns.map(run => run.name))];
1335+
1336+
// In flamegraph-only mode, ensure we include runs from flamegraph data
1337+
if (validateFlameGraphData()) {
1338+
const flamegraphRunNames = Object.keys(flamegraphData.runs);
1339+
allRunNames = [...new Set([...allRunNames, ...flamegraphRunNames])];
1340+
}
1341+
13341342
latestRunsLookup = createLatestRunsLookup();
13351343
console.log('Run names and lookup created. Runs:', allRunNames);
13361344

13371345
// Check if we have actual benchmark results vs flamegraph-only results
13381346
const hasActualBenchmarks = loadedBenchmarkRuns.some(run =>
1339-
run.results && run.results.some(result => result.suite !== 'flamegraph')
1347+
run.results && run.results.length > 0 && run.results.some(result => result.suite !== 'flamegraph')
13401348
);
13411349

13421350
const hasFlameGraphResults = loadedBenchmarkRuns.some(run =>
@@ -1346,7 +1354,14 @@ function initializeCharts() {
13461354
console.log('Benchmark analysis:', {
13471355
hasActualBenchmarks,
13481356
hasFlameGraphResults,
1349-
loadedBenchmarkRuns: loadedBenchmarkRuns.length
1357+
loadedBenchmarkRuns: loadedBenchmarkRuns.length,
1358+
runDetails: loadedBenchmarkRuns.map(run => ({
1359+
name: run.name,
1360+
resultCount: run.results ? run.results.length : 0,
1361+
hasResults: run.results && run.results.length > 0
1362+
})),
1363+
flamegraphValidation: validateFlameGraphData(),
1364+
flamegraphRunCount: validateFlameGraphData() ? Object.keys(flamegraphData.runs).length : 0
13501365
});
13511366

13521367
// If we only have flamegraph results (no actual benchmark data), create synthetic data
@@ -1408,6 +1423,12 @@ function initializeCharts() {
14081423
} else {
14091424
// No runs parameter, use defaults
14101425
activeRuns = new Set(defaultCompareNames || []);
1426+
1427+
// If no default runs and we're in flamegraph-only mode, use all available runs
1428+
if (activeRuns.size === 0 && !hasActualBenchmarks && hasFlameGraphResults) {
1429+
activeRuns = new Set(allRunNames);
1430+
console.log('Flamegraph-only mode: auto-selected all available runs:', Array.from(activeRuns));
1431+
}
14111432
}
14121433

14131434
// Setup UI components
@@ -1779,36 +1800,33 @@ function createSyntheticFlameGraphData(flamegraphLabels) {
17791800

17801801
// Create synthetic benchmark results for each flamegraph
17811802
flamegraphLabels.forEach(label => {
1782-
// Try to determine suite from metadata, default to "Flamegraphs"
1783-
const metadata = metadataForLabel(label, 'benchmark');
1784-
let suite = 'Flamegraphs';
1803+
// Get suite from flamegraphData - this should always be available
1804+
let suite = null;
17851805

1786-
// Try to match with existing metadata to get proper suite name
1787-
if (metadata) {
1788-
// Most flamegraphs are likely from Compute Benchmarks
1789-
suite = 'Compute Benchmarks';
1790-
} else {
1791-
// For common benchmark patterns, assume Compute Benchmarks
1792-
const computeBenchmarkPatterns = [
1793-
'SubmitKernel', 'SubmitGraph', 'FinalizeGraph', 'SinKernelGraph',
1794-
'AllocateBuffer', 'CopyBuffer', 'CopyImage', 'CreateBuffer',
1795-
'CreateContext', 'CreateImage', 'CreateKernel', 'CreateProgram',
1796-
'CreateQueue', 'ExecuteKernel', 'MapBuffer', 'MapImage',
1797-
'ReadBuffer', 'ReadImage', 'WriteBuffer', 'WriteImage'
1798-
];
1799-
1800-
if (computeBenchmarkPatterns.some(pattern => label.includes(pattern))) {
1801-
suite = 'Compute Benchmarks';
1806+
if (window.flamegraphData?.runs) {
1807+
// Check all runs for suite information for this benchmark
1808+
for (const runName in flamegraphData.runs) {
1809+
const runData = flamegraphData.runs[runName];
1810+
if (runData.suites && runData.suites[label]) {
1811+
suite = runData.suites[label];
1812+
break;
1813+
}
18021814
}
18031815
}
18041816

1817+
// If no suite found, this indicates a problem with the flamegraph data generation
1818+
if (!suite) {
1819+
console.error(`No suite information found for flamegraph: ${label}. This indicates missing suite data in flamegraphs.js`);
1820+
suite = `ERROR: Missing suite for ${label}`;
1821+
}
1822+
18051823
// Add to suite names
18061824
suiteNames.add(suite);
18071825

18081826
// Create a synthetic timeseries entry for this flamegraph
18091827
const syntheticData = {
18101828
label: label,
1811-
display_label: metadata?.display_name || label,
1829+
display_label: label, // Use label directly since this is synthetic data
18121830
suite: suite,
18131831
unit: 'flamegraph',
18141832
lower_is_better: false,

devops/scripts/benchmarks/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,15 @@ def main(directory, additional_env_vars, compare_names, filter):
410410
f"Reloaded {len(history.runs)} benchmark runs for HTML generation."
411411
)
412412

413+
# Finalize flamegraph data for this run (write all benchmarks to flamegraphs.js)
414+
if options.flamegraph and options.save_name:
415+
try:
416+
flamegraph = get_flamegraph()
417+
flamegraph.finalize_run_flamegraphs(html_path, options.save_name)
418+
log.info(f"Finalized flamegraph data for run: {options.save_name}")
419+
except Exception as e:
420+
log.debug(f"Failed to finalize flamegraph data: {e}")
421+
413422
generate_html(history, compare_names, html_path, metadata)
414423
log.info(f"HTML with benchmark results has been generated")
415424

devops/scripts/benchmarks/output_html.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,6 @@ def _write_output_to_file(
2626
if options.output_html == "local":
2727
data_path = os.path.join(html_path, f"{filename}.js")
2828

29-
# Check if the file exists and has flamegraph data that we need to preserve
30-
existing_flamegraph_data = None
31-
if os.path.exists(data_path):
32-
try:
33-
with open(data_path, "r") as f:
34-
existing_content = f.read()
35-
# Extract existing flamegraphData if present
36-
if "flamegraphData = {" in existing_content:
37-
start = existing_content.find("flamegraphData = {")
38-
if start != -1:
39-
# Find the end of the flamegraphData object
40-
brace_count = 0
41-
found_start = False
42-
end = start
43-
for i, char in enumerate(existing_content[start:], start):
44-
if char == "{":
45-
brace_count += 1
46-
found_start = True
47-
elif char == "}" and found_start:
48-
brace_count -= 1
49-
if brace_count == 0:
50-
end = i + 1
51-
break
52-
if found_start and end > start:
53-
# Extract the complete flamegraphData section including the semicolon
54-
next_semicolon = existing_content.find(";", end)
55-
if next_semicolon != -1:
56-
existing_flamegraph_data = existing_content[
57-
start : next_semicolon + 1
58-
]
59-
log.debug(
60-
"Preserved existing flamegraph data for HTML output"
61-
)
62-
except Exception as e:
63-
log.debug(f"Could not parse existing flamegraph data: {e}")
64-
6529
with open(data_path, "w") as f:
6630
# For local format, we need to write JavaScript variable assignments
6731
f.write("benchmarkRuns = ")
@@ -80,12 +44,6 @@ def _write_output_to_file(
8044
json.dump(json.loads(output.to_json())["tags"], f, indent=2)
8145
f.write(";\n")
8246

83-
# Preserve and append existing flamegraph data if any
84-
if existing_flamegraph_data:
85-
f.write("\n")
86-
f.write(existing_flamegraph_data)
87-
f.write("\n")
88-
8947
if not archive:
9048
log.info(f"See {html_path}/index.html for the results.")
9149
else:

0 commit comments

Comments
 (0)