1- from utils . aggregate import Aggregator , SimpleMedian , EWMA
2- from utils . validate import Validate
3- from utils . result import Result , BenchmarkRun
4- from options import options
1+ # Copyright (C) 2024-2025 Intel Corporation
2+ # Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
3+ # See LICENSE.TXT
4+ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55
6- import os
76import re
8- import sys
97import json
108import argparse
119from datetime import datetime , timezone
1210from pathlib import Path
1311from dataclasses import dataclass , asdict
1412
13+ from utils .aggregate import Aggregator , SimpleMedian , EWMA
14+ from utils .validate import Validate
15+ from utils .result import BenchmarkRun
16+ from utils .logger import log
17+ from options import options
18+
1519
1620verbose = False
1721
22+
1823@dataclass
1924class BenchmarkHistoricAverage :
2025 """Contains historic average information for 1 benchmark"""
@@ -115,8 +120,8 @@ def validate_benchmark_result(result: BenchmarkRun) -> bool:
115120 if result .hostname != hostname :
116121 return False
117122 if result .name != result_name :
118- print (
119- f"Warning: Result file { result_path } does not match specified result name { result .name } ."
123+ log . warning (
124+ f"Result file { result_path } does not match specified result name { result .name } ."
120125 )
121126 return False
122127 if result .date < datetime .strptime (cutoff , "%Y%m%d_%H%M%S" ).replace (
@@ -227,10 +232,9 @@ def perf_diff_entry() -> dict:
227232 elif halfway_round (delta , 2 ) < - options .regression_threshold :
228233 regression .append (perf_diff_entry ())
229234
230- if verbose :
231- print (
232- f"{ test .name } : expect { hist_avg [test .name ].value } , got { test .value } "
233- )
235+ log .debug (
236+ f"{ test .name } : expect { hist_avg [test .name ].value } , got { test .value } "
237+ )
234238
235239 return improvement , regression
236240
@@ -267,24 +271,24 @@ def to_hist(
267271 elif avg_type == "EWMA" :
268272 aggregator_type = EWMA
269273 else :
270- print ( "Error: Unsupported avg_type f{avg_type}." )
274+ log . error ( " Unsupported avg_type f{avg_type}." )
271275 exit (1 )
272276
273277 try :
274278 with open (compare_file , "r" ) as compare_f :
275279 compare_result = BenchmarkRun .from_json (json .load (compare_f ))
276280 except :
277- print (f"Unable to open { compare_file } ." )
281+ log . error (f"Unable to open { compare_file } ." )
278282 exit (1 )
279283
280284 # Sanity checks:
281285 if compare_result .hostname == "Unknown" :
282- print (
286+ log . error (
283287 "Hostname for results in {compare_file} unknown, unable to build a historic average: Refusing to continue."
284288 )
285289 exit (1 )
286290 if not Validate .timestamp (cutoff ):
287- print ("Invalid timestamp provided, please follow YYYYMMDD_HHMMSS." )
291+ log . error ("Invalid timestamp provided, please follow YYYYMMDD_HHMMSS." )
288292 exit (1 )
289293
290294 # Build historic average and compare results against historic average:
@@ -348,13 +352,13 @@ def to_hist(
348352
349353 if args .verbose :
350354 verbose = True
351- print ("-- Compare.py --" )
355+ log . info ("-- Compare.py --" )
352356
353357 if args .operation == "to_hist" :
354358 if not Validate .timestamp (args .cutoff ):
355359 raise ValueError ("Timestamp must be provided as YYYYMMDD_HHMMSS." )
356360 if args .avg_type not in ["median" , "EWMA" ]:
357- print ("Only median, EWMA is currently supported: exiting." )
361+ log . error ("Only median, EWMA is currently supported: exiting." )
358362 exit (1 )
359363
360364 improvements , regressions = Compare .to_hist (
@@ -373,28 +377,34 @@ def to_hist(
373377 else :
374378 regressions_ignored .append (test )
375379
376- def print_regression (entry : dict ):
377- """Print an entry outputted from Compare.to_hist"""
378- print (f"Test: { entry ['name' ]} " )
379- print (f"-- Historic { entry ['avg_type' ]} : { entry ['hist_avg' ]} " )
380- print (f"-- Run result: { entry ['value' ]} " )
381- print (f"-- Delta: { entry ['delta' ]} " )
382- print ("" )
380+ def print_regression (entry : dict , is_warning : bool = False ):
381+ """Print an entry outputted from Compare.to_hist
382+
383+ Args:
384+ entry (dict): The entry to print
385+ is_warning (bool): If True, use log.warning instead of log.info
386+ """
387+ log_func = log .warning if is_warning else log .info
388+ log_func (f"Test: { entry ['name' ]} " )
389+ log_func (f"-- Historic { entry ['avg_type' ]} : { entry ['hist_avg' ]} " )
390+ log_func (f"-- Run result: { entry ['value' ]} " )
391+ log_func (f"-- Delta: { entry ['delta' ]} " )
392+ log_func ("" )
383393
384394 if improvements :
385- print ("#\n # Improvements:\n #\n " )
395+ log . info ("#\n # Improvements:\n #\n " )
386396 for test in improvements :
387397 print_regression (test )
388398 if regressions_ignored :
389- print ("#\n # Regressions (filtered out by regression-filter):\n #\n " )
399+ log . info ("#\n # Regressions (filtered out by regression-filter):\n #\n " )
390400 for test in regressions_ignored :
391401 print_regression (test )
392402 if regressions_of_concern :
393- print ("#\n # Regressions:\n #\n " )
403+ log . warning ("#\n # Regressions:\n #\n " )
394404 for test in regressions_of_concern :
395- print_regression (test )
405+ print_regression (test , is_warning = True )
396406 exit (1 ) # Exit 1 to trigger github test failure
397- print ("\n No unexpected regressions found!" )
407+ log . info ("\n No unexpected regressions found!" )
398408 else :
399- print ("Unsupported operation: exiting." )
409+ log . error ("Unsupported operation: exiting." )
400410 exit (1 )
0 commit comments