Skip to content

Commit 0ff0142

Browse files
committed
Add benchmark history updates
1 parent 03bfd15 commit 0ff0142

File tree

3 files changed

+45
-24
lines changed

3 files changed

+45
-24
lines changed

devops/scripts/benchmarks/history.py

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
# Copyright (C) 2024 Intel Corporation
1+
# Copyright (C) 2024-2025 Intel Corporation
22
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
33
# See LICENSE.TXT
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

66
import os
77
import json
88
from pathlib import Path
9+
import socket
910
from utils.result import Result, BenchmarkRun
1011
from options import Compare, options
1112
from datetime import datetime, timezone
1213
from utils.utils import run
1314

1415

1516
class BenchmarkHistory:
16-
benchmark_run_index_max = 0
1717
runs = []
1818

1919
def __init__(self, dir):
@@ -35,42 +35,55 @@ def load(self, n: int):
3535
# Get all JSON files in the results directory
3636
benchmark_files = list(results_dir.glob("*.json"))
3737

38-
# Extract index numbers and sort files by index number
39-
def extract_index(file_path: Path) -> int:
38+
# Extract timestamp and sort files by it
39+
def extract_timestamp(file_path: Path) -> str:
4040
try:
41-
return int(file_path.stem.split("_")[0])
42-
except (IndexError, ValueError):
43-
return -1
41+
return file_path.stem.split("_")[-1]
42+
except IndexError:
43+
return ""
4444

45-
benchmark_files = [
46-
file for file in benchmark_files if extract_index(file) != -1
47-
]
48-
benchmark_files.sort(key=extract_index)
45+
benchmark_files.sort(key=extract_timestamp, reverse=True)
4946

5047
# Load the first n benchmark files
5148
benchmark_runs = []
52-
for file_path in benchmark_files[n::-1]:
49+
for file_path in benchmark_files[:n]:
5350
benchmark_run = self.load_result(file_path)
5451
if benchmark_run:
5552
benchmark_runs.append(benchmark_run)
5653

57-
if benchmark_files:
58-
self.benchmark_run_index_max = extract_index(benchmark_files[-1])
59-
6054
self.runs = benchmark_runs
6155

6256
def create_run(self, name: str, results: list[Result]) -> BenchmarkRun:
6357
try:
64-
result = run("git rev-parse --short HEAD")
58+
script_dir = os.path.dirname(os.path.abspath(__file__))
59+
result = run("git rev-parse --short HEAD", cwd=script_dir)
6560
git_hash = result.stdout.decode().strip()
61+
62+
# Get the GitHub repo URL from git remote
63+
remote_result = run("git remote get-url origin", cwd=script_dir)
64+
remote_url = remote_result.stdout.decode().strip()
65+
66+
# Convert SSH or HTTPS URL to owner/repo format
67+
if remote_url.startswith("[email protected]:"):
68+
# SSH format: [email protected]:owner/repo.git
69+
github_repo = remote_url.split("[email protected]:")[1].rstrip(".git")
70+
elif remote_url.startswith("https://github.com/"):
71+
# HTTPS format: https://github.com/owner/repo.git
72+
github_repo = remote_url.split("https://github.com/")[1].rstrip(".git")
73+
else:
74+
github_repo = None
75+
6676
except:
6777
git_hash = "unknown"
78+
github_repo = None
6879

6980
return BenchmarkRun(
7081
name=name,
7182
git_hash=git_hash,
83+
github_repo=github_repo,
7284
date=datetime.now(tz=timezone.utc),
7385
results=results,
86+
hostname=socket.gethostname(),
7487
)
7588

7689
def save(self, save_name, results: list[Result], to_file=True):
@@ -84,12 +97,9 @@ def save(self, save_name, results: list[Result], to_file=True):
8497
results_dir = Path(os.path.join(self.dir, "results"))
8598
os.makedirs(results_dir, exist_ok=True)
8699

87-
self.benchmark_run_index_max += 1
88-
file_path = Path(
89-
os.path.join(
90-
results_dir, f"{self.benchmark_run_index_max}_{save_name}.json"
91-
)
92-
)
100+
# Use formatted timestamp for the filename
101+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
102+
file_path = Path(os.path.join(results_dir, f"{save_name}_{timestamp}.json"))
93103
with file_path.open("w") as file:
94104
json.dump(serialized, file, indent=4)
95105
print(f"Benchmark results saved to {file_path}")
@@ -120,6 +130,7 @@ def compute_average(self, data: list[BenchmarkRun]):
120130
name=first_run.name,
121131
git_hash="average",
122132
date=first_run.date, # should this be different?
133+
hostname=first_run.hostname,
123134
)
124135

125136
return average_benchmark_run

devops/scripts/benchmarks/main.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ def main(directory, additional_env_vars, save_name, compare_names, filter):
253253
if not options.dry_run:
254254
chart_data = {this_name: results}
255255

256-
history = BenchmarkHistory(directory)
256+
results_dir = directory
257+
if options.custom_results_dir:
258+
results_dir = Path(options.custom_results_dir)
259+
history = BenchmarkHistory(results_dir)
257260
# limit how many files we load.
258261
# should this be configurable?
259262
history.load(1000)
@@ -445,7 +448,12 @@ def validate_and_parse_env_args(env_args):
445448
help="The name of the results which should be used as a baseline for metrics calculation",
446449
default=options.current_run_name,
447450
)
448-
451+
parser.add_argument(
452+
"--results-dir",
453+
type=str,
454+
help="Specify a custom results directory",
455+
default=options.custom_results_dir,
456+
)
449457
parser.add_argument(
450458
"--build-jobs",
451459
type=int,
@@ -476,6 +484,7 @@ def validate_and_parse_env_args(env_args):
476484
options.iterations_stddev = args.iterations_stddev
477485
options.build_igc = args.build_igc
478486
options.current_run_name = args.relative_perf
487+
options.custom_results_dir = args.results_dir
479488
options.build_jobs = args.build_jobs
480489

481490
if args.build_igc and args.compute_runtime is None:

devops/scripts/benchmarks/options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Options:
4242
compute_runtime_tag: str = "25.05.32567.12"
4343
build_igc: bool = False
4444
current_run_name: str = "This PR"
45+
custom_results_dir = None
4546
build_jobs: int = multiprocessing.cpu_count()
4647

4748
options = Options()

0 commit comments

Comments
 (0)