]>
Commit | Line | Data |
---|---|---|
041b39d2 XL |
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 | |
f035d41b XL |
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 | |
041b39d2 XL |
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. | |
0bf4aa26 | 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). |
f035d41b XL |
23 | |
24 | Please note that `RUSTFLAGS` by default applies to everything that cargo builds and runs during a build! | |
6a06907d XL |
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 | |
f035d41b | 27 | rustc for the specific crates you want to profile. |