Profile code regions in python, optionally with LIKWID markers.
Project description
scope-profiler
This module provides a unified profiling system for Python applications, with optional integration of LIKWID markers using the pylikwid marker API for hardware performance counters.
It allows you to:
- Configure profiling globally via a singleton ProfilingConfig.
- Collect timing data via context-managed profiling regions.
- Use a clean decorator syntax to profile functions.
- Optionally record time traces in HDF5 files.
- Automatically initialize and close LIKWID markers only when needed.
- Print aggregated summaries of all profiling regions.
Install
Install from PyPI:
pip install scope-profiler
Usage
To set up the configuration, create an instance of ProfilingConfig and add it to the ProfileManager, this should be done once at application startup and will persist until the program exits or is explicitly finalized (see below). Note that the config applies to any profiling contexts created (even in other files) after it has been initialized.
from scope_profiler import ProfileManager
# Setup global profiling configuration
ProfileManager.setup(
use_likwid=False,
time_trace=True,
flush_to_disk=True,
)
# Profile the main() function with a decorator
@ProfileManager.profile("main")
def main():
x = 0
for i in range(10):
# Profile each iteration with a context manager
with ProfileManager.profile_region(region_name="iteration"):
x += 1
# Call main
main()
# Finalize profiler
ProfileManager.finalize()
Execution:
❯ python test.py
Region: main
Total Calls : 1
Total Time : 0.001503709 s
Avg Time : 0.001503709 s
Min Time : 0.001503709 s
Max Time : 0.001503709 s
Std Dev : 0.0 s
----------------------------------------
Region: iteration
Total Calls : 10
Total Time : 3.832e-06 s
Avg Time : 3.832e-07 s
Min Time : 2.08e-07 s
Max Time : 8.75e-07 s
Std Dev : 2.2431888016838885e-07 s
----------------------------------------
Overhead
The profiling overhead per call depends on the region type.
The benchmark below (examples/benchmark_overhead.py) measures each mode
against a bare function call:
The two modes most relevant to HPC — NCallsOnly and TimeOnly — add roughly 0.09 µs and 0.75 µs per instrumented call respectively.
Profiling can also be fully deactivated at setup time
(profiling_activated=False) to reduce the overhead to ~0.03 µs — barely
above a bare function call — making it safe to leave instrumentation in
production code and toggle it on only when needed.
The LineProfiler mode is intentionally heavier (~41 µs/call) because
line_profiler traces every source line. It is designed for targeted
debugging of individual functions, not for always-on use in hot loops.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file scope_profiler-0.1.9.tar.gz.
File metadata
- Download URL: scope_profiler-0.1.9.tar.gz
- Upload date:
- Size: 19.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0508d96dc8d959431dc0314a502a46b520de37cffa7329d3ead9a46b441c1d2b
|
|
| MD5 |
8c22bb1ee4c4eccbaa44680f7206f66e
|
|
| BLAKE2b-256 |
6f4a7007ecb3cb111cb07a6a5af46188b417fbb05c587ba28678373d77069e2a
|
Provenance
The following attestation bundles were made for scope_profiler-0.1.9.tar.gz:
Publisher:
publish.yml on max-models/scope-profiler
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scope_profiler-0.1.9.tar.gz -
Subject digest:
0508d96dc8d959431dc0314a502a46b520de37cffa7329d3ead9a46b441c1d2b - Sigstore transparency entry: 1166261444
- Sigstore integration time:
-
Permalink:
max-models/scope-profiler@9ab7deab4624ff08e9b429890b56be2f3fcbf074 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/max-models
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9ab7deab4624ff08e9b429890b56be2f3fcbf074 -
Trigger Event:
push
-
Statement type:
File details
Details for the file scope_profiler-0.1.9-py3-none-any.whl.
File metadata
- Download URL: scope_profiler-0.1.9-py3-none-any.whl
- Upload date:
- Size: 23.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f95a8afedc392e01120cb3e08b6417c08aeba00051ce86e3eba5489256a4e6c
|
|
| MD5 |
d10894ee168500271ac82181769290e9
|
|
| BLAKE2b-256 |
e34f064241b296a5d371c715c9c2df9463d9469c4d3173c2f79c39ca1cb45d89
|
Provenance
The following attestation bundles were made for scope_profiler-0.1.9-py3-none-any.whl:
Publisher:
publish.yml on max-models/scope-profiler
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scope_profiler-0.1.9-py3-none-any.whl -
Subject digest:
1f95a8afedc392e01120cb3e08b6417c08aeba00051ce86e3eba5489256a4e6c - Sigstore transparency entry: 1166261490
- Sigstore integration time:
-
Permalink:
max-models/scope-profiler@9ab7deab4624ff08e9b429890b56be2f3fcbf074 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/max-models
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9ab7deab4624ff08e9b429890b56be2f3fcbf074 -
Trigger Event:
push
-
Statement type: