mozilla / grcov

Rust tool to collect and aggregate code coverage data for multiple source files
Mozilla Public License 2.0
1.19k stars 149 forks source link

Malformed instrumentation profile data #575

Open zbraniecki opened 3 years ago

zbraniecki commented 3 years ago

I'm trying to run grcov locally against fluent-rs:

cargo +nightly  --version; // cargo 1.51.0-nightly (c3abcfe8a 2021-01-25)
grcov --version; // grcov 0.7.1
rustup +nightly component add llvm-tools-preview
export RUSTFLAGS="-Zinstrument-coverage"
cargo +nightly build
cargo +nightly test
grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/coverage/

output:

03:09:27 [ERROR] Error while executing llvm tools: Failure while running "/home/zbraniecki/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata" "merge" "-sparse" "/tmp/.tmpLgJJPj/fluent-syntax/default_1.profraw" "/tmp/.tmpLgJJPj/fluent/default_1.profraw" "/tmp/.tmpLgJJPj/fluent-pseudo/default_1.profraw" "/tmp/.tmpLgJJPj/fluent-fallback/default_1.profraw" "/tmp/.tmpLgJJPj/fluent-testing/default_1.profraw" "/tmp/.tmpLgJJPj/fluent-bundle/default_1.profraw" "/tmp/.tmpLgJJPj/default_1.profraw" "/tmp/.tmpLgJJPj/intl-memoizer/default_1.profraw" "/tmp/.tmpLgJJPj/fluent-resmgr/default_1.profraw" "-o" "/tmp/.tmpLgJJPj/3/grcov.profdata"
warning: /tmp/.tmpLgJJPj/fluent-syntax/default_1.profraw: Malformed instrumentation profile data
error: No profiles could be merged.

What am I doing wrong?

zbraniecki commented 3 years ago

I see that grcov used stable llvm-profdata here, and I don't think I can change that, so I also did rustup default nightly and redid all the steps and the error is:

▶ grcov . -s . --binary-path ./target/debug/ -t lcov --branch --ignore-not-existing -o ./target/debug/coverage/
03:15:58 [ERROR] Error while executing llvm tools: Failure while running "/home/zbraniecki/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata" "merge" "-sparse" "/tmp/.tmpIO8hPr/fluent-syntax/default_1.profraw" "/tmp/.tmpIO8hPr/fluent/default_1.profraw" "/tmp/.tmpIO8hPr/fluent-pseudo/default_1.profraw" "/tmp/.tmpIO8hPr/fluent-fallback/default_1.profraw" "/tmp/.tmpIO8hPr/fluent-testing/default_1.profraw" "/tmp/.tmpIO8hPr/fluent-bundle/default_1.profraw" "/tmp/.tmpIO8hPr/default_1.profraw" "/tmp/.tmpIO8hPr/intl-memoizer/default_1.profraw" "/tmp/.tmpIO8hPr/fluent-resmgr/default_1.profraw" "-o" "/tmp/.tmpIO8hPr/0/grcov.profdata"
warning: /tmp/.tmpIO8hPr/fluent-syntax/default_1.profraw: Malformed instrumentation profile data
error: No profiles could be merged.
marco-c commented 3 years ago

@zbraniecki is there any chance there are some profraw files left from earlier executions? Can you make sure you remove all of them first, in any subdirectory of your CWD, and then try again?

csnover commented 3 years ago

I’m seeing the same thing here, trying to run against this tree. This is a fresh install of grcov, I have had no .profraw files before, and I confirmed that no .profraw files existed before running RUSTFLAGS="-Zinstrument-coverage" cargo +nightly test.

One possibly relevant thing that happened after I tried switching the default toolchain to nightly (so that grcov would use nightly) was that the error message changed from “Malformed instrumentation profile data” to “Failed to uncompress data (zlib)”. Otherwise everything is the same.

Versions: rustc 1.52.0-nightly (a15f484b9 2021-02-22) grcov 0.7.1 macOS 10.14.6 Apple clang version 11.0.0 (clang-1100.0.33.17) Target: x86_64-apple-darwin18.7.0

winksaville commented 3 years ago

I'm having the same problem in this repo:

$ grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/coverage/
19:54:35 [ERROR] Error while executing llvm tools: Failure while running "/home/wink/.rustup/toolchains/nightly-2021-03-25-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata" "merge" "-sparse" "/tmp/.tmprPDOCZ/default_1.profraw" "-o" "/tmp/.tmprPDOCZ/1/grcov.profdata"
warning: /tmp/.tmprPDOCZ/default_1.profraw: Malformed instrumentation profile data
error: No profiles could be merged.

I started with a cargo clean

wink@3900x:~/prgs/rust/projects/binance-auto-sell (main)
$ cargo clean

wink@3900x:~/prgs/rust/projects/binance-auto-sell (main)
$ ls target/debug/deps/*.gcda
ls: cannot access 'target/debug/deps/*.gcda': No such file or directory

wink@3900x:~/prgs/rust/projects/binance-auto-sell (main)
$ ls target/debug/deps/*.gcno^C

wink@3900x:~/prgs/rust/projects/binance-auto-sell (main)
$ cargo build
   Compiling proc-macro2 v1.0.26
   Compiling version_check v0.9.3
   Compiling unicode-xid v0.2.1
   Compiling syn v1.0.69
   Compiling libc v0.2.93
   Compiling autocfg v1.0.1
   Compiling unicode-segmentation v1.7.1
   Compiling bitflags v1.2.1
   Compiling unicode-width v0.1.8
   Compiling hashbrown v0.9.1
   Compiling lazy_static v1.4.0
   Compiling vec_map v0.8.2
   Compiling termcolor v1.1.2
   Compiling strsim v0.10.0
   Compiling os_str_bytes v2.4.0
   Compiling textwrap v0.12.1
   Compiling heck v0.3.2
   Compiling proc-macro-error-attr v1.0.4
   Compiling proc-macro-error v1.0.4
   Compiling indexmap v1.6.2
   Compiling quote v1.0.9
   Compiling atty v0.2.14
   Compiling clap_derive v3.0.0-beta.2
   Compiling clap v3.0.0-beta.2
   Compiling binance-auto-sell v0.1.0 (/home/wink/prgs/rust/projects/binance-auto-sell)
    Finished dev [unoptimized + debuginfo] target(s) in 12.67s

wink@3900x:~/prgs/rust/projects/binance-auto-sell (main)
$ ls target/debug/deps/*.gcda
target/debug/deps/autocfg-126bc84acbac0b8c.gcda                target/debug/deps/quote-5f2a98a903f1d830.gcda
target/debug/deps/clap_derive-41d1e50bc7b6fbf1.gcda            target/debug/deps/syn-945e0b207a9244e3.gcda
target/debug/deps/heck-3bb96286dbb034a0.gcda                   target/debug/deps/unicode_segmentation-d992f3cab04b59cb.gcda
target/debug/deps/proc_macro2-32a461668e4c2f4b.gcda            target/debug/deps/unicode_xid-4182131ee577b5da.gcda
target/debug/deps/proc_macro_error_attr-fed05f76688e79bf.gcda  target/debug/deps/version_check-9c3b370c5d37e25f.gcda
target/debug/deps/proc_macro_error-e052a8072925854c.gcda

wink@3900x:~/prgs/rust/projects/binance-auto-sell (main)
$ ls target/debug/deps/*.gcno
target/debug/deps/atty-706b631cf0f623af.gcno               target/debug/deps/proc_macro_error_attr-fed05f76688e79bf.gcno
target/debug/deps/autocfg-126bc84acbac0b8c.gcno            target/debug/deps/proc_macro_error-e052a8072925854c.gcno
target/debug/deps/binance_auto_sell-08d4f743715dd216.gcno  target/debug/deps/quote-5f2a98a903f1d830.gcno
target/debug/deps/bitflags-fec8e9ae1a67719f.gcno           target/debug/deps/strsim-042a9a3b14de9d23.gcno
target/debug/deps/clap_derive-41d1e50bc7b6fbf1.gcno        target/debug/deps/syn-945e0b207a9244e3.gcno
target/debug/deps/clap-f364193d6943d44e.gcno               target/debug/deps/termcolor-facf7d196d2bb8d6.gcno
target/debug/deps/hashbrown-58b681a40238888b.gcno          target/debug/deps/textwrap-6012548a703e61d2.gcno
target/debug/deps/heck-3bb96286dbb034a0.gcno               target/debug/deps/unicode_segmentation-d992f3cab04b59cb.gcno
target/debug/deps/indexmap-6b0ded79e8b39e78.gcno           target/debug/deps/unicode_width-9ab5865733e9acc9.gcno
target/debug/deps/lazy_static-ff2d4c059a61c830.gcno        target/debug/deps/unicode_xid-4182131ee577b5da.gcno
target/debug/deps/libc-3b8e6d0e981cb486.gcno               target/debug/deps/vec_map-6ca2ab92fd8f89b6.gcno
target/debug/deps/os_str_bytes-102a4b6d633dbb5e.gcno       target/debug/deps/version_check-9c3b370c5d37e25f.gcno
target/debug/deps/proc_macro2-32a461668e4c2f4b.gcno

wink@3900x:~/prgs/rust/projects/binance-auto-sell (main)
$ cargo test
   Compiling memchr v2.3.4
   Compiling predicates-core v1.0.2
   Compiling regex-syntax v0.6.23
   Compiling doc-comment v0.3.3
   Compiling byteorder v1.4.3
   Compiling normalize-line-endings v0.3.0
   Compiling treeline v0.1.0
   Compiling difference v2.0.0
   Compiling num-traits v0.2.14
   Compiling wait-timeout v0.2.0
   Compiling predicates-tree v1.0.2
   Compiling regex-automata v0.1.9
   Compiling aho-corasick v0.7.15
   Compiling bstr v0.2.15
   Compiling float-cmp v0.8.0
   Compiling regex v1.4.5
   Compiling predicates v1.0.7
   Compiling assert_cmd v1.0.3
   Compiling binance-auto-sell v0.1.0 (/home/wink/prgs/rust/projects/binance-auto-sell)
    Finished test [unoptimized + debuginfo] target(s) in 5.77s
     Running unittests (target/debug/deps/binance_auto_sell-c339468d8b31a4f5)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/cli.rs (target/debug/deps/cli-03999f18fd6a5d1d)

running 4 tests
test test_req_params ... ok
test test_no_params ... ok
test test_help ... ok
test test_req_params_as_env_vars ... ok

test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s

wink@3900x:~/prgs/rust/projects/binance-auto-sell (main)
$ ls target/debug/deps/*.gcno
target/debug/deps/aho_corasick-ad99b36d87dad5ef.gcno            target/debug/deps/os_str_bytes-102a4b6d633dbb5e.gcno
target/debug/deps/assert_cmd-f0b35b0037a1eb28.gcno              target/debug/deps/predicates-b111f5b45bf83e43.gcno
target/debug/deps/atty-706b631cf0f623af.gcno                    target/debug/deps/predicates_core-4cee68d773ad6d15.gcno
target/debug/deps/autocfg-126bc84acbac0b8c.gcno                 target/debug/deps/predicates_tree-19be2b1addb64486.gcno
target/debug/deps/binance_auto_sell-08d4f743715dd216.gcno       target/debug/deps/proc_macro2-32a461668e4c2f4b.gcno
target/debug/deps/binance_auto_sell-c339468d8b31a4f5.gcno       target/debug/deps/proc_macro_error_attr-fed05f76688e79bf.gcno
target/debug/deps/bitflags-fec8e9ae1a67719f.gcno                target/debug/deps/proc_macro_error-e052a8072925854c.gcno
target/debug/deps/bstr-8a46881b1818d9ab.gcno                    target/debug/deps/quote-5f2a98a903f1d830.gcno
target/debug/deps/byteorder-1dcd7d16eaa2a55e.gcno               target/debug/deps/regex_automata-622c79664be0867f.gcno
target/debug/deps/clap_derive-41d1e50bc7b6fbf1.gcno             target/debug/deps/regex-f8c6ba8a7a4b41cb.gcno
target/debug/deps/clap-f364193d6943d44e.gcno                    target/debug/deps/regex_syntax-4fc315958e360e1e.gcno
target/debug/deps/cli-03999f18fd6a5d1d.gcno                     target/debug/deps/strsim-042a9a3b14de9d23.gcno
target/debug/deps/difference-0b1df53297011337.gcno              target/debug/deps/syn-945e0b207a9244e3.gcno
target/debug/deps/doc_comment-5fa0b7b5ac9399ae.gcno             target/debug/deps/termcolor-facf7d196d2bb8d6.gcno
target/debug/deps/float_cmp-b917f80ceb711dd5.gcno               target/debug/deps/textwrap-6012548a703e61d2.gcno
target/debug/deps/hashbrown-58b681a40238888b.gcno               target/debug/deps/treeline-f99e78fe68ba5336.gcno
target/debug/deps/heck-3bb96286dbb034a0.gcno                    target/debug/deps/unicode_segmentation-d992f3cab04b59cb.gcno
target/debug/deps/indexmap-6b0ded79e8b39e78.gcno                target/debug/deps/unicode_width-9ab5865733e9acc9.gcno
target/debug/deps/lazy_static-ff2d4c059a61c830.gcno             target/debug/deps/unicode_xid-4182131ee577b5da.gcno
target/debug/deps/libc-3b8e6d0e981cb486.gcno                    target/debug/deps/vec_map-6ca2ab92fd8f89b6.gcno
target/debug/deps/memchr-e220204c3e6e1397.gcno                  target/debug/deps/version_check-9c3b370c5d37e25f.gcno
target/debug/deps/normalize_line_endings-e18de6db46d4808b.gcno  target/debug/deps/wait_timeout-cdc2a104228af21e.gcno
target/debug/deps/num_traits-8b15a5fa3e43484a.gcno

wink@3900x:~/prgs/rust/projects/binance-auto-sell (main)
$ ls target/debug/deps/*.gcda
target/debug/deps/aho_corasick-ad99b36d87dad5ef.gcda       target/debug/deps/predicates-b111f5b45bf83e43.gcda
target/debug/deps/assert_cmd-f0b35b0037a1eb28.gcda         target/debug/deps/predicates_core-4cee68d773ad6d15.gcda
target/debug/deps/atty-706b631cf0f623af.gcda               target/debug/deps/predicates_tree-19be2b1addb64486.gcda
target/debug/deps/autocfg-126bc84acbac0b8c.gcda            target/debug/deps/proc_macro2-32a461668e4c2f4b.gcda
target/debug/deps/binance_auto_sell-08d4f743715dd216.gcda  target/debug/deps/proc_macro_error_attr-fed05f76688e79bf.gcda
target/debug/deps/binance_auto_sell-c339468d8b31a4f5.gcda  target/debug/deps/proc_macro_error-e052a8072925854c.gcda
target/debug/deps/bstr-8a46881b1818d9ab.gcda               target/debug/deps/quote-5f2a98a903f1d830.gcda
target/debug/deps/byteorder-1dcd7d16eaa2a55e.gcda          target/debug/deps/regex_automata-622c79664be0867f.gcda
target/debug/deps/clap_derive-41d1e50bc7b6fbf1.gcda        target/debug/deps/regex-f8c6ba8a7a4b41cb.gcda
target/debug/deps/clap-f364193d6943d44e.gcda               target/debug/deps/regex_syntax-4fc315958e360e1e.gcda
target/debug/deps/cli-03999f18fd6a5d1d.gcda                target/debug/deps/strsim-042a9a3b14de9d23.gcda
target/debug/deps/difference-0b1df53297011337.gcda         target/debug/deps/syn-945e0b207a9244e3.gcda
target/debug/deps/float_cmp-b917f80ceb711dd5.gcda          target/debug/deps/termcolor-facf7d196d2bb8d6.gcda
target/debug/deps/hashbrown-58b681a40238888b.gcda          target/debug/deps/textwrap-6012548a703e61d2.gcda
target/debug/deps/heck-3bb96286dbb034a0.gcda               target/debug/deps/unicode_segmentation-d992f3cab04b59cb.gcda
target/debug/deps/indexmap-6b0ded79e8b39e78.gcda           target/debug/deps/unicode_width-9ab5865733e9acc9.gcda
target/debug/deps/libc-3b8e6d0e981cb486.gcda               target/debug/deps/unicode_xid-4182131ee577b5da.gcda
target/debug/deps/memchr-e220204c3e6e1397.gcda             target/debug/deps/version_check-9c3b370c5d37e25f.gcda
target/debug/deps/num_traits-8b15a5fa3e43484a.gcda         target/debug/deps/wait_timeout-cdc2a104228af21e.gcda
target/debug/deps/os_str_bytes-102a4b6d633dbb5e.gcda
wink@3900x:~/prgs/rust/projects/binance-auto-sell (main)
$ grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/coverage/
19:54:35 [ERROR] Error while executing llvm tools: Failure while running "/home/wink/.rustup/toolchains/nightly-2021-03-25-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata" "merge" "-sparse" "/tmp/.tmprPDOCZ/default_1.profraw" "-o" "/tmp/.tmprPDOCZ/1/grcov.profdata"
warning: /tmp/.tmprPDOCZ/default_1.profraw: Malformed instrumentation profile data
error: No profiles could be merged.

wink@3900x:~/prgs/rust/projects/binance-auto-sell (main)
$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/wink/.rustup

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu (default)
nightly-2021-03-25-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu

active toolchain
----------------

nightly-2021-03-25-x86_64-unknown-linux-gnu (overridden by '/home/wink/prgs/rust/projects/binance-auto-sell/rust-toolchain')
rustc 1.53.0-nightly (07e0e2ec2 2021-03-24)

wink@3900x:~/prgs/rust/projects/binance-auto-sell (main)
$ grcov --version
grcov 0.7.1

wink@3900x:~/prgs/rust/projects/binance-auto-sell (main)
$ clang --version
clang version 11.1.0
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

wink@3900x:~/prgs/rust/projects/binance-auto-sell (main)
$ inxi -Fxz
System:    Kernel: 5.11.11-arch1-1 x86_64 bits: 64 compiler: N/A Desktop: Cinnamon 4.8.6 Distro: Arch Linux 
Machine:   Type: Desktop Mobo: ASRock model: X570 Creator serial: <filter> UEFI: American Megatrends v: P2.10 date: 12/16/2019 
CPU:       Topology: 12-Core model: AMD Ryzen 9 3900X bits: 64 type: MT MCP arch: Zen 2 L2 cache: 6144 KiB 
           flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm bogomips: 182474 
           Speed: 3598 MHz min/max: 2200/3800 MHz Core speeds (MHz): 1: 3596 2: 2056 3: 3599 4: 2058 5: 3599 6: 2055 7: 2057 
           8: 2197 9: 2200 10: 2198 11: 2200 12: 2200 13: 2056 14: 2199 15: 2058 16: 3600 17: 2056 18: 2199 19: 2200 20: 2200 
           21: 2203 22: 2200 23: 2199 24: 2062 
Graphics:  Device-1: NVIDIA TU116 [GeForce GTX 1660] vendor: Micro-Star MSI driver: nvidia v: 460.67 bus ID: 7c:00.0 
           Display: x11 server: X.org 1.20.10 driver: nvidia unloaded: modesetting resolution: <xdpyinfo missing> 
           Message: Unable to show advanced data. Required tool glxinfo missing. 
Audio:     Device-1: NVIDIA TU116 High Definition Audio vendor: Micro-Star MSI driver: snd_hda_intel v: kernel bus ID: 7c:00.1 
           Device-2: Advanced Micro Devices [AMD] Starship/Matisse HD Audio vendor: ASRock driver: snd_hda_intel v: kernel 
           bus ID: 7e:00.4 
           Sound Server: ALSA v: k5.11.11-arch1-1 
Network:   Device-1: Intel I211 Gigabit Network vendor: ASRock driver: igb v: kernel port: b000 bus ID: 71:00.0 
           IF: enp113s0 state: down mac: <filter> 
           Device-2: Intel Wi-Fi 6 AX200 driver: iwlwifi v: kernel port: b000 bus ID: 72:00.0 
           IF: wlp114s0 state: down mac: <filter> 
           Device-3: Aquantia AQC107 NBase-T/IEEE 802.3bz Ethernet [AQtion] vendor: ASRock driver: atlantic v: kernel 
           port: a000 bus ID: 77:00.0 
           IF: enp119s0 state: up speed: 1000 Mbps duplex: full mac: <filter> 
           IF-ID-1: docker0 state: down mac: <filter> 
Drives:    Local Storage: total: 465.76 GiB used: 156.09 GiB (33.5%) 
           ID-1: /dev/nvme0n1 vendor: Sabrent model: Rocket 4.0 500GB size: 465.76 GiB 
           ID-2: /dev/nvme1n1 vendor: Sabrent model: Rocket 4.0 500GB size: 465.76 GiB 
Partition: ID-1: / size: 491.15 GiB used: 156.02 GiB (31.8%) fs: ext4 dev: /dev/dm-2 
           ID-2: /boot size: 1.86 GiB used: 73.4 MiB (3.9%) fs: vfat dev: /dev/nvme0n1p1 
Swap:      ID-1: swap-1 type: file size: 512.0 MiB used: 0 KiB (0.0%) file: /swapfile 
Sensors:   System Temperatures: cpu: 42.5 C mobo: N/A 
           Fan Speeds (RPM): N/A 
Info:      Processes: 470 Uptime: 6h 01m Memory: 31.28 GiB used: 7.03 GiB (22.5%) Init: systemd Compilers: gcc: 10.2.0 
           clang: 11.1.0 Shell: bash v: 5.1.4 inxi: 3.1.03 
marco-c commented 3 years ago

@zbraniecki @csnover @winksaville I've realized I didn't document this properly (see #595), but the LLVM_PROFILE_FILE environment variable should be used in non-trivial settings. Can you ensure you do step 4 of https://github.com/mozilla/grcov#example-how-to-generate-source-based-coverage-for-a-rust-project before running tests, and report back on your results?

BogdanovAleksei commented 2 years ago

For nightly compiler use :

$ rustup default nightly
$ cargo install grcov
$ rustup component add llvm-tools-preview
gkorland commented 2 years ago

We're also getting the same error when running

grcov . --binary-path ./bin/linux-x64-debug/rejson.so -s . -t lcov --branch --ignore-not-existing --ignore "/*" -o lcov.info

We get:

warning: /tmp/.tmphfHmgu/default_1.profraw: malformed instrumentation profile data
marco-c commented 2 years ago

@gkorland are you using LLVM_PROFILE_FILE like described in step 4 of https://github.com/mozilla/grcov#example-how-to-generate-source-based-coverage-for-a-rust-project?

gkorland commented 2 years ago

@marco-c yes I do.

yi-ge commented 1 year ago

I have the same problem.

yi-ge commented 1 year ago

After investigating the grcov source code, the issue is due to grcov's default use of Rust toolchain's built-in llvm-profdata instead of the version in the system PATH. The Rust toolchain's llvm-profdata may not have zlib support, which is why you encountered a problem when running grcov.

If you want grcov to use the llvm-profdata version in your system PATH (e.g., the version installed through Homebrew), you can set the --llvm-path option to point to the folder path where your llvm-profdata executable is located.