fitzgen requested wasmtime-core-reviewers for a review on PR #13077.
fitzgen requested pchickey for a review on PR #13077.
fitzgen opened PR #13077 from fitzgen:wasmtime-hot-blocks to bytecodealliance:main:
This commit adds a new
wasmtime hot-blockssubcommand that profiles Wasm
execution usingperfand identifies the hottest basic blocks in the compiled
Wasm code.Example output:
$ cargo run -- hot-blocks -F 999 -p 100 tests/all/cli_tests/fib.wat `fib` :: block 0x16 :: 81.62% total samples [Samples] [Assembly] [CLIF] [Wasm] 14.07% add esi, 1 - - 21.29% lea ecx, [rax + rdi] v14 = iadd.i32 v13, v12 i32.add 13.29% mov rdi, rax " " 17.64% mov rax, rcx " " 15.33% jmp 0xe jump block3(v18, v13, v14) br $loop `fib` :: block 0x0 :: 18.33% total samples [Samples] [Assembly] [CLIF] [Wasm] 18.33% cmp esi, edx brif v11, block2, block5 br_if $break jae 0x2a " " `wasm[0]::function[1]` :: block 0x37 :: 0.04% total samples [Samples] [Assembly] [CLIF] [Wasm] 0.04% add ebx, 1 - - jmp 0x6b jump block3(v14) br $loopDepends on https://github.com/bytecodealliance/wasmtime/pull/13073
fitzgen requested wasmtime-core-reviewers for a review on PR #13077.
fitzgen requested cfallin for a review on PR #13077.
fitzgen requested wasmtime-default-reviewers for a review on PR #13077.
fitzgen updated PR #13077.
cfallin submitted PR review:
This looks reasonable overall -- with my level of review on all of the output-parsing cod calibrated at "this is a useful tool for developers" rather than "production-ready robustness".
A thought below but otherwise I'm happy to see this in-tree for its usefulness. Thanks!
cfallin created PR review comment:
This feels slightly brittle to me in that it's essentially re-serializing (un-parsing) (parts of) the command line for a subprocess: we may miss new options we add that we'd want to pass to the subprocess. I wonder if it would make sense to have a
.to_cmdline()/.serialize()/ ... method on theRunCommand?
cfallin created PR review comment:
Rather than manually baking in the invocation of Capstone here, could we reuse the innards of
wasmtime objdumpto get the disassembly? That keeps our logic and deps for disassembly to one place overall.
fitzgen updated PR #13077.
fitzgen submitted PR review.
fitzgen created PR review comment:
Turns out that the
Displayimpleemntations do this already, so I reused that.
fitzgen submitted PR review.
fitzgen created PR review comment:
Factored out the disassembly code from the objdump command into a new, shared module and used it in
hot_blocks.rs.
fitzgen updated PR #13077.
github-actions[bot] added the label wasmtime:api on PR #13077.
fitzgen requested cfallin for a review on PR #13077.
alexcrichton submitted PR review:
Nice!
Stray thought on this: could debuginfo factor into this as well during rendering? For example at minimum this could print the hex offset in wasm which could then be passed to
wasm-tools addr2line, but at most it could runaddr2linehere in-process and print some information. If it's not easy to add though probably not worth it
cfallin submitted PR review.
cfallin submitted PR review:
This looks reasonable overall -- with my level of review on all of the output-parsing code calibrated at "this is a useful tool for developers" rather than "production-ready robustness".
A thought below but otherwise I'm happy to see this in-tree for its usefulness. Thanks!
fitzgen commented on PR #13077:
Stray thought on this: could debuginfo factor into this as well during rendering? For example at minimum this could print the hex offset in wasm which could then be passed to
wasm-tools addr2line, but at most it could runaddr2linehere in-process and print some information. If it's not easy to add though probably not worth itSure, I can investigate this in a follow up. Are you imagining, when we have debuginfo available, output that loks something like this?
[Samples] [Assembly] [CLIF] [Wasm] 14.07% add esi, 1 - - 21.29% lea ecx, [rax + rdi] v14 = iadd.i32 v13, v12 0x12 fib fib.rs:12:4
fitzgen commented on PR #13077:
Hm or maybe something like objdump's mixed source and asm disassembly? That way we could still see the actual Wasm instructions.
fitzgen added PR #13077 Add wasmtime hot-blocks subcommand to the merge queue.
alexcrichton commented on PR #13077:
I was just thinking of source locations for now, so no need to read files on disk and intermingle in source code just yet. What you sketched sounds reasoanble to me!
github-merge-queue[bot] removed PR #13077 Add wasmtime hot-blocks subcommand from the merge queue.
fitzgen updated PR #13077.
fitzgen has enabled auto merge for PR #13077.
fitzgen added PR #13077 Add wasmtime hot-blocks subcommand to the merge queue.
fitzgen merged PR #13077.
fitzgen removed PR #13077 Add wasmtime hot-blocks subcommand from the merge queue.
Last updated: May 03 2026 at 22:13 UTC