-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-138122: Add sampling profiler visualisation to docs #142772
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
Add an interactive JS visualisation to demonstrate how the sampling profiler works. A small demo program is shown executing line by line, demonstrating how stack frames are created and destroyed and how samples are taken periodically during the process. A new Sphinx extension is used to capture and inject the trace into the JS file during documentation build to make these traces reproducible (and avoid hard coding them in the source code).
| .. only:: html | ||
|
|
||
| The following interactive visualization demonstrates how sampling profiling | ||
| works. Press **Play** to watch a Python program execute, and observe how the |
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.
See the :guilabel: role for buttons.
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 tried using this but it just wraps the element in a span and has no associated styling, so the text isn't highlighted in any way. I could style it in the local CSS but this should probably get a global style rule.
The only other place where this is used is in the logging cookbook (search for "Download ZIP") which isn't styled either. Seems like a bug to me.
Include the JS and CSS files in the Sphinx extension to make sure Sphinx properly includes these when producing all output types.
Moved function colors to a lookup map and easing definitions to a module constant so they aren't recreated on each call. Cached the background element reference in DOMStackFrame instead of querying it on every hover. Chained the regex replacements in syntax highlighting into one expression. Removed the CSS color rules for specific functions since colors are now set in JS, along with a duplicate color variable and two methods that were never called.
Add a visualisation explaining how the sampling profiler works.
CC: @pablogsal
📚 Documentation preview 📚: https://cpython-previews--142772.org.readthedocs.build/en/142772/library/profiling.sampling.html