Skip to content

Native cargo coverage support #13040

Open

Description

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 with RUSTC_WORKSPACE_WRAPPER.

The solution works, of course, but it isn’t particularly discoverable. The obvious way to achieve -Cinstrument-coverage continues to be via RUSTFLAGS 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 (via profile.*.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

[profile.dev]
instrument-coverage = true

is still going to instrument all the crates, including the dependencies.

[profile.dev]
instrument-coverage = true
[profile.dev.packages."*"]
instrument-coverage = false

Notes

Relevant discussion on Zulip

cc @Ekleog
cc @taiki-e (as a developer of llvm-cov)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-profilesArea: profilesArea: profilesC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-testS-needs-rfcStatus: Needs an RFC to make progress.Status: Needs an RFC to make progress.

    Type

    No type

    Projects

    • Status

      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions