Skip to content

[Benchmarks] Add chart annotations #19023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: sycl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 207 additions & 0 deletions devops/scripts/benchmarks/html/chart-annotations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
// Copyright (C) 2025 Intel Corporation
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

/**
* Find version changes in data points to create annotations
* @param {Array} points - Data points to analyze
* @param {string} versionKey - Key to track version changes
* @returns {Array} - List of change points
*/
function findVersionChanges(points, versionKey) {
if (!points || points.length < 2) return [];

const changes = [];
// Sort points by date
const sortedPoints = [...points].sort((a, b) => a.x - b.x);
let lastVersion = sortedPoints[0][versionKey];

for (let i = 1; i < sortedPoints.length; i++) {
const currentPoint = sortedPoints[i];

const currentVersion = currentPoint[versionKey];
if (currentVersion && currentVersion !== lastVersion) {
changes.push({
date: currentPoint.x,
newVersion: currentVersion,
});
lastVersion = currentVersion;
}
}

return changes;
}

/**
* Add version change annotations to chart options
* @param {Object} data - Chart data
* @param {Object} options - Chart.js options object
*/
function addVersionChangeAnnotations(data, options) {
const changeTrackers = [
{
// Benchmark repos updates
versionKey: 'gitBenchHash',
sources: [
{
name: "Compute Benchmarks",
url: "https://github.com/intel/compute-benchmarks.git",
Comment on lines +48 to +49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't these stored in group metadata? we should ideally create this list automatically.

color: {
border: 'rgba(220, 53, 69, 0.8)',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's a minor thing, but maybe we should pick colors that aren't similar to what we use for data series? someone might misinterpret the annotation as relating to just one series.
(i'm not sure it's going to be possible).

background: 'rgba(220, 53, 69, 0.9)'
}
},
{
name: "SYCL-Bench",
url: "https://github.com/unisa-hpc/sycl-bench.git",
color: {
border: 'rgba(32, 156, 238, 0.8)',
background: 'rgba(32, 156, 238, 0.9)'
}
},
{
name: "Velocity-Bench",
url: "https://github.com/oneapi-src/Velocity-Bench/",
color: {
border: 'rgba(255, 153, 0, 0.8)',
background: 'rgba(255, 153, 0, 0.9)'
}
}
],
pointsFilter: (points, url) => points.filter(p => p.gitBenchUrl === url),
formatLabel: (sourceName, version) => `${sourceName}: ${version.substring(0, 7)}`
},
{
// Compute Runtime updates
versionKey: 'compute_runtime',
sources: [
{
name: "Compute Runtime",
url: "https://github.com/intel/compute-runtime.git",
color: {
border: 'rgba(40, 167, 69, 0.8)',
background: 'rgba(40, 167, 69, 0.9)'
}
}
],
}
];

changeTrackers.forEach(tracker => {
tracker.sources.forEach((source) => {
const changes = {};

// Find changes across all runs
Object.values(data.runs).flatMap(runData =>
findVersionChanges(
tracker.pointsFilter ? tracker.pointsFilter(runData.data, source.url) : runData.data,
tracker.versionKey
)
).forEach(change => {
const changeKey = `${source.name}-${change.newVersion}`;
if (!changes[changeKey] || change.date < changes[changeKey].date) {
changes[changeKey] = change;
}
});

// Create annotation for each unique change
Object.values(changes).forEach(change => {
const annotationId = `${change.date}`;
// If annotation at a given date already exists, update it
if (options.plugins.annotation.annotations[annotationId]) {
options.plugins.annotation.annotations[annotationId].label.content.push(`${tracker.formatLabel ?
`tracker.formatLabel(source.name, change.newVersion)` :
`${source.name}: ${change.newVersion}`}`);
options.plugins.annotation.annotations[annotationId].borderColor = 'rgba(128, 128, 128, 0.8)';
options.plugins.annotation.annotations[annotationId].borderWidth += 1;
options.plugins.annotation.annotations[annotationId].label.backgroundColor = 'rgba(128, 128, 128, 0.9)';
} else {
options.plugins.annotation.annotations[annotationId] = {
type: 'line',
xMin: change.date,
xMax: change.date,
borderColor: source.color.border,
borderWidth: 2,
borderDash: [3, 3],
label: {
content: [ tracker.formatLabel ?
tracker.formatLabel(source.name, change.newVersion) :
`${source.name}: ${change.newVersion}` ],
display: false,
position: 'start',
backgroundColor: source.color.background,
z: 1,
}
}
};
});
});
});
}

/**
* Set up event listeners for annotation interactions
* @param {Chart} chart - Chart.js instance
* @param {CanvasRenderingContext2D} ctx - Canvas context
* @param {Object} options - Chart.js options object
*/
function setupAnnotationListeners(chart, ctx, options) {
// Add event listener for annotation clicks - display/hide label
ctx.canvas.addEventListener('click', function(e) {
const activeElements = chart.getElementsAtEventForMode(e, 'nearest', { intersect: true }, false);

// If no data point is clicked, check if an annotation was clicked
if (activeElements.length === 0) {
const rect = chart.canvas.getBoundingClientRect();
const x = e.clientX - rect.left;

// Check if click is near any annotation line
const annotations = options.plugins.annotation.annotations;
Object.values(annotations).some(annotation => {
// Get the position of the annotation line
const xPos = chart.scales.x.getPixelForValue(annotation.xMin);

// Display label if click is near the annotation line (within 5 pixels)
if (Math.abs(x - xPos) < 5) {
annotation.label.display = !annotation.label.display;
chart.update();
return true; // equivalent to break in a for loop
}
return false;
});
}
});

// Add mouse move handler to change cursor when hovering over annotations
ctx.canvas.addEventListener('mousemove', function(e) {
const rect = chart.canvas.getBoundingClientRect();
const x = e.clientX - rect.left;

// Check if mouse is near any annotation line
const annotations = options.plugins.annotation.annotations;
const isNearAnnotation = Object.values(annotations).some(annotation => {
const xPos = chart.scales.x.getPixelForValue(annotation.xMin);

if (Math.abs(x - xPos) < 5) {
return true;
}
return false;
});

// Change cursor style based on proximity to annotation
ctx.canvas.style.cursor = isNearAnnotation ? 'pointer' : '';
});

// Reset cursor when mouse leaves the chart area
ctx.canvas.addEventListener('mouseleave', function() {
ctx.canvas.style.cursor = '';
});
}

// Export functions to make them available to other modules
window.ChartAnnotations = {
findVersionChanges,
addVersionChangeAnnotations,
setupAnnotationListeners
};
2 changes: 2 additions & 0 deletions devops/scripts/benchmarks/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
<title>Benchmark Results</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-annotation"></script>
<script src="data.js"></script>
<script src="config.js"></script>
<script src="chart-annotations.js"></script>
<script src="scripts.js"></script>
<link rel="stylesheet" href="styles.css">
</head>
Expand Down
44 changes: 21 additions & 23 deletions devops/scripts/benchmarks/html/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ function createChart(data, containerId, type) {
`Stddev: ${point.stddev.toFixed(2)} ${data.unit}`,
`Git Hash: ${point.gitHash}`,
`Compute Runtime: ${point.compute_runtime}`,
`Bench hash: ${point.gitBenchHash?.substring(0, 7)}`,
`Bench URL: ${point.gitBenchUrl}`,
];
} else {
return [`${context.dataset.label}:`,
Expand All @@ -140,7 +142,10 @@ function createChart(data, containerId, type) {
}
}
}
}
},
annotation: type === 'time' ? {
annotations: {}
} : undefined
},
scales: {
y: {
Expand All @@ -158,7 +163,7 @@ function createChart(data, containerId, type) {
if (type === 'time') {
options.interaction = {
mode: 'nearest',
intersect: false
intersect: true // Require to hover directly over a point
};
options.onClick = (event, elements) => {
if (elements.length > 0) {
Expand All @@ -180,6 +185,11 @@ function createChart(data, containerId, type) {
maxTicksLimit: 10
}
};

// Add dependencies version change annotations
if (Object.keys(data.runs).length > 0) {
ChartAnnotations.addVersionChangeAnnotations(data, options);
}
}

const chartConfig = {
Expand All @@ -202,29 +212,15 @@ function createChart(data, containerId, type) {

const chart = new Chart(ctx, chartConfig);
chartInstances.set(containerId, chart);

// Add annotation interaction handlers for time-series charts
if (type === 'time') {
ChartAnnotations.setupAnnotationListeners(chart, ctx, options);
}

return chart;
}

function createTimeseriesDatasets(data) {
return Object.entries(data.runs).map(([name, runData], index) => ({
label: runData.runName, // Use run name for legend
data: runData.points.map(p => ({
seriesName: runData.runName, // Use run name for tooltips
x: p.date,
y: p.value,
gitHash: p.git_hash,
gitRepo: p.github_repo,
stddev: p.stddev
})),
borderColor: colorPalette[index % colorPalette.length],
backgroundColor: colorPalette[index % colorPalette.length],
borderWidth: 1,
pointRadius: 3,
pointStyle: 'circle',
pointHoverRadius: 5
}));
}

function updateCharts() {
const filterRunData = (chart) => ({
...chart,
Expand Down Expand Up @@ -815,7 +811,9 @@ function addRunDataPoint(group, run, result, comparison, name = null) {
stddev: result.stddev,
gitHash: run.git_hash,
gitRepo: run.github_repo,
compute_runtime: run.compute_runtime
compute_runtime: run.compute_runtime,
gitBenchUrl: result.git_url,
gitBenchHash: result.git_hash,
});

return group;
Expand Down
Loading