◐ Shell
clean mode source ↗

gh-140677: Add heatmap output format to sampling profiler by ThierryMT · Pull Request #140678 · python/cpython

@ThierryMT

Add --heatmap option to the sampling profiler that generates an HTML
visualization showing line-by-line sample intensity with color coding.

The heatmap shows the actual source code with lines colored from blue
(few samples) to red (many samples), making it easy to identify hot
loops, expensive operations, and unexpected bottlenecks within functions.

This complements flamegraphs by providing line-level granularity that
flamegraphs don't show. While flamegraphs show which functions are hot
and their call relationships, heatmaps show which specific lines within
those functions are the bottlenecks.

Features:
- Color-coded source code (blue to red gradient)
- Line numbers and sample counts
- Collapsible file sections
- Dark theme matching modern editors
- Standalone HTML output
- Log-scale color normalization

Usage:
  python -m profiling.sampling --heatmap script.py
  python -m profiling.sampling --heatmap -o results.html -p 1234

Fixes pythongh-140677