Skip to main content

Module benchmark_common

Module benchmark_common 

Source
Expand description

Benchmark common utilities — PCI bus ID normalization, timing, result structs with JSON serialization, and timestamped logging.

Ports the core infrastructure from scripts/lib/benchmark_common.sh:

  • PCI bus ID normalization (0000:01:00.0 → 01:00.0)
  • Benchmark timing utilities (elapsed calculation, formatting)
  • BenchmarkResult struct with JSON serialization compatible with benchmark_logs.rs parsing
  • Timestamped logging with [YYYY-MM-DD HH:MM:SS] prefix
  • Tee-style logging to stderr + optional file output

§Validation Assertions

  • VAL-INFRA-013: PCI bus normalization, timing utilities, result struct with JSON serialization
  • VAL-INFRA-014: Timestamped logging [YYYY-MM-DD HH:MM:SS] prefix, supports stderr + file output

Structs§

BenchLogger
Benchmark logger that writes timestamped lines to stderr and optionally to a log file (tee behavior).
BenchTimer
A simple stopwatch for benchmark timing.
BenchmarkResult
A single benchmark measurement result.
BenchmarkResults
A collection of benchmark results, compatible with the JSON schema used by benchmark_logs.rs.

Functions§

format_elapsed
Format a Duration as a human-readable string.
format_timestamp_prefix
Format a timestamp string for use in log lines.
is_dry_run
Check if dry-run mode is enabled via environment variable.
normalize_pci_bus_id
Normalize a PCI bus ID string.
now_timestamp
Get the current timestamp in YYYY-MM-DD HH:MM:SS format.
resolve_log_dir
Resolve the benchmark log directory.