GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-138122: Add exception profiling mode to the sampling profiler by pablogsal · Pull Request #142561 · python/cpython

Conversation

@pablogsal

@pablogsal pablogsal commented Dec 11, 2025 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

  • Issue: Implement PEP 799 – A dedicated profiling package for organizing Python profiling tools #138122

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot mentioned this pull request Dec 11, 2025
Implement PEP 799 – A dedicated profiling package for organizing Python profiling tools #138122
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Dec 11, 2025
@pablogsal
pablogsal force-pushed the exceptions branch 3 times, most recently from 2746f4a to d756ae5 Compare December 11, 2025 04:17
@pablogsal
pablogsal requested review from StanFromIreland and savannahostrowski December 11, 2025 04:19
@pablogsal
pythongh-138122: Add exception profiling mode to the sampling profiler
c316046
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 force-pushed the exceptions branch from d756ae5 to c316046 Compare December 11, 2025 04:19
@pablogsal
Add what's new entry
011f3f0
@pablogsal
pablogsal requested a review from AA-Turner as a code owner December 11, 2025 04:25
savannahostrowski
savannahostrowski requested changes Dec 11, 2025
View reviewed changes
Comment thread Lib/profiling/sampling/cli.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/profiling/sampling/cli.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting core review label Dec 11, 2025
@bedevere-app

bedevere-app Bot commented Dec 11, 2025

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added the awaiting changes label Dec 11, 2025
savannahostrowski
savannahostrowski approved these changes Dec 11, 2025
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting changes labels Dec 11, 2025
StanFromIreland
StanFromIreland reviewed Dec 11, 2025
View reviewed changes
Comment thread Doc/library/profiling.sampling.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal
remove impl details
364726b
StanFromIreland
StanFromIreland approved these changes Dec 11, 2025
View reviewed changes

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@pablogsal
pablogsal merged commit 6a0135a into python:main Dec 11, 2025
46 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal
pablogsal deleted the exceptions branch December 11, 2025 20:46
@bedevere-app bedevere-app Bot removed the awaiting merge label Dec 11, 2025
@pablogsal

pablogsal commented Dec 11, 2025

Copy link
Copy Markdown
Member Author

Thanks for the reviews @StanFromIreland and @savannahostrowski !

StanFromIreland and savannahostrowski reacted with heart emoji savannahostrowski reacted with rocket emoji
All reactions
  • ❤️ 2 reactions
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

fatelei pushed a commit to fatelei/cpython that referenced this pull request Dec 12, 2025
@pablogsal @fatelei
pythongh-138122: Add exception profiling mode to the sampling profiler (
92f1114
python#142561)
@GrahamDumpleton GrahamDumpleton mentioned this pull request Sep 30, 2026
profiling.sampling: exception mode misses except blocks running in generators and coroutines #158539
Closed
korniltsev-grafanista
korniltsev-grafanista reviewed Oct 12, 2026
View reviewed changes
Comment thread Include/internal/pycore_debug_offsets.h
} thread_state;

// Exception stack item offset
struct {

@korniltsev-grafanista korniltsev-grafanista Oct 12, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Was there a reason to keep this struct anonymous? This trips cgo -godefs which is likely cgos problem, but still.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@savannahostrowski savannahostrowski savannahostrowski approved these changes
@StanFromIreland StanFromIreland StanFromIreland approved these changes
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner
+1 more reviewer
@korniltsev-grafanista korniltsev-grafanista korniltsev-grafanista left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@pablogsal @savannahostrowski @StanFromIreland @korniltsev-grafanista
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.