Skip to content

Commit f119e29

Browse files
committed
[Benchmarks] Add benchmarks logger
1 parent 156429e commit f119e29

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

devops/scripts/benchmarks/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ are stored [here](https://oneapi-src.github.io/unified-runtime/performance/).
4545
## Output formats
4646
You can display the results in the form of a HTML file by using `--ouptut-html` and a markdown file by using `--output-markdown`. Due to character limits for posting PR comments, the final content of the markdown file might be reduced. In order to obtain the full markdown output, use `--output-markdown full`.
4747

48+
## Logging
49+
50+
The benchmark runner uses a configurable logging system with different log levels that can be set using the `--log-level` command-line option.
51+
52+
Available log levels:
53+
- `debug`
54+
- `info` (default)
55+
- `warning`
56+
- `error`
57+
- `critical`
58+
59+
To set the log level, use the `--log-level` option:
60+
```bash
61+
./main.py ~/benchmarks_workdir/ --sycl ~/llvm/build/ --log-level debug
62+
```
63+
4864
## Requirements
4965

5066
### Python

devops/scripts/benchmarks/main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from utils.compute_runtime import *
2222
from utils.validate import Validate
2323
from utils.detect_versions import DetectVersion
24+
from utils.logger import log, LogLevel
2425
from presets import enabled_suites, presets
2526

2627
import argparse
@@ -576,6 +577,13 @@ def validate_and_parse_env_args(env_args):
576577
"'Include archived runs'. PR runs typically have a shorter retention period than baselines.",
577578
default=options.archive_pr_days,
578579
)
580+
parser.add_argument(
581+
"--log-level",
582+
type=str,
583+
choices=["debug", "info", "warning", "error", "critical"],
584+
help="Set the logging level",
585+
default="info",
586+
)
579587

580588
args = parser.parse_args()
581589
additional_env_vars = validate_and_parse_env_args(args.env)
@@ -606,6 +614,12 @@ def validate_and_parse_env_args(env_args):
606614
options.build_jobs = args.build_jobs
607615
options.hip_arch = args.hip_arch
608616

617+
# Set the log level
618+
log_level = LogLevel.from_string(args.log_level).value
619+
log.logger.setLevel(log_level)
620+
for handler in log.logger.handlers:
621+
handler.setLevel(log_level)
622+
609623
if args.build_igc and args.compute_runtime is None:
610624
parser.error("--build-igc requires --compute-runtime to be set")
611625
if args.compute_runtime is not None:
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Copyright (C) 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
5+
6+
import logging
7+
import sys
8+
from enum import Enum
9+
10+
class LogLevel(Enum):
11+
DEBUG = logging.DEBUG
12+
INFO = logging.INFO
13+
WARNING = logging.WARNING
14+
ERROR = logging.ERROR
15+
CRITICAL = logging.CRITICAL
16+
17+
@staticmethod
18+
def from_string(level_str):
19+
level_map = {
20+
"debug": LogLevel.DEBUG,
21+
"info": LogLevel.INFO,
22+
"warning": LogLevel.WARNING,
23+
"error": LogLevel.ERROR,
24+
"critical": LogLevel.CRITICAL
25+
}
26+
return level_map.get(level_str.lower(), LogLevel.INFO)
27+
28+
class BenchmarkLogger:
29+
"""Logger for the Unified Runtime Benchmark Runner.
30+
31+
This logger provides different log levels (DEBUG, INFO, WARNING, ERROR, CRITICAL)
32+
that can be controlled via command-line arguments.
33+
"""
34+
35+
_instance = None
36+
37+
def __new__(cls):
38+
if cls._instance is None:
39+
cls._instance = super(BenchmarkLogger, cls).__new__(cls)
40+
cls._instance._initialize_logger()
41+
return cls._instance
42+
43+
def _initialize_logger(self):
44+
"""Initialize the logger with the appropriate log level."""
45+
self.logger = logging.getLogger("ur_benchmarks")
46+
47+
# Create console handler
48+
console_handler = logging.StreamHandler(sys.stdout)
49+
50+
# Set default log level (INFO)
51+
self.logger.setLevel(logging.INFO)
52+
console_handler.setLevel(logging.INFO)
53+
54+
# Create formatter
55+
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
56+
console_handler.setFormatter(formatter)
57+
58+
# Add the handler to the logger
59+
self.logger.addHandler(console_handler)
60+
61+
def debug(self, message):
62+
"""Log a debug message."""
63+
self.logger.debug(message)
64+
65+
def info(self, message):
66+
"""Log an info message."""
67+
self.logger.info(message)
68+
69+
def warning(self, message):
70+
"""Log a warning message."""
71+
self.logger.warning(message)
72+
73+
def error(self, message):
74+
"""Log an error message."""
75+
self.logger.error(message)
76+
77+
def critical(self, message):
78+
"""Log a critical message."""
79+
self.logger.critical(message)
80+
81+
# Global logger instance
82+
log = BenchmarkLogger()

0 commit comments

Comments
 (0)