Native cargo coverage support #13040
Labels
A-profiles
Area: profiles
C-feature-request
Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Command-test
S-needs-rfc
Status: Needs an RFC to make progress.
Problem
I was looking at a performance issue caused by env RUSTFLAGS="-Cinstrument-coverage" in our codebase and have determined that the major part of the degradation (~10x slowdown) was because dependencies were instrumented. In one particular case, a hot & tight AVX-intrinsic heavy code has been instrumented as well. I suspect that this was leading to AVX registers being spilled and reloaded between each intrinsic to invoke a call to the coverage runtime library(-ies.)
The best fix for me would have been to somehow exclude the dependencies external to the cargo workspace from being passed this flag (collecting coverage for external dependencies isn’t particularly useful in the first place), but I was not able to find any way to do so, before Jakub Beránek suggested to write a wrapper script that would be applied to my
cargo
invocations withRUSTC_WORKSPACE_WRAPPER
.The solution works, of course, but it isn’t particularly discoverable. The obvious way to achieve
-Cinstrument-coverage
continues to be viaRUSTFLAGS
and in most cases it will do something a little different from what a good default would be (to only instrument your own code.)Proposed Solution
I believe adding a profile setting to enable or disable addition of
-Cinstrument-coverage
flag would be a pretty good option here. It would allow to specifically instrument the local crates only (viaprofile.*.packages."*".instrument-coverage=false
) while also retaining a full ability to selectively or fully instrument all the other crates as well using the same mechanism.The one negative to this proposed solution is that the obvious setting of
is still going to instrument all the crates, including the dependencies.
Notes
Relevant discussion on Zulip
cc @Ekleog
cc @taiki-e (as a developer of llvm-cov)
The text was updated successfully, but these errors were encountered: