This is a guide for how to profile the compilation of a Rust library or binary.
Install the following packages from cargo:
cargo install --git https://github.com/rust-lang/measureme crox flamegraph summarize
See Using cargo for instructions on setting up cargo if needed.
Change the BUILD.gn for your rustc_binary or rustc_library to include configs += ["//build/config/rust:self-profile"].
fx build <target> or fx clippy <target>. The former will also include LLVM linking in the overall report, the latter will generate a report only for a check-build.
Locate the *.mm_profdata file which was created in your output directory (e.g. out/qemu/fxfs-0816704.mm_profdata).
summarize summarize out/qemu/fxfs-0816704.mm_profdata | rg '\|' | awk '{print $4,$2}' | head
flamegraph out/qemu/fxfs-0816704.mm_profdata
A rustc.svg file will be created in the current working directory which can be viewed in e.g. Chrome.
crox out/qemu/fxfs-0816704.mm_profdata
A chrome_profile.json file will be created in the current working directory which can be viewed in [ui.perfetto.dev].