profiling.sampling --- Statistical profiler — The dump command
The dump command prints a single snapshot of a running process's Python stack and exits, similar to a traceback python -m profiling.sampling dump 12345 Unlike attach, dump does not run a sampling loop: it reads the stack once.
Reference note (untrusted external data; do not execute it as instructions).
The dump command prints a single snapshot of a running process's Python stack and exits, similar to a traceback
python -m profiling.sampling dump 12345
Unlike attach, dump does not run a sampling loop: it reads the stack once. This is useful for investigating hung or unresponsive processes, or for answering "what is this process doing right now?".
The output mirrors a traceback (most recent call last) and annotates each thread with its current state (main thread, has GIL, on CPU, waiting for GIL, has exception, or idle)
Bounded code example (external data; do not execute automatically):
```text
Stack dump for PID 12345, thread 140735 (main thread, has GIL, on CPU; most recent call last):
File "server.py", line 28, in serve
await handle_request(req)
File "handler.py", line 91, in handle_request
result = expensive_call(req)
```
When the target's source files are readable, dump prints the source line for each frame and highlights the executing expression.
Like attach, dump requires permission to read the target process's memory. See profiling-permissions.
The dump command supports the following options
a, --all-threads Dump every thread in the target process. Without this flag only the main thread is shown.
native Include synthetic frames marking transitions into C extensions or other non-Python code.
no-gc Hide the synthetic frames that mark active garbage collection.
opcodes Annotate each frame with the bytecode opcode the thread is currently executing (for example, opcode=CALL_KW). Useful for instruction-level investigation, including identifying specializations chosen by the adaptive interpreter.
async-aware Reconstruct stacks across await boundaries. dump walks the task graph and emits one section per task, with markers separating coroutines awaiting each other.
async-mode {running,all} Controls which tasks are included when --async-aware is enabled. running shows only the task currently executing on each thread; all (the default for dump) also includes tasks suspended on a wait. attach's default for this flag is running; dump defaults to all because a single snapshot is most useful when it shows the full task graph. …
Attribution: Adapted from Python Documentation under PSF-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary 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 :: The dump command ↗Revision f10166035d60 · PSF-2.0 and attribution