Skip to content

feat: add --cpu-prof-flamegraph to generate interactive SVG flamegraphs#32572

Open
bartlomieju wants to merge 18 commits intomainfrom
cpu-prof-flamegraph
Open

feat: add --cpu-prof-flamegraph to generate interactive SVG flamegraphs#32572
bartlomieju wants to merge 18 commits intomainfrom
cpu-prof-flamegraph

Conversation

@bartlomieju
Copy link
Member

@bartlomieju bartlomieju commented Mar 8, 2026

Summary

Builds on top of #31909 to add interactive SVG flamegraph generation for CPU profiles, plus improvements to the existing --cpu-prof functionality.

New: --cpu-prof-flamegraph flag

Generates a self-contained, interactive SVG flamegraph alongside the .cpuprofile file. No external dependencies required — the SVG is generated directly from V8 CPU profile data.

deno run --cpu-prof --cpu-prof-flamegraph script.ts
# or
deno eval --cpu-prof --cpu-prof-flamegraph "/* code */"

Flamegraph features:

  • Click any frame to zoom into that subtree
  • "Reset Zoom" button to restore full view
  • Ctrl+F / "Search" button for regex-based function search with magenta highlighting and matched percentage
  • "Invert" checkbox to flip into an icicle graph (root at top)
  • Hover any frame to see function name and sample count in the status bar
  • Responsive — fills the browser viewport, adapts on resize
  • Warm color gradient matching cargo-flamegraph / inferno style

Other improvements

  • deno eval support: All --cpu-prof-* flags now work with deno eval
  • Fixed total time calculation: The markdown report now properly computes inclusive time (self + all descendants) using bottom-up tree aggregation, instead of showing only self time
Screenshot 2026-03-08 at 14 47 19

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

littledivy and others added 12 commits January 21, 2026 23:17
Signed-off-by: Divy <dj.srivastava23@gmail.com>
…port

- Add --cpu-prof, --cpu-prof-dir, --cpu-prof-name, --cpu-prof-interval,
  and --cpu-prof-md flags to `deno eval`
- Fix call tree total time calculation: properly walk the tree to compute
  inclusive time (self + all descendants) instead of using self time only
- Fix Hot Functions and Function Details sections to show accurate
  total time percentages

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds a new `--cpu-prof-flamegraph` flag that generates a self-contained
SVG flamegraph alongside the .cpuprofile file. No external dependencies
required — the SVG is generated directly from the V8 CPU profile data.

The flamegraph shows:
- Call stacks as nested rectangles (root at bottom, leaves at top)
- Width proportional to sample count (time spent)
- Warm color palette with hover tooltips showing sample counts
- Function names with source locations

Supported on both `deno run` and `deno eval`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rewrite flamegraph generation to match the inferno/cargo-flamegraph
style with full interactivity:
- Click any frame to zoom into that subtree
- "Reset Zoom" button to restore full view
- Ctrl+F / Search button for regex-based function search with
  magenta highlighting and matched percentage display
- Hover any frame to see function details in the status bar
- Fluid/responsive width that adapts to browser window
- Percentage-based coordinates with fg:x/fg:w sample-count
  attributes for precise zoom calculations
- Gradient background (grey to warm yellow)
- Verdana font, matching inferno's visual style

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use min-height:100vh and dynamic JS resizing to ensure the flamegraph
fills the entire browser window, with frames pushed to the bottom.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds an interactive "Invert" checkbox that flips the flamegraph into an
icicle graph (root at top). Toggling back restores the original layout.
Zoom works correctly in both orientations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bartlomieju bartlomieju changed the title Cpu prof flamegraph feat: add --cpu-prof-flamegraph to generate interactive SVG flamegraphs Mar 8, 2026
Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, what does the flamegraph look like?

Comment on lines +935 to +936
// Interactive JavaScript for the flamegraph SVG, modeled after inferno/flamegraph.
// Supports: click-to-zoom, reset zoom, Ctrl+F search with highlight, hover details.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, should we move this to a file and include_str!?

@bartlomieju
Copy link
Member Author

@littledivy I update the description with example screenshot of SVG flamegraph. Let's land #31909 first then I'll rebase this one.

bartlomieju and others added 6 commits March 9, 2026 17:13
Resolve conflicts between main's CPU profiling refactor (CpuProfFlags,
centralized cpu_prof_parse, u32 interval, cpu_prof_filename) and our
flamegraph additions. Adopts main's structural improvements while
preserving flamegraph support and total_time tracking in markdown reports.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Extract flamegraph JS to `cpu_profiler/flamegraph.js`, loaded via
  `include_str!`
- Move cpuprofile/markdown generation to `cpu_profiler/cpuprof.rs`
- Move flamegraph SVG generation to `cpu_profiler/flamegraph.rs`
- Keep config, state, and profiler orchestration in `cpu_profiler/mod.rs`

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants