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
66import os
77import json
88from pathlib import Path
9+ import socket
910from utils .result import Result , BenchmarkRun
1011from options import Compare , options
1112from datetime import datetime , timezone
1213from utils .utils import run
1314
1415
1516class 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
0 commit comments