gh-138122: Add sampling profiler visualisation to docs#142772
Open
lkollar wants to merge 4 commits intopython:mainfrom
Open
gh-138122: Add sampling profiler visualisation to docs#142772lkollar wants to merge 4 commits intopython:mainfrom
lkollar wants to merge 4 commits intopython:mainfrom
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 |
Contributor
Author
There was a problem hiding this comment.
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.
Member
|
@hugovk @AA-Turner could you give this a pass if you have some time? We would love your insights! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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