
This commit introduces a new feature for logging elapsed time for specific Key Performance Indicators (KPIs). Usage: time_kpi = TimeKPI(time.time()) code ... code ... . . . code ... time_kpi.log_elapsed_time(time.time(), "Kpi_name/function_name") Example LOG: [2025-05-08 03:41:55] KTE INFO MainThread time_kpi.log_elapsed_time 52 :: test_func_test elapsed time: 2.06 seconds Change-Id: Idefbdb2dc707b05ac5d24194b34af1dcb236e152 Signed-off-by: Abhishek jaiswal <abhishek.jaiswal@windriver.com>
32 lines
900 B
Python
32 lines
900 B
Python
import time
|
|
|
|
from framework.logging.automation_logger import get_logger
|
|
|
|
|
|
class TimeKPI:
|
|
"""
|
|
A class to represent a time-based KPI (Key Performance Indicator).
|
|
"""
|
|
|
|
def __init__(self, start_time: float):
|
|
"""Initialize the TimeKPI with a name and value.
|
|
|
|
Args:
|
|
start_time (float): The time when the KPI started.
|
|
"""
|
|
self.start_time = start_time
|
|
|
|
def log_elapsed_time(self, end_time: float, kpi_name: str) -> float:
|
|
"""Calculate the elapsed time since the start time.
|
|
|
|
Args:
|
|
end_time (float): The time when the KPI ended.
|
|
kpi_name (str): The time when the KPI ended.
|
|
|
|
Returns:
|
|
float: The elapsed time.
|
|
"""
|
|
elapsed_time = time.time() - self.start_time
|
|
message = f"{kpi_name} elapsed time: {elapsed_time:.2f} seconds"
|
|
get_logger().log_kpi(message)
|