Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions devops/scripts/benchmarks/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from utils.aggregate import Aggregator, SimpleMedian, EWMA
from utils.validate import Validate
from utils.result import BenchmarkRun
from utils.logger import log
from utils.logger import log, initialize_logger
from options import options


Expand Down Expand Up @@ -362,7 +362,7 @@ def to_hist(

args = parser.parse_args()

log.initialize(args.verbose)
initialize_loger(args.verbose)
log.info("-- Compare.py --")

if args.operation == "to_hist":
Expand Down
4 changes: 2 additions & 2 deletions devops/scripts/benchmarks/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from utils.compute_runtime import *
from utils.validate import Validate
from utils.detect_versions import DetectVersion
from utils.logger import log
from utils.logger import log, initialize_logger
from presets import enabled_suites, presets

# Update this if you are changing the layout of the results files
Expand Down Expand Up @@ -722,7 +722,7 @@ def validate_and_parse_env_args(env_args):
options.flamegraph = args.flamegraph is not None

# Initialize logger with command line arguments
log.initialize(args.verbose, args.log_level)
initialize_logger(args.verbose, args.log_level)

if args.build_igc and args.compute_runtime is None:
parser.error("--build-igc requires --compute-runtime to be set")
Expand Down
119 changes: 37 additions & 82 deletions devops/scripts/benchmarks/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,91 +5,46 @@

import logging
import sys
from typing import Optional, Type, Any


# Define log level mapping as a module-level function
def _get_log_level(level_str: str) -> int:
"""Convert a string log level to a logging module level constant."""
level_map = {
"debug": logging.DEBUG,
"info": logging.INFO,
"warning": logging.WARNING,
"error": logging.ERROR,
"critical": logging.CRITICAL,
}
return level_map.get(level_str.lower(), logging.INFO)
log = logging.getLogger("ur_benchmarks")

def initialize_logger(verbose: bool = False, log_level: str = "info") -> None:
"""Configure the logger with the appropriate log level.
self._logger: logging.Logger = logging.getLogger("ur_benchmarks")
class BenchmarkLogger:
"""Logger for the Benchmark Runner.
Args:
verbose: If True, sets the log level to DEBUG regardless of log_level
log_level: One of "debug", "info", "warning", "error", "critical"
This logger provides different log levels (DEBUG, INFO, WARNING, ERROR, CRITICAL)
that can be controlled via command-line arguments. Call initialize() with the
appropriate parameters after parsing command line arguments.
Note:
This method will only initialize the logger once. Subsequent calls will be ignored.
"""

_instance: Optional["BenchmarkLogger"] = None

def __new__(cls: Type["BenchmarkLogger"]) -> "BenchmarkLogger":
if cls._instance is None:
cls._instance = super(BenchmarkLogger, cls).__new__(cls)
return cls._instance

def __init__(self) -> None:
"""Create logger but don't configure it until initialize() is called."""
self._logger: logging.Logger = logging.getLogger("ur_benchmarks")

def initialize(self, verbose: bool = False, log_level: str = "info") -> None:
"""Configure the logger with the appropriate log level.
Args:
verbose: If True, sets the log level to DEBUG regardless of log_level
log_level: One of "debug", "info", "warning", "error", "critical"
Note:
This method will only initialize the logger once. Subsequent calls will be ignored.
"""
# Return early if logger is already initialized (has handlers)
if self._logger.handlers:
return

console_handler = logging.StreamHandler(sys.stdout)

level = logging.DEBUG if verbose else _get_log_level(log_level)
self._logger.setLevel(level)
console_handler.setLevel(level)

formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
console_handler.setFormatter(formatter)

self._logger.addHandler(console_handler)

def debug(self, message: Any) -> None:
"""Log a debug message."""
if self._logger.handlers:
self._logger.debug(message)

def info(self, message: Any) -> None:
"""Log an info message."""
if self._logger.handlers:
self._logger.info(message)

def warning(self, message: Any) -> None:
"""Log a warning message."""
if self._logger.handlers:
self._logger.warning(message)

def error(self, message: Any) -> None:
"""Log an error message."""
if self._logger.handlers:
self._logger.error(message)

def critical(self, message: Any) -> None:
"""Log a critical message."""
if self._logger.handlers:
self._logger.critical(message)


# Global logger instance
log = BenchmarkLogger()
# Return early if logger is already initialized (has handlers)

if log.handlers:
return

console_handler = logging.StreamHandler(sys.stdout)

level = (
logging.DEBUG
if verbose
else dict(
debug=logging.DEBUG,
info=logging.INFO,
warning=logging.WARNING,
error=logging.ERROR,
critical=logging.CRITICAL,
).get(log_level.lower(), logging.INFO)
)

log.setLevel(level)
console_handler.setLevel(level)

formatter = logging.Formatter(
"%(asctime)s - %(levelname)s - %(message)s <%(filename)s:%(lineno)d>"
)
console_handler.setFormatter(formatter)

log.addHandler(console_handler)
Loading