Configuration#
All profiling behaviour is controlled through ProfileManager.setup().
This must be called once before any regions are created. The
configuration is global: every call to profile() or profile_region()
— even from other modules — uses the active settings.
ProfileManager.setup() parameters#
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Master switch. When |
|
|
|
Wrap regions with LIKWID marker API calls for hardware counter collection. Requires |
|
|
|
Enable line-by-line profiling via |
|
|
|
Record nanosecond start/end timestamps for every call. |
|
|
|
Periodically flush timing buffers to per-rank HDF5 files. |
|
|
|
Number of events buffered in memory before an automatic flush. |
|
|
|
Output path for the merged HDF5 file written by |
Profiling modes#
The combination of flags determines which internal region class is used. This strategy dispatch avoids runtime conditionals in the hot path:
|
|
|
Region class |
What it records |
|---|---|---|---|---|
– |
– |
– |
|
Nothing (profiling off) |
no |
no |
– |
|
Call count only |
yes |
no |
no |
|
Timestamps (in-memory) |
yes |
no |
yes |
|
Timestamps + HDF5 |
no |
yes |
– |
|
LIKWID markers only |
yes |
yes |
no |
|
Timestamps + LIKWID (in-memory) |
yes |
yes |
yes |
|
Timestamps + LIKWID + HDF5 |
– |
– |
– |
|
Timestamps + HDF5 + line-by-line |
When use_line_profiler=True it takes precedence over the other
combinations.
Toggling profiling at runtime#
Because the configuration is a singleton, you can leave all instrumentation in place and simply flip the master switch:
import os
from scope_profiler import ProfileManager
ProfileManager.setup(
profiling_activated=os.environ.get("ENABLE_PROFILING", "0") == "1",
)
When profiling_activated=False, every region is a DisabledProfileRegion
whose __enter__ / __exit__ / wrap are trivial no-ops, adding only
the cost of a Python function call (~45 ns).
Re-configuring#
Calling setup() again resets all existing regions and applies the new
configuration:
ProfileManager.setup(time_trace=True)
# ... profile some code ...
ProfileManager.finalize()
# Start a fresh session with different settings
ProfileManager.setup(time_trace=False)
# ...
ProfileManager.finalize()