We'll be profiling these benchmarks with Visual Studio. Make sure you have basic C/C++ payloads installed for it.
- Add the following beneath the
[[bench]]
line inCargo.toml
:[profile.bench] debug = true
- Build the benchmark without running it with
cargo bench --no-run
- Locate the benchmark binary at
target/release/deps/bench-*.exe
. If there are multiplebench
executables indeps
, you can determine which one is the most recent by deleting all of them and rebuilding. - Start Visual Studio and open a new project. Browse to the
.exe
location and open it. - Right click on the
bench-*
project in the Solution Explorer and selectProperties
. - Set the
Arguments
parameter to--bench <FILTER>
where<FILTER>
is the filter you would pass tocargo bench -- <FILTER>
. - Save the project properties and select
Debug > Performance Profiler...
. - Check
CPU Usage
and clickStart
. The benchmarks will run and upon finishing the data will be analyzed. - Select the areas of the diagnostics session when your benchmark is running to analyze.
With the "pprof" feature enabled, the Criterion benchmarking library can be used
to automatically output profiles with flamegraphs for each benchmark. Simply run
the desired benchmarks while passing --profile-time=10
or similar to the
benchmark binary. (Passing this argument probably requires specifying the
"bench" benchmark specifically, as other test binaries that cargo thinks might
have benchmarks in them do not understand the flag.)
Example command: cargo bench --bench bench --no-default-features --features fooencoder,pprof -- 'minecraft_savedata/fooencoder/serialize' --profile-time=10
This will run the "minecraft_savedata/fooencoder/serialize" benchmark and
profile it, then save a flamegraph of the profile results as a .svg
file to
target/criterion/minecraft_savedata_fooencoder/serialize/profile/flamegraph.svg
.
Know how to profile these benchmarks on other platforms? Open a pull request!