Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support generating unique profraw files by default when using -C instrument-coverage #100381

Closed
ridwanabdillahi opened this issue Aug 10, 2022 · 1 comment
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@ridwanabdillahi
Copy link
Contributor

Currently, when enabling the instrumentation of Rust crates using the -C instrument-coverage rustc flag, rustc does not set any default naming scheme for the generated *.profraw files. Today, a user has two options:

  1. Allow LLVM to set the default naming scheme which is default.profraw. Thie issue here is if there is more than one binary being executed that is linked to the instrumented library, LLVM would overwrite the coverage results from the previous executed binary.
  2. Manually set the LLVM_PROFILE_FILE environment variable and apply LLVMs special pattern strings to ensure unique files are generated.

LLVM also has API support for passing in the designated filename for instrumented profile files via rustc. This is leveraged today when enabling profile guided optimization or PGO. The Rust compiler directly sets a default naming scheme for the generated profraw file, default_%m.profraw.

Profile files generated by rustc's -C instrument-coverage should have the same or similar defaults to ensure coverage results are not overwritten by each test binary executed. A similar but more unique version of the default for PGO instrumented profile files should be used since multiple binaries are executed using the same instrumented library such as default_%m_%p.profraw.

@Urgau
Copy link
Member

Urgau commented Aug 10, 2022

@rustbot labels +A-code-coverage +C-enhancement

@rustbot rustbot added A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Aug 10, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 16, 2022
…ut, r=wesleywiser

Add support for generating unique profraw files by default when using `-C instrument-coverage`

Currently, enabling the rustc flag `-C instrument-coverage` instruments the given crate and by default uses the naming scheme `default.profraw` for any instrumented profile files generated during the execution of a binary linked against this crate. This leads to multiple binaries being executed overwriting one another and causing only the last executable run to contain actual coverage results.

This can be overridden by manually setting the environment variable `LLVM_PROFILE_FILE` to use a unique naming scheme.

This PR adds a change to add support for a reasonable default for rustc to use when enabling coverage instrumentation similar to how the Rust compiler treats generating these same `profraw` files when PGO is enabled.

The new naming scheme is set to `default_%m_%p.profraw` to ensure the uniqueness of each file being generated using [LLVMs special pattern strings](https://clang.llvm.org/docs/SourceBasedCodeCoverage.html#running-the-instrumented-program).

Today the compiler sets the default for PGO `profraw` files to `default_%m.profraw` to ensure a unique file for each run. The same can be done for the instrumented profile files generated via the `-C instrument-coverage` flag as well which LLVM has API support for.

Linked Issue: rust-lang#100381

r? `@wesleywiser`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

3 participants