]> git.proxmox.com Git - rustc.git/blame - src/doc/unstable-book/src/compiler-flags/profile.md
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / src / doc / unstable-book / src / compiler-flags / profile.md
CommitLineData
041b39d2
XL
1# `profile`
2
3The tracking issue for this feature is: [#42524](https://github.com/rust-lang/rust/issues/42524).
4
5------------------------
6
7This feature allows the generation of code coverage reports.
8
9Set the `-Zprofile` compiler flag in order to enable gcov profiling.
10
11For example:
12```Bash
13cargo new testgcov --bin
14cd testgcov
f035d41b
XL
15export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
16export CARGO_INCREMENTAL=0
041b39d2
XL
17cargo build
18cargo run
19```
20
21Once you've built and run your program, files with the `gcno` (after build) and `gcda` (after execution) extensions will be created.
0bf4aa26 22You can parse them with [llvm-cov gcov](https://llvm.org/docs/CommandGuide/llvm-cov.html#llvm-cov-gcov) or [grcov](https://github.com/mozilla/grcov).
f035d41b
XL
23
24Please note that `RUSTFLAGS` by default applies to everything that cargo builds and runs during a build!
6a06907d
XL
25When the `--target` flag is explicitly passed to cargo, the `RUSTFLAGS` no longer apply to build scripts and procedural macros.
26For more fine-grained control consider passing a `RUSTC_WRAPPER` program to cargo that only adds the profiling flags to
f035d41b 27rustc for the specific crates you want to profile.