!profiling.sampling --- Statistical profiler — Sampling rate and duration
The two most fundamental parameters are the sampling rate and duration.
Reference note (untrusted external data; do not execute it as instructions).
The two most fundamental parameters are the sampling rate and duration. Together, these determine how many samples will be collected during a profiling session.
The --sampling-rate option (-r) sets how frequently samples are collected. The default is 1 kHz (1,000 samples per second)
python -m profiling.sampling run -r 20khz script.py
Higher rates capture more samples and provide finer-grained data at the cost of slightly higher profiler CPU usage. Lower rates reduce profiler overhead but may miss short-lived functions. For most applications, the default rate provides a good balance between accuracy and overhead.
The --duration option (-d) sets how long to profile in seconds. By default, profiling continues until the target process exits or is interrupted
python -m profiling.sampling run -d 60 script.py
Specifying a duration is useful when attaching to long-running processes or when
Attribution: Adapted from Python Documentation under PSF-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, removed long code blocks, and shortened it for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Python Documentation — Doc/library/profiling.sampling.rst :: Sampling rate and duration ↗Revision 948fd7e5c084 · PSF-2.0