scope-profiler#
A lightweight, low-overhead profiling framework for Python and HPC applications.
scope-profiler lets you instrument code regions with decorators or context managers, collect nanosecond-resolution timing traces, and optionally integrate LIKWID hardware performance counters or line_profiler line-by-line analysis — all through a single, unified API.
Key features#
Two instrumentation styles —
@ProfileManager.profiledecorator andwith ProfileManager.region()context manager.Near-zero overhead — the default timing mode adds ~700 ns per call; profiling can be toggled off at startup with no code changes.
HDF5 time traces — start/end timestamps are flushed to disk and merged automatically, ready for post-hoc analysis and Gantt charts.
MPI-aware — per-rank data is collected and merged transparently via
mpi4py.LIKWID integration — hardware counter regions are opened/closed alongside timing, with no extra boilerplate, and every marker region’s raw events and derived metrics land in the same HDF5 file.
Line profiler integration — enable
line_profilerper-line stats on any decorated function with a single flag.CLI post-processing —
scope-profiler plotreads HDF5 output and generates Gantt charts and exports region statistics JSON with region/rank filtering.MCP server —
scope-profiler-mcpexposes structured profiling data to AI coding agents such as Claude Code, so an agent can inspect a run, benchmark a script and compare before/after profiles as part of its own workflow. See MCP server for AI coding agents.Jupyter/IPython magics —
%%scope,%%scope_lineand%%scope_recursiveprofile a cell (the last with nothing instrumented at all), while%scope_compare,%scope_df,%scope_loadand%scope_exportcompare, analyse and export runs — including one from an MPI job — without leaving the notebook. See Jupyter/IPython magics.
Quick example#
from scope_profiler import ProfileManager
with ProfileManager.session():
@ProfileManager.profile("compute")
def compute():
return sum(i * i for i in range(100_000))
compute()
Documentation#
Getting started
User guide
- Configuration
- Multiple sessions
ProfileManager.setup()parameters- Grouping settings, and reusing them
- Settings in a TOML file
- Output file size
- HDF5 compression and chunking
- Enabling
capture_region_source - Naming a run with
label - Profiling modes
- What is no longer configurable
- Toggling profiling at runtime
- Recursive profiling of decorated entrypoints
- Re-configuring
- GPU timing and synchronization
- Profiling regions
- Threads, tasks and coroutines
- HDF5 output & post-processing from Python
- Plotting with the CLI
- The example run
- Basic usage
- Text summary instead of figures
- Gantt chart
- Flame chart
- Flame graph
- Duration bar charts
- Duration over time
- Comparing several runs
- Selecting which plots to generate
- Filtering regions and ranks
- Region statistics JSON
- Interactive HTML charts
- Exporting the data behind the charts
- Exporting to external profile viewers
- Files without timing data
- Reproducing the figures on this page
- Plotly figures for the web
- Deploying a profiling dashboard
- Try it: drag and drop a profile
- MCP server for AI coding agents
- Jupyter/IPython magics
- Installing and loading
%%scope- profile a cell%scope_timeit- time a statement%%scope_line- line-by-line profiling for a cell%%scope_recursive- profile a cell with nothing instrumented%%scope_agg- aggregation mode for very hot regions%scope_load- bring in a run from outside the notebook%scope_df- a run as a pandas DataFrame%scope_last- reprint a previous run%scope_compare- compare two runs%scope_export- export a run to a file%scope_reset- drop recorded runs- Tutorial
- MPI support
- LIKWID hardware counters
- Line-by-line profiling
- Profiling Fortran code
- Profiling C and C++ code
- Profiling overhead
Interactive Jupyter tutorials
Reference
Examples & workflows