diff --git a/scripts/nvx_tools/benchmark.py b/scripts/nvx_tools/benchmark.py index b7ec07d..c1ff90e 100644 --- a/scripts/nvx_tools/benchmark.py +++ b/scripts/nvx_tools/benchmark.py @@ -39,7 +39,7 @@ KernelBuildConstants, OpenVMMBuildConstants, ) -from .common import sha256_file +from .common import bytes_to_mib, sha256_file BOOT_MARKER = b"ALPINE-MICROVM-BOOT-OK" RESTORE_MARKER = b"OPENVMM-SNAPSHOT-RESTORE-OK" @@ -1201,10 +1201,6 @@ def summarize_lifecycle_profiles( } -def bytes_to_mib(value: int | float) -> float: - return value / (1024 * 1024) - - def terminate(process: subprocess.Popen[bytes]) -> None: if process.poll() is None: process.kill() diff --git a/scripts/nvx_tools/common.py b/scripts/nvx_tools/common.py index fc63ec7..4637f70 100644 --- a/scripts/nvx_tools/common.py +++ b/scripts/nvx_tools/common.py @@ -32,6 +32,10 @@ def remaining_timeout(deadline: float) -> float: return max(0.0, deadline - time.monotonic()) +def bytes_to_mib(value: int | float) -> float: + return value / (1024 * 1024) + + def artifact_path(name: str) -> Path: return BuildConstants.BUILD_DIR / name diff --git a/scripts/nvx_tools/performance.py b/scripts/nvx_tools/performance.py index 4d76f79..e2e9b4c 100644 --- a/scripts/nvx_tools/performance.py +++ b/scripts/nvx_tools/performance.py @@ -17,6 +17,8 @@ from pathlib import Path from typing import cast +from .common import bytes_to_mib + LEGACY_CSV_FIELDS = ["commit", "metric", "unit", "direction", "p50"] CSV_FIELDS = [ "platform", @@ -66,7 +68,6 @@ "openvmm_snapshot_restore_peak_rss", } ) -BYTES_PER_MIB = 1024 * 1024 LIFECYCLE_MEMORY_MIB = 128 LIFECYCLE_BOOT_MARKER = "ALPINE-MICROVM-BOOT-OK" LIFECYCLE_RESTORE_MARKER = "OPENVMM-SNAPSHOT-RESTORE-OK" @@ -1160,7 +1161,7 @@ def read_lifecycle_data(platform: str, input_path: Path) -> LifecycleData: metric: ( unit, "lower", - value / BYTES_PER_MIB if unit == "MiB" else value, + bytes_to_mib(value) if unit == "MiB" else value, ) for metric, section, field, unit in metric_fields for value in [_openvmm_value(document, section, backend, field, input_path)] @@ -1277,8 +1278,8 @@ def append_openvmm_diagnostics( document, section, backend, "peak_rss_max_bytes", source ) lines.append( - f"| {label} | {p50 / BYTES_PER_MIB:.2f} MiB | " - f"{maximum / BYTES_PER_MIB:.2f} MiB |" + f"| {label} | {bytes_to_mib(p50):.2f} MiB | " + f"{bytes_to_mib(maximum):.2f} MiB |" ) lines.extend( [