adamrk opened PR #15188 from adamrk:abk/bench-callgrind to bytecodealliance:main:
Allow benchmarks to be measured by running under Callgrind. This is done by providing a utilities
wasmtime_bench_util::benchandwasmtime_bench_util::Timerwhich are drop-in replacements forcriterion::Bencher::iterandstd::time::Instantrespectively.The goal of this change is to allow tracking of benchmark results in are-we-fast-yet.
When run natively, the utility replacements behave the same as
iterandInstant, but when running under Callgrind they'll dump Valgrind counters when the timer is stopped.Additionally, a helper function is provided which can be used to detect if the benchmark is being run under Valgrind and this is used for some benchmarks to reduce their memory usage to an amount Valgrind can support.
When using Valgrind, benchmarks should be run with Criterion's
--testmode, so that each benchmark produces a single dump:valgrind --tool=callgrind --instr-atstart=no \ target/release/deps/<bench> --bench --test<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease review the Bytecode Alliance's AI tool usage policy at
https://github.com/bytecodealliance/governance/blob/main/AI_TOOL_POLICY.mdPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
adamrk removed the review request for wasmtime-wasi-reviewers from PR #15188.
adamrk requested wasmtime-wasi-reviewers for a review on PR #15188.
adamrk requested rvolosatovs for a review on PR #15188.
adamrk removed the review request for wasmtime-core-reviewers from PR #15188.
adamrk requested dicej for a review on PR #15188.
adamrk requested wasmtime-core-reviewers for a review on PR #15188.
adamrk removed the review request for wasmtime-default-reviewers from PR #15188.
adamrk requested wasmtime-default-reviewers for a review on PR #15188.
adamrk requested alexcrichton for a review on PR #15188.
:memo: adamrk submitted PR review.
:speech_balloon: adamrk created PR review comment:
This dependency is already used in Sightglass, but it pulls in a few dependencies which don't pass
cargo vetyet. I marked the new bench util crate as only needingsafe-to-run, but I'm not sure exactly what the process should be for marking these new crates assafe-to-run.Alternatively, we could not use
valgrind-requestsand just implement what we need directly. I think that would be about 60 lines of code where were copying constants from valgrind header files, as well as inline assembly to clear and dump the counters.
adamrk updated PR #15188.
adamrk updated PR #15188.
alexcrichton commented on PR #15188:
What's the consequence of forgetting this? Given that we have to go out of our way to integrate this seems like any new benchmarks are more-or-less guaranteed to forget this so I'm curious what would happen in that case. Overall looks fine to me, and new dev-deps IMO are fine.
adamrk commented on PR #15188:
What's the consequence of forgetting this?
If someone creates a benchmark that uses
std::time::Instantor the criterioniterthen I think we should be able to set up are-we-fast-yet to see that there's no dump for that benchmark and show it as an error (or just 0).
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
This dependency is already used in Sightglass, but it pulls in a few dependencies which don't pass
cargo vetyet. I marked the new bench util crate as only needingsafe-to-run, but I'm not sure exactly what the process should be for marking these new crates assafe-to-run.I think it is fine to mark as
safe-to-runsince it is a developer dependency only, not a deployment dependency.
adamrk updated PR #15188.
adamrk updated PR #15188.
adamrk requested fitzgen for a review on PR #15188.
Last updated: Nov 19 2026 at 20:05 UTC