Skip to content

Conversation

@pablogsal
Copy link
Member

@pablogsal pablogsal 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.
@pablogsal pablogsal requested a review from AA-Turner as a code owner December 11, 2025 04:25
@bedevere-app
Copy link

bedevere-app bot commented Dec 11, 2025

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

Copy link
Member

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

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

LGTM

@pablogsal pablogsal merged commit 6a0135a into python:main Dec 11, 2025
46 checks passed
@pablogsal pablogsal deleted the exceptions branch December 11, 2025 20:46
@pablogsal
Copy link
Member Author

Thanks for the reviews @StanFromIreland and @savannahostrowski !

Sign up for free to 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