Skip to content

tools: Add flamegraph subcommand#52

Draft
djolertrk wants to merge 1 commit intonextfrom
feature/flamegraph
Draft

tools: Add flamegraph subcommand#52
djolertrk wants to merge 1 commit intonextfrom
feature/flamegraph

Conversation

@djolertrk
Copy link
Copy Markdown
Collaborator

Implemented miden-debug flamegraph as a non-interactive execution mode. It drives DebugExecutor to completion one VM cycle at a time, samples callstack.frames() on each cycle, converts frames to semicolon-separated folded stack paths, aggregates cycle counts per stack, and renders the result as an SVG flame graph with inferno or as folded-stack text for external tools

It uses inferno crate as a new dependency.

@djolertrk djolertrk requested review from bitwalker and greenhat April 13, 2026 09:36
@djolertrk
Copy link
Copy Markdown
Collaborator Author

Usage:

midenc \
    --emit masm,masp \
    --exe \
    --debug full \
    --entrypoint example_miden_project::entrypoint \
    target/wasm32-unknown-unknown/debug/example_miden_project.wasm


miden-debug flamegraph \
    --sysroot /path/to/compiler/target/debug/build/miden-core-lib-310dec8ab72220bd/out/assets \
    -o flamegraph.svg \
    example_miden_project.masp \
    -- 10
Executed 59920 cycles across 2 unique stack paths
Wrote flame graph to flamegraph.svg
Screenshot 2026-04-13 at 11 29 30

@djolertrk djolertrk mentioned this pull request Apr 13, 2026
@bitwalker
Copy link
Copy Markdown
Collaborator

Nice! It'd be useful, if you're able, to see an example like the one you show here, but generated from a run against one of the more involved example projects from the compiler repo, to get a sense of what a typical flamegraph would look like, just in case it raises any obvious issues in the process. That may require the transaction debugging stuff though, so we may have to wait until some of those other in-flight PRs and stuff land.

@greenhat
Copy link
Copy Markdown
Contributor

Nice job!
Most of the code to be profiled will be the rollup code executed in transactions. It'd be great to find a way to expose the flamegraph generation API through the tx API. I think the most likely use case among the developers would be to enable flamegraph generation in their tests that are using the MockChain API.

@djolertrk
Copy link
Copy Markdown
Collaborator Author

Nice job! Most of the code to be profiled will be the rollup code executed in transactions. It'd be great to find a way to expose the flamegraph generation API through the tx API. I think the most likely use case among the developers would be to enable flamegraph generation in their tests that are using the MockChain API.

Yep. It does make sense.

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.

3 participants