bundle.perf_report¶
Extract Tracy profiler zone statistics from CSV exports, store them as structured HDF5 datasets keyed by version and platform, and generate PDF performance reports with automatic cross-version comparison.
Public API¶
Class |
Module |
Description |
|---|---|---|
|
|
Parse Tracy CSV files (or |
|
|
Single zone record (name, src_file, src_line, total_ns, total_perc, counts, mean_ns, min_ns, max_ns, std_ns). |
|
|
All records from one CSV, with |
|
|
Multi-version, multi-platform HDF5 storage via |
Full pipeline¶
The recommended way to run profiling is through the test CLI:
bundle testing python pytest --perf
# or with a custom output directory:
bundle testing python pytest --perf --perf-output ./my-perf-dir
This runs the full pipeline automatically:
Starts
tracy-capturein the background →bundle.<version>.tracyRuns the test suite as a subprocess with
PERF_MODE=true(Tracy hook active, logs silenced)Waits for
tracy-captureto finish writing when the subprocess exitsExports the
.tracyfile to CSV viatracy-csvexportLoads and stores profile data in HDF5 (
profiles.h5)Generates a PDF report (
bundle.<version>.pdf)
Output files in <repo>/perf/ (or --perf-output):
bundle.<version>.tracy— raw Tracy capturebundle.<version>.csv— exported zone statisticsbundle.<version>.pdf— performance reportprofiles.h5— historical HDF5 store
Prerequisites: bundle tracy build (builds and installs tracy-capture and tracy-csvexport).
CLI¶
The module provides a standalone generate command via the bundle CLI:
# Auto-detect backend from input files
bundle perf-report generate -i perf/ -o perf/
# Explicitly select backend
bundle perf-report generate --backend tracy -i perf/ -o perf/
bundle perf-report generate --backend cprofile -i references/linux/cprofile/ -o perf/
# Custom PDF filename, skip HDF5
bundle perf-report generate -i perf/ -o perf/ --pdf-name my_report.pdf --no-h5
This auto-detects the profiler backend from input files (.prof → cProfile, .csv/.tracy → Tracy), saves profiling data to HDF5, auto-detects a previous version as baseline for comparison, and generates a PDF with per-profile charts and optional delta columns.
Usage¶
Extract profiles¶
from bundle.perf_report import ProfileExtractor
from pathlib import Path
# From a Tracy capture file (runs tracy-csvexport internally)
profile = ProfileExtractor.extract_from_tracy(Path("bundle.1.0.0.tracy"))
# From an already-exported CSV
profile = ProfileExtractor.extract(Path("bundle.1.0.0.csv"))
# All CSV/Tracy files in a directory
profiles = ProfileExtractor.extract_all(Path("perf/"))
for rec in profile.records:
print(f"{rec.name}: mean={rec.mean_ns}ns total={rec.total_ns}ns ({rec.counts} calls)")
Store to HDF5¶
from bundle.perf_report import ProfileStorage
from pathlib import Path
# Save with version + platform key
storage = ProfileStorage.from_directory(
prof_dir=Path("perf/"),
h5_path=Path("perf/profiles.h5"),
machine_id="my-machine",
bundle_version="1.5.0",
platform_id="linux-x86_64-CPython3.12.8",
platform_meta={"system": "linux", "arch": "x86_64", "processor": "..."},
)
# Discover stored data
versions = storage.list_versions() # ["1.5.0", "1.5.1"]
platforms = storage.list_platforms("1.5.0") # ["linux-x86_64-CPython3.12.8"]
# Read back
meta = storage.load_meta("1.5.0", "linux-x86_64-CPython3.12.8")
profiles = storage.load_profiles("1.5.0", "linux-x86_64-CPython3.12.8")
Tracy CSV format¶
tracy-csvexport produces a CSV with one row per profiled zone:
Column |
Type |
Description |
|---|---|---|
|
str |
Zone / function name |
|
str |
Source file path |
|
int |
Source line number |
|
int |
Total time in all calls (nanoseconds) |
|
float |
Percentage of total capture time |
|
int |
Number of zone invocations |
|
int |
Mean time per call (nanoseconds) |
|
int |
Minimum time per call (nanoseconds) |
|
int |
Maximum time per call (nanoseconds) |
|
float |
Standard deviation (nanoseconds) |
HDF5 layout¶
/<version>/<platform_id>/
meta attrs: machine_id, platform_id, bundle_version, timestamp,
system, arch, node, processor, python_version, ...
profiles/<csv_name> structured dataset (name, src_file, src_line, total_ns,
total_perc, counts, mean_ns, min_ns, max_ns, std_ns)
attrs: csv_path, total_calls
Dependencies¶
bundle.hdf5(HDF5 store)bundle.latex(PDF generation)numpy,matplotlibclick(CLI)tracy-csvexport(external binary, installed viabundle tracy build)