rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.96k stars 12.69k forks source link

Add a cargo option to generate coverage reports using `-Z instrument-coverage` #85902

Open richkadel opened 3 years ago

richkadel commented 3 years ago

The Rust unstable book includes some examples of the workflow for generating LLVM coverage reports using -Z instrument-coverage.

Given the flexibility of this feature, having these detailed examples is useful, but there should be an "easy button" for generating coverage reports for the more common use cases. (I have some personal bash scripts to simplify the process during development, for example.) cargo can provide a great foundation for cross platform automation of Rust coverage analysis.

Some loose requirements, off the top of my head, include:

Longer term:

richkadel commented 3 years ago

Added to the tracking issue (#79121) for -Z instrument-coverage stabilization.

chadbrewbaker commented 3 years ago

cargo test -Ztimings is also problematic. It would be nice to shim in a prefix script like /usr/bin/time -v to get memory usage; I'm working on a Rust port of /usr/bin/time -v that emits JSON/CSV/PythonDict for easy parsing.

Debug symbols for production call stack profiling is another sore point. https://pyroscope.io/ uses https://github.com/iovisor/bcc/blob/master/tools/profile.py under the hood. This script needs modified to properly annotate Rust call stacks. Is cargo build able to emit debug symbol files as part of the production build? https://wiki.ubuntu.com/Debug%20Symbol%20Packages

Ideally one could get a coverage report from the production call stack traces too.

inquisitivecrystal commented 3 years ago

@rustbot label A-code-coverage C-feature-request T-cargo

jhpratt commented 3 years ago

Highly related: cargo llvm-cov