Skip to content

Conversation

@pablogsal
Copy link
Member

@pablogsalpablogsal commented Dec 11, 2025

When profiling code it's often valuable to understand what
code paths are executing while exceptions are being handled. The new
--mode=exception option filters samples to only include threads that
have an active exception, making it easy to identify hot spots in error
handling code without noise from normal execution paths.

This works by checking both the thread's current_exception (for
exceptions being raised/propagated) and exc_info (for exceptions being
handled in except blocks). The feature integrates with the existing
profiler infrastructure including the live TUI, flamegraph output, and
gecko format for Firefox Profiler visualization.


📚 Documentation preview 📚: https://cpython-previews--142561.org.readthedocs.build/

When profiling code it's often valuable to understand what code paths are executing while exceptions are being handled. The new --mode=exception option filters samples to only include threads that have an active exception, making it easy to identify hot spots in error handling code without noise from normal execution paths. This works by checking both the thread's current_exception (for exceptions being raised/propagated) and exc_info (for exceptions being handled in except blocks). The feature integrates with the existing profiler infrastructure including the live TUI, flamegraph output, and gecko format for Firefox Profiler visualization.
@bedevere-app
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Copy link
Member

@StanFromIrelandStanFromIreland left a comment

Choose a reason for hiding this comment

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

LGTM

@pablogsalpablogsal merged commit 6a0135a into python:mainDec 11, 2025
46 checks passed
@pablogsalpablogsal deleted the exceptions branch December 11, 2025 20:46
@pablogsal
Copy link
MemberAuthor

Thanks for the reviews @StanFromIreland and @savannahostrowski !

fatelei pushed a commit to fatelei/cpython that referenced this pull request Dec 12, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@pablogsal@savannahostrowski@StanFromIreland