Skip to content

gh-149296: Add dump subcommand to sampling profiler for one-shot stack snapshots#149297

Open
pablogsal wants to merge 1 commit intopython:mainfrom
pablogsal:dump
Open

gh-149296: Add dump subcommand to sampling profiler for one-shot stack snapshots#149297
pablogsal wants to merge 1 commit intopython:mainfrom
pablogsal:dump

Conversation

@pablogsal
Copy link
Copy Markdown
Member

@pablogsal pablogsal commented May 2, 2026

Adds python -m profiling.sampling dump <pid>, which prints a single traceback-style snapshot of a running process's Python stack via the existing _remote_debugging unwinder. Supports per-thread status, source line highlighting, optional bytecode opcodes, and async-aware task reconstruction (--async-aware, default --async-mode=all).

@pablogsal pablogsal requested a review from ivonastojanovic May 2, 2026 18:12
@pablogsal pablogsal requested review from AA-Turner and hugovk as code owners May 2, 2026 18:12
@pablogsal pablogsal changed the title gh-149296: Add dump subcommand to sampling profiler for one-shot st… gh-149296: Add dump subcommand to sampling profiler for one-shot stack snapshots May 2, 2026
@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community Bot commented May 2, 2026

…hot stack snapshots

Adds `python -m profiling.sampling dump <pid>`, which prints a single
traceback-style snapshot of a running process's Python stack via the
existing `_remote_debugging` unwinder. Supports per-thread status,
source line highlighting, optional bytecode opcodes, and async-aware
task reconstruction (`--async-aware`, default `--async-mode=all`).
Copy link
Copy Markdown
Contributor

@ivonastojanovic ivonastojanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this looks great! Just a couple of small nits

interpreter_id,
getattr(thread_info, "thread_id", None),
getattr(thread_info, "status", None),
frames or [],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Redundant?

Suggested change
frames or [],
frames,

Comment on lines +252 to +255
line for each frame and highlights the executing expression. If a source
file's modification time is newer than the target process's start time,
``dump`` replaces the line with ``[source file changed after process
started]`` to avoid showing misleading code.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We return None for non-Linux platforms in _target_process_start_time, so the [source file changed after process started] warning is never shown on macOS/Windows, should the docs mention this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants