From 2b26b8b32bb2246caa0a82b6ea16f11da3686d0e Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Tue, 26 May 2020 15:16:57 +0200 Subject: [PATCH 1/2] Fix documentation example for gcov profiling Incremental compilation needs to be turned off. Also added the other RUSTFLAGS that should/need to be turned on. --- src/doc/unstable-book/src/compiler-flags/profile.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/doc/unstable-book/src/compiler-flags/profile.md b/src/doc/unstable-book/src/compiler-flags/profile.md index 452aca51532c9..b3b3e4eb4058f 100644 --- a/src/doc/unstable-book/src/compiler-flags/profile.md +++ b/src/doc/unstable-book/src/compiler-flags/profile.md @@ -12,10 +12,15 @@ For example: ```Bash cargo new testgcov --bin cd testgcov -export RUSTFLAGS="-Zprofile" +export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort" +export CARGO_INCREMENTAL=0 cargo build cargo run ``` Once you've built and run your program, files with the `gcno` (after build) and `gcda` (after execution) extensions will be created. 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). + +Please note that `RUSTFLAGS` apply to everything that cargo builds and runs during a build, including build scripts! +To avoid this, pass a `RUSTC_WRAPPER` program to cargo that only adds the profiling flags to rustc for the specific +crates you want to profile. From 7bf026eed6924f7175e9df8c7c81ac2e2697daef Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Wed, 3 Jun 2020 11:05:56 +0200 Subject: [PATCH 2/2] Doc: unstable book - profile.md: improve wording - mention `--target` flag excludes RUSTFLAGS passing to build scripts and proc macros --- src/doc/unstable-book/src/compiler-flags/profile.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/doc/unstable-book/src/compiler-flags/profile.md b/src/doc/unstable-book/src/compiler-flags/profile.md index b3b3e4eb4058f..7973b3e4f2f32 100644 --- a/src/doc/unstable-book/src/compiler-flags/profile.md +++ b/src/doc/unstable-book/src/compiler-flags/profile.md @@ -21,6 +21,7 @@ cargo run Once you've built and run your program, files with the `gcno` (after build) and `gcda` (after execution) extensions will be created. 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). -Please note that `RUSTFLAGS` apply to everything that cargo builds and runs during a build, including build scripts! -To avoid this, pass a `RUSTC_WRAPPER` program to cargo that only adds the profiling flags to rustc for the specific -crates you want to profile. +Please note that `RUSTFLAGS` by default applies to everything that cargo builds and runs during a build! +When the `--target` flag is explicitly passed to cargo, the `RUSTFLAGS` no longer apply to build scripts and procedural macros. +For more fine-grained control consider passing a `RUSTC_WRAPPER` program to cargo that only adds the profiling flags to +rustc for the specific crates you want to profile.