Examples and workflows#

Install for this page: pip install scope-profiler runs the core examples. pip install "scope-profiler[extras]" adds every broadly installable example dependency; LIKWID remains separate and needs a system LIKWID installation plus scope-profiler[likwid].

The repository includes small scripts for specific profiling tasks and a repeatable AI optimization workflow.

Profiling examples#

Run an example with:

python examples/<script>.py

For large or high-frequency workloads, aggregation mode stores call counts, inclusive totals, minimums, maximums, and exclusive totals while keeping the profile small:

with ProfileManager.session(
    aggregation_mode=True,
    return_results=True,
) as run:
    with ProfileManager.region("solve"):
        solve()

run.results.print_summary(title="Aggregate profile")

See ex_aggregation.py for a complete runnable example. Individual events and timeline plots are not available in this mode.

Output formats#

The extension of the output path picks the format, and HDF5 remains the default. A JSON profile holds exactly the same run — every call, in integer nanoseconds — and reads back into the same ProfilingResults:

scope-profiler run -o profile.json my_script.py          # or .json.gz, or .html
scope-profiler export json profiling_data.h5 -o exports  # convert an existing run
from scope_profiler import read_json, write_json

write_json(run.results, "profile.json.gz")
results = read_json("profile.json.gz")

See ex_json_export.py for a complete runnable example, and CLI reference for when to prefer which format.

AI optimization workflow#

The agent workflow example demonstrates measure → edit → re-measure → correctness-check using the CLI or MCP tools. The runnable repository workload is configured in benchmarks/sensor.toml.

See AGENTS.md for the instructions used by Codex and other coding agents.