-
- Notifications
You must be signed in to change notification settings - Fork 32.3k
gh-135953: Implement sampling tool under profile.sample #135998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
0828aa3
to 57e3152
Compare This allows adding a new 'sample' submodule and enables invoking the sampling profiler through 'python -m profile.sample', while retaining backwards compatibility when using 'profile'.
Implement a statistical sampling profiler that can profile external Python processes by PID. Uses the _remote_debugging module and converts the results to pstats-compatible format for analysis.
This variant overrides how column headers are printed to avoid conflating call counts with sample counts. The SampledStats results are stored in the exact same format as Stats, but since the results don't represent call counts but sample counts, the column headers are different to account for this. This ensure that using the pstats browser instantiates the right object to handle the correct columns, add a factory function which can instantiate the correct class. As the Stats class can only handle either a filename or an object which provides the 'stats' attribute in a pre-parsed format, this provides a StatsLoaderShim to avoid marshalling the data twice (once to check the marker and once in the Stats module if we were to pass the file name).
Implements collapsed stack trace format output for the sampling profiler. This format represents complete call stacks as semicolon- delimited strings with sample counts, making it compatible with external flamegraph generation tools like flamegraph.pl. The format uses filename:function:line notation and stores call trees during sampling for efficient post-processing into the collapsed format.
a019e6a
to a0be753
Compare a0be753
to aeca768
Compare Lib/profile/sample.py Outdated
@@ -47,8 +49,14 @@ def sample(self, collector, duration_sec=10): | |||
try: | |||
stack_frames = self.unwinder.get_stack_trace() | |||
collector.collect(stack_frames) | |||
except (RuntimeError, UnicodeDecodeError, OSError): |
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.
This is wrong: the profiler can and will fail naturally with OSError
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.
I had to modify the windows part of remote debugging in dbe2c0a to not raise a generic OSError
so we can catch it properly
🤖 New build scheduled with the buildbot fleet by @pablogsal for commit 260d934 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F135998%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
@lkollar seems this fails on the buildbot with some weird errors:
I think we are missing the subdir in Line 2514 in 61dd9fd
|
Seems we are not protecting also against FreeBSD: https://buildbot.python.org/#/builders/1228/builds/718/steps/6/logs/stdio We need to:
|
🤖 New build scheduled with the buildbot fleet by @pablogsal for commit a33d166 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F135998%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
🤖 New build scheduled with the buildbot fleet by @pablogsal for commit 0235127 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F135998%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
🤖 New build scheduled with the buildbot fleet by @pablogsal for commit 90260a6 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F135998%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
🤖 New build scheduled with the buildbot fleet by @pablogsal for commit 5683b76 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F135998%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
No description provided.