scope_profiler.profile_config
Configuration for profiling managers.
Attributes
| Name | Description |
|---|---|
tomllib | No description. |
Classes
| Name | Description |
|---|---|
GPUOptions | GPU timing and NVTX settings, as a group. |
HDF5Options | HDF5 storage settings, as a group. |
MemrayOptions | Memray capture settings, as a group. |
ProfilingConfig | Configuration for one profiling manager. |
ProfilingOptions | A bag of :meth:ProfileManager.setup settings, to reuse or pass around. |
SetupOptions | The keyword names :meth:ProfileManager.setup accepts, for typing. |
Functions
| Name | Description |
|---|---|
load_profiling_config | Load the [profiling] table from a TOML settings file. |
tomllibattributemodule attribute#
tomllib = _tomllibGPUOptionsclassdataclass#
class GPUOptions(timing: bool | None = None, backend: Any = None, nvtx: bool | None = None, sync_on_exit: bool | None = None)Bases: _OptionGroup
GPU timing and NVTX settings, as a group.
In a TOML config file this is the [profiling.gpu] table.
Attributes
timing : bool or None
Record CUDA-event elapsed device time per region
(use_gpu_timing).
backend : str, object, or None
CUDA-event backend (gpu_timing_backend): "auto", "torch",
"cupy", or an object implementing record_event() and
elapsed_time_ns(start_event, end_event).
sync_on_exit : bool or None
Synchronize the device at region exit (gpu_sync_on_exit).
Requires timing and removes CPU/GPU overlap; disabled by default.
nvtx : bool or None
Emit NVTX ranges for NVIDIA Nsight tools (use_nvtx).
backendattributeclass attributeinstance attribute#
backend: Any = Nonenvtxattributeclass attributeinstance attribute#
nvtx: bool | None = Nonesync_on_exitattributeclass attributeinstance attribute#
sync_on_exit: bool | None = Nonetimingattributeclass attributeinstance attribute#
timing: bool | None = NoneInherited from scope_profiler.profile_config._OptionGroup
to_kwargsmethod#
scope_profiler.profile_config._OptionGroupView sourcedef to_kwargs() -> dictThis group’s explicitly-set fields, under their flat names.
HDF5Optionsclassdataclass#
class HDF5Options(compression: str | None = None, compression_level: int | None = None, chunk_size: int | None = None)Bases: _OptionGroup
HDF5 storage settings, as a group.
In a TOML config file this is the [profiling.hdf5] table.
Attributes
compression : str or None
Compression filter for timestamp and GPU-duration datasets
(hdf5_compression): "gzip", "lzf", "zstd", or
"auto" to compress only runs large enough to repay the write CPU.
compression_level : int or None
GZIP level 0—9 or Zstandard level 1—22
(hdf5_compression_level).
chunk_size : int or None
Maximum events per dataset chunk (hdf5_chunk_size). Enables
chunked partial reads even without compression.
chunk_sizeattributeclass attributeinstance attribute#
chunk_size: int | None = Nonecompressionattributeclass attributeinstance attribute#
compression: str | None = Nonecompression_levelattributeclass attributeinstance attribute#
compression_level: int | None = NoneInherited from scope_profiler.profile_config._OptionGroup
to_kwargsmethod#
scope_profiler.profile_config._OptionGroupView sourcedef to_kwargs() -> dictThis group’s explicitly-set fields, under their flat names.
MemrayOptionsclassdataclass#
class MemrayOptions(enabled: bool | None = None, path: str | None = None, native_traces: bool | None = None, trace_python_allocators: bool | None = None, follow_fork: bool | None = None)Bases: _OptionGroup
Memray capture settings, as a group.
ProfilingOptions(memray=MemrayOptions(enabled=True, native_traces=True))
configures the same run as ProfilingOptions(use_memray=True, memray_native_traces=True); use whichever reads better at the call
site. In a TOML config file the group is the [profiling.memray]
table.
Attributes
enabled : bool or None
Record process-wide allocations with Memray (use_memray).
path : str or None
Capture path (memory_profile_path); defaults to
<file-stem>.memray.bin.
native_traces : bool or None
Capture native stack frames (memray_native_traces).
trace_python_allocators : bool or None
Trace Python’s own allocators (memray_trace_python_allocators).
Creates much larger traces and has materially higher overhead.
follow_fork : bool or None
Keep tracking across fork() (memray_follow_fork).
enabledattributeclass attributeinstance attribute#
enabled: bool | None = Nonefollow_forkattributeclass attributeinstance attribute#
follow_fork: bool | None = Nonenative_tracesattributeclass attributeinstance attribute#
native_traces: bool | None = Nonepathattributeclass attributeinstance attribute#
path: str | None = Nonetrace_python_allocatorsattributeclass attributeinstance attribute#
trace_python_allocators: bool | None = NoneInherited from scope_profiler.profile_config._OptionGroup
to_kwargsmethod#
scope_profiler.profile_config._OptionGroupView sourcedef to_kwargs() -> dictThis group’s explicitly-set fields, under their flat names.
ProfilingConfigclass#
class ProfilingConfig(file_path: str = 'profiling_data.h5', label: str | None = None, use_likwid: bool = False, perf_events: list[str] | tuple[str, ...] | str | None = None, use_line_profiler: bool = False, use_memray: bool = False, memory_profile_path: str | None = None, memray_native_traces: bool = False, memray_trace_python_allocators: bool = False, memray_follow_fork: bool = False, deactivate_profiling: bool = False, use_nvtx: bool = False, use_gpu_timing: bool = False, gpu_timing_backend='auto', deactivate_file_output: bool = False, recursive_profile: bool = False, aggregation_mode: bool = False, profile_mpi_calls: bool = False, track_threads: bool = False, track_async: bool = False, capture_region_source: bool = False, metadata_detail: str = 'minimal', buffer_limit: int = 1024, output_mode: str = 'auto', hdf5_compression: str | None = None, hdf5_compression_level: int | None = None, hdf5_chunk_size: int | None = None, gpu_sync_on_exit: bool = False, enable_tags: list[str] | tuple[str, ...] | str | None = None)Configuration for one profiling manager.
This class centralizes configuration for LIKWID performance counters,
buffer limits, and file paths. Each manager owns a separate instance, so
independently configured profiling sessions can coexist. Constructing it
is purely local: it reads the communicator for rank and size but issues no
MPI call of its own, so setup() does not have to be collective.
aggregation_modeproperty#
aggregation_mode: boolWhether regions retain aggregates instead of individual events.
buffer_limitproperty#
buffer_limit: intInitial per-region buffer capacity; buffers grow beyond it as needed.
capture_region_sourceproperty#
capture_region_source: boolReturn whether a region’s defining source is captured at creation.
commproperty#
comm: Intercomm | NoneMPI communicator or None if MPI is unavailable.
deactivate_file_outputproperty#
deactivate_file_output: boolReturn whether the run writes no HDF5 file at all.
deactivate_profilingproperty#
deactivate_profiling: boolReturn whether profiling is globally turned off.
enable_tagsproperty#
enable_tags: tuple[str, ...]Opt-in region tags this run records, or an empty tuple.
file_pathproperty#
file_path: strGlobal output file path for combined profiling data.
gpu_sync_on_exitproperty#
gpu_sync_on_exit: boolWhether GPU regions wait for the device before recording CPU end time.
gpu_timing_backendproperty#
gpu_timing_backendCUDA-event timing backend selector or backend object.
hdf5_chunk_sizeproperty#
hdf5_chunk_size: int | NoneMaximum number of events per timestamp chunk.
hdf5_compressionproperty#
hdf5_compression: str | NoneCompression filter used for timestamp datasets.
hdf5_compression_levelproperty#
hdf5_compression_level: int | NoneConfigured GZIP or Zstandard compression level.
labelproperty#
label: str | NoneShort name for this run, or None if none was given to setup().
memory_profile_pathproperty#
memory_profile_path: Path | NoneMemray capture path, or None when allocation profiling is off.
metadataproperty#
metadata: dictEnvironment metadata collected on this rank (hostname, OpenMP threads, …).
metadata_detailproperty#
metadata_detail: str"full" or "minimal": how much environment metadata is recorded.
output_modeproperty#
output_mode: strMPI HDF5 output strategy: auto, direct, or parallel.
pausedproperty#
paused: boolWhether runtime timing collection is temporarily suspended.
perf_eventsproperty#
perf_events: tuple[str, ...]Requested Linux perf event names, or an empty tuple when disabled.
profile_mpi_callsproperty#
profile_mpi_calls: boolWhether mpi4py communicator operations are profiled.
recursive_profileproperty#
recursive_profile: boolReturn whether recursive decorator profiling is enabled by default.
start_time_nsproperty#
start_time_ns: intThe run’s start time (ns, perf_counter_ns clock).
The moment the configuration was created. Persisted as metadata and used as the timeline origin when reading the results back.
track_asyncproperty#
track_async: boolWhether every call records its asyncio task or greenlet.
track_threadsproperty#
track_threads: boolWhether every call records the thread it ran on.
trackerproperty#
trackerThis run’s :class:~scope_profiler.concurrency.ConcurrencyTracker.
None unless track_threads is set, which is what keeps the default
configuration free of any thread, asyncio or greenlet hook.
use_gpu_timingproperty#
use_gpu_timing: boolReturn whether CUDA-event GPU timing is enabled.
use_likwidproperty#
use_likwid: boolReturn whether LIKWID profiling is enabled.
use_line_profilerproperty#
use_line_profiler: boolReturn whether line_profiler profiling is enabled.
use_memrayproperty#
use_memray: boolReturn whether Memray allocation profiling is enabled.
use_nvtxproperty#
use_nvtx: boolReturn whether NVTX annotations are enabled.
collect_likwid_resultsmethod#
def collect_likwid_results(region_names) -> listClose the LIKWID markers and return the run’s counter results.
Tries three sources, richest first, so a host where LIKWID cannot do the fancy parts still ends up with real numbers in the HDF5 file:
- the perfmon read-back, run in a subprocess because it can crash the interpreter outright on hosts that cannot really count;
- LIKWID’s marker file, parsed directly --- real values, but no event names or derived metrics;
- a marker-API snapshot taken before the markers were closed, for when there is no marker file at all.
See :mod:scope_profiler.likwid_data for why the first one is fenced
off.
Parameters
region_names : iterable of str Region names to snapshot via the marker API.
Returns
list of scope_profiler.likwid_data.LikwidRegionResult
Empty when LIKWID is disabled, the process was not started under
likwid-perfctr -m / likwid-mpirun -marker, or the markers
were already collected.
Notes
A process can only do this once. Closing the markers tears the marker
API down, and querying it afterwards crashes the interpreter rather
than raising, so a second finalize() returns nothing instead of
reading again. The counters of the whole process therefore end up in
the file written by the first finalize().
likwid_environmentmethod#
def likwid_environment() -> dictReturn the LIKWID_* environment variables of this process.
pylikwid_markerclosemethod#
def pylikwid_markerclose()Close LIKWID markers to finalize measurement regions.
Idempotent: repeated calls (a second finalize(), say) do nothing.
pylikwid_markerinitmethod#
def pylikwid_markerinit()Initialize LIKWID markers if LIKWID is enabled.
resetmethodclassmethod#
def reset()Compatibility no-op retained for callers of older releases.
Configurations are ordinary per-manager objects now, so there is no process-wide instance to reset.
stop_memory_profilingmethod#
def stop_memory_profiling() -> NoneFinish Memray’s process-wide allocation capture, if enabled.
ProfilingOptionsclassdataclass#
class ProfilingOptions(file_path: str | None = None, label: str | None = None, use_likwid: bool | None = None, perf_events: list[str] | tuple[str, ...] | str | None = None, use_line_profiler: bool | None = None, use_memray: bool | None = None, memory_profile_path: str | None = None, memray_native_traces: bool | None = None, memray_trace_python_allocators: bool | None = None, memray_follow_fork: bool | None = None, deactivate_profiling: bool | None = None, use_nvtx: bool | None = None, use_gpu_timing: bool | None = None, gpu_timing_backend: Any = None, deactivate_file_output: bool | None = None, recursive_profile: bool | None = None, aggregation_mode: bool | None = None, profile_mpi_calls: bool | None = None, track_threads: bool | None = None, track_async: bool | None = None, capture_region_source: bool | None = None, metadata_detail: str | None = None, buffer_limit: int | None = None, output_mode: str | None = None, hdf5_compression: str | None = None, hdf5_compression_level: int | None = None, hdf5_chunk_size: int | None = None, enable_tags: list[str] | tuple[str, ...] | None = None, memray: MemrayOptions | None = None, gpu: GPUOptions | None = None, hdf5: HDF5Options | None = None, gpu_sync_on_exit: bool | None = None)A bag of :meth:ProfileManager.setup settings, to reuse or pass around.
Every field mirrors a setup()/session() keyword argument and
defaults to None, meaning “unset - let setup()’s own default, or
its config_path file, decide”. Pass one to setup() or
session() instead of repeating the same handful of keyword arguments
at every call site::
options = ProfilingOptions(use_likwid=True, file_path="run.h5")ProfileManager.setup(options=options)# ... or, equivalently:with ProfileManager.session(options=options): ...An explicit keyword argument passed alongside options still wins over
the same field on options, so a shared ProfilingOptions can be
reused across runs with one-off overrides::
ProfileManager.setup(options=options, file_path="run_b.h5")Settings that share a prefix can also be given as groups —
:class:MemrayOptions, :class:GPUOptions and :class:HDF5Options —
which spell the same settings without the prefix::
options = ProfilingOptions( file_path="run.h5", hdf5=HDF5Options(compression="gzip", compression_level=4),)Setting one thing both ways raises ValueError rather than picking a
winner.
Attributes
file_path : str or None
Path to the output profiling data file (default:
"profiling_data.h5").
label : str or None
Short name for this run (default: None, i.e. the output file’s
stem). Post-processing uses it wherever a run has to be named —
chart legends, the summary heading, scope-profiler inspect, the
JSON statistics - and it is stored in the output file as the
label metadata field, so it survives into every later
post-processing step.
use_likwid : bool or None
Enable LIKWID hardware counter collection (default: False).
perf_events : sequence of str or None
Linux perf_event_open events to collect per region (default: None).
use_line_profiler : bool or None
Enable line-by-line profiling via line_profiler (default: False).
use_memray : bool or None
Record process-wide memory allocations with Memray (default: False).
deactivate_profiling : bool or None
Turn profiling off entirely (setup() default: False). Every
region becomes a no-op, so the instrumentation can stay in the code
at near-zero cost instead of being removed.
use_nvtx : bool or None
Add NVTX ranges to profiled regions for NVIDIA Nsight tools
(default: False). Requires scope-profiler[nvtx].
use_gpu_timing : bool or None
Record CUDA-event elapsed device time for each profiled region
(default: False). CPU timestamps are still recorded, so the normal
timeline remains enqueue-side timing.
gpu_sync_on_exit : bool or None
Wait for the GPU device at region exit. Requires use_gpu_timing
and removes CPU/GPU overlap; disabled by default.
gpu_timing_backend : str, object, or None
CUDA-event backend for use_gpu_timing: "auto", "torch",
"cupy", or a custom object implementing record_event() and
elapsed_time_ns(start_event, end_event) (default: "auto").
deactivate_file_output : bool or None
Write no HDF5 file at all (default: False), not even the run
metadata. Pair it with finalize(return_results=True) to analyse a
run entirely in memory.
recursive_profile : bool or None
Enable recursive profiling for all decorated functions by default
(default: False). Overridable per decorator with
@ProfileManager.profile(..., recursive=...).
aggregation_mode : bool or None
Record only count, inclusive total, minimum, maximum, and exclusive
total per region (default: False). Timeline events are unavailable
in this mode; it cannot be combined with line, GPU, NVTX, or LIKWID
profiling.
profile_mpi_calls : bool or None
Profile mpi4py operations made through predefined or derived
communicators (default: False). mpi4py remains lazily imported.
track_threads : bool or None
Record which thread each call ran on, and describe every thread the
run touched (default: False). Required for correct results from
concurrently used regions; see
:class:~scope_profiler.region_profiler.ThreadedProfileRegion.
track_async : bool or None
Also record which asyncio task or greenlet each call ran in, and how
much of the call was spent awaiting (default: False). Implies
track_threads.
capture_region_source : bool or None
Record where each region is defined - the with block or the
decorated function - once per distinct source file, the first time
any of its regions is created (default: False). See
:attr:~scope_profiler.region.Region.source_text. Off by default:
the cost tracks that file’s total size (one ast.parse + tree
walk), so it stays under a millisecond for a typical file but can
reach tenths of a second per rank for a single file with thousands
of lines, paid independently by every rank.
metadata_detail : {“minimal”, “full”} or None
How much of the run’s environment is recorded (default:
"minimal"). "minimal" stores versions, platform, CPU model
and thread/rank counts, and each region’s and line profile’s source
file relative to the working directory (or by name alone, outside
it). "full" adds the user name, host name, working directory,
loaded modules, environment variables such as PATH and
VIRTUAL_ENV, SLURM_* variables and absolute source paths;
opt into it for runs that stay on the machine they were recorded on.
buffer_limit : int or None
Initial number of profiling events preallocated per region (default:
1024). Buffers grow on demand, so this is a starting size rather
than a limit; raise it for very hot regions to avoid repeated
reallocation.
output_mode : str or None
MPI file writer: "auto", "direct", or "parallel"
(default: "auto"). auto prefers MPI-enabled h5py when
compatible with the active instrumentation and otherwise lets ranks
append directly to one serial-HDF5 file in token order.
hdf5_compression : str or None
Compression filter for timestamp and GPU-duration datasets:
None, "auto", "gzip", "lzf", or "zstd"
(default: None). "auto" compresses at publication time, and only
when the run is large enough for the saving to repay the write CPU.
hdf5_compression_level : int or None
GZIP level 0—9 or Zstandard level 1—22 (default: None).
hdf5_chunk_size : int or None
Maximum events per dataset chunk (default: None). Enables chunked
partial reads even without compression.
enable_tags : sequence of str or None
Opt-in region tags to record (default: None). Regions carrying a tag
registered with :meth:ProfileManager.register_opt_in_tag - typically
a library’s own instrumentation - stay disabled unless one of their
opt-in tags is listed here, in region_tags, or in the
comma-separated SCOPE_PROFILER_ENABLE_TAGS environment variable.
"*" enables every opt-in tag.
memray : MemrayOptions or None
The use_memray/memory_profile_path/memray_* settings as
one group.
gpu : GPUOptions or None
The use_gpu_timing/gpu_timing_backend/use_nvtx settings
as one group.
hdf5 : HDF5Options or None
The hdf5_* settings as one group.
aggregation_modeattributeclass attributeinstance attribute#
aggregation_mode: bool | None = Nonebuffer_limitattributeclass attributeinstance attribute#
buffer_limit: int | None = Nonecapture_region_sourceattributeclass attributeinstance attribute#
capture_region_source: bool | None = Nonedeactivate_file_outputattributeclass attributeinstance attribute#
deactivate_file_output: bool | None = Nonedeactivate_profilingattributeclass attributeinstance attribute#
deactivate_profiling: bool | None = Noneenable_tagsattributeclass attributeinstance attribute#
enable_tags: list[str] | tuple[str, ...] | None = Nonefile_pathattributeclass attributeinstance attribute#
file_path: str | None = Nonegpuattributeclass attributeinstance attribute#
gpu: GPUOptions | None = Nonegpu_sync_on_exitattributeclass attributeinstance attribute#
gpu_sync_on_exit: bool | None = Nonegpu_timing_backendattributeclass attributeinstance attribute#
gpu_timing_backend: Any = Nonehdf5attributeclass attributeinstance attribute#
hdf5: HDF5Options | None = Nonehdf5_chunk_sizeattributeclass attributeinstance attribute#
hdf5_chunk_size: int | None = Nonehdf5_compressionattributeclass attributeinstance attribute#
hdf5_compression: str | None = Nonehdf5_compression_levelattributeclass attributeinstance attribute#
hdf5_compression_level: int | None = Nonelabelattributeclass attributeinstance attribute#
label: str | None = Nonememory_profile_pathattributeclass attributeinstance attribute#
memory_profile_path: str | None = Nonememrayattributeclass attributeinstance attribute#
memray: MemrayOptions | None = Nonememray_follow_forkattributeclass attributeinstance attribute#
memray_follow_fork: bool | None = Nonememray_native_tracesattributeclass attributeinstance attribute#
memray_native_traces: bool | None = Nonememray_trace_python_allocatorsattributeclass attributeinstance attribute#
memray_trace_python_allocators: bool | None = Nonemetadata_detailattributeclass attributeinstance attribute#
metadata_detail: str | None = Noneoutput_modeattributeclass attributeinstance attribute#
output_mode: str | None = Noneperf_eventsattributeclass attributeinstance attribute#
perf_events: list[str] | tuple[str, ...] | str | None = Noneprofile_mpi_callsattributeclass attributeinstance attribute#
profile_mpi_calls: bool | None = Nonerecursive_profileattributeclass attributeinstance attribute#
recursive_profile: bool | None = Nonetrack_asyncattributeclass attributeinstance attribute#
track_async: bool | None = Nonetrack_threadsattributeclass attributeinstance attribute#
track_threads: bool | None = Noneuse_gpu_timingattributeclass attributeinstance attribute#
use_gpu_timing: bool | None = Noneuse_likwidattributeclass attributeinstance attribute#
use_likwid: bool | None = Noneuse_line_profilerattributeclass attributeinstance attribute#
use_line_profiler: bool | None = Noneuse_memrayattributeclass attributeinstance attribute#
use_memray: bool | None = Noneuse_nvtxattributeclass attributeinstance attribute#
use_nvtx: bool | None = NoneSetupOptionsclass#
class SetupOptions(TypedDict)Bases: TypedDict
The keyword names :meth:ProfileManager.setup accepts, for typing.
setup() and session() take their settings as **overrides
rather than restating 28 keyword parameters, so this is what gives type
checkers and editors the names and types of those keywords. It mirrors
:class:ProfilingOptions exactly - test_setup_options_match_fields
fails the build if the two ever drift.
aggregation_modeattributeinstance attribute#
aggregation_mode: boolbuffer_limitattributeinstance attribute#
buffer_limit: intcapture_region_sourceattributeinstance attribute#
capture_region_source: booldeactivate_file_outputattributeinstance attribute#
deactivate_file_output: booldeactivate_profilingattributeinstance attribute#
deactivate_profiling: boolenable_tagsattributeinstance attribute#
enable_tags: list[str] | tuple[str, ...]file_pathattributeinstance attribute#
file_path: strgpu_sync_on_exitattributeinstance attribute#
gpu_sync_on_exit: boolgpu_timing_backendattributeinstance attribute#
gpu_timing_backend: Anyhdf5_chunk_sizeattributeinstance attribute#
hdf5_chunk_size: inthdf5_compressionattributeinstance attribute#
hdf5_compression: strhdf5_compression_levelattributeinstance attribute#
hdf5_compression_level: intlabelattributeinstance attribute#
label: strmemory_profile_pathattributeinstance attribute#
memory_profile_path: strmemray_follow_forkattributeinstance attribute#
memray_follow_fork: boolmemray_native_tracesattributeinstance attribute#
memray_native_traces: boolmemray_trace_python_allocatorsattributeinstance attribute#
memray_trace_python_allocators: boolmetadata_detailattributeinstance attribute#
metadata_detail: stroutput_modeattributeinstance attribute#
output_mode: strperf_eventsattributeinstance attribute#
perf_events: list[str] | tuple[str, ...] | strprofile_mpi_callsattributeinstance attribute#
profile_mpi_calls: boolrecursive_profileattributeinstance attribute#
recursive_profile: booltrack_asyncattributeinstance attribute#
track_async: booltrack_threadsattributeinstance attribute#
track_threads: booluse_gpu_timingattributeinstance attribute#
use_gpu_timing: booluse_likwidattributeinstance attribute#
use_likwid: booluse_line_profilerattributeinstance attribute#
use_line_profiler: booluse_memrayattributeinstance attribute#
use_memray: booluse_nvtxattributeinstance attribute#
use_nvtx: boolload_profiling_configfunction#
def load_profiling_config(path: str | os.PathLike[str]) -> dictLoad the [profiling] table from a TOML settings file.
A top-level table is also accepted for small files. Paths in the file
retain TOML’s normal meaning and are interpreted relative to the current
working directory, just like paths passed to :meth:ProfileManager.setup.
Settings may be written flat, or grouped into the memray, gpu and
hdf5 sub-tables that mirror :class:MemrayOptions,
:class:GPUOptions and :class:HDF5Options::
[profiling]file_path = "run.h5"
[profiling.hdf5]compression = "gzip"compression_level = 4Setting the same thing both ways is an error, not a silent precedence rule.