Skip to content

Conversation

@lkollar
Copy link
Contributor

@lkollar lkollar commented Dec 15, 2025

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
Copy link
Member

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.

Copy link
Contributor Author

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants