]> git.lizzy.rs Git - rust.git/blob - src/doc/unstable-book/src/compiler-flags/profile.md
Rollup merge of #85663 - fee1-dead:document-arc-from, r=m-ou-se
[rust.git] / src / doc / unstable-book / src / compiler-flags / profile.md
1 # `profile`
2
3 The tracking issue for this feature is: [#42524](https://github.com/rust-lang/rust/issues/42524).
4
5 ------------------------
6
7 This feature allows the generation of code coverage reports.
8
9 Set the `-Zprofile` compiler flag in order to enable gcov profiling.
10
11 For example:
12 ```Bash
13 cargo new testgcov --bin
14 cd testgcov
15 export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
16 export CARGO_INCREMENTAL=0
17 cargo build
18 cargo run
19 ```
20
21 Once you've built and run your program, files with the `gcno` (after build) and `gcda` (after execution) extensions will be created.
22 You 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).
23
24 Please note that `RUSTFLAGS` by default applies to everything that cargo builds and runs during a build!
25 When the `--target` flag is explicitly passed to cargo, the `RUSTFLAGS` no longer apply to build scripts and procedural macros.
26 For more fine-grained control consider passing a `RUSTC_WRAPPER` program to cargo that only adds the profiling flags to
27 rustc for the specific crates you want to profile.