Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo flamegraph support #38

Open
lpotthast opened this issue Dec 4, 2023 · 2 comments
Open

cargo flamegraph support #38

lpotthast opened this issue Dec 4, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@lpotthast
Copy link

Using https://github.com/flamegraph-rs/flamegraph with

cargo flamegraph --bench benchmarks

with benches/benchmarks.rs being present and defined in Cargo.toml leads to benchmark names being printed but no benchmark-code being actually executed.

It would be great if there was support between divan and flamegraph!
If I do something wrong and this should already work, please let me know.

@nvzqz nvzqz added the enhancement New feature or request label Dec 6, 2023
@cbarrick
Copy link

cbarrick commented Mar 5, 2024

In my experience, it seems like the benchmarks are being run, but only a single sample of each. I can verify this be having a single benchmark that is expected to run for a nontrivial amount of time (like 20s).

Using cargo bench with divan, I know how long a single sample should take, and using cargo flamegraph appears to take that exact amount of time. The resulting flamegraph looks plausible.

However, no measurements are printed to the console, and --sample-count is ignored.

Maybe this is WAI and we just need some documentation?

@cbarrick
Copy link

cbarrick commented Mar 7, 2024

I did some debugging on this.

It turns out that cargo bench --bench=foo will call you benchmark like:

./target/bench/deps/foo --bench

But cargo flamegraph --bench=foo will call your benchmark like:

./target/bench/deps/foo

i.e. cargo flamegraph does not pass the --bench flag. Without this flag, divan::main will run your benchmarks once without reporting stats.

The quickfix is to invoke your benchmark like:

cargo flamegraph --bench=foo -- --bench

I am not sure if this is a bug in cargo-flamegraph, a bug in divan, or working as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants