Code Monkey home page Code Monkey logo

llvm-profparser's Introduction

llvm-profparser

Build Status License Coverage Status

This is a reasonably complete to parse the llvm instrumentation profraw file format and avoid the need to install and use the llvm-profdata/llvm-cov binaries. It aims to be backwards compatible with as many llvm versions that could be used for coverage data in Rust projects and currently supports the following llvm versions: 11, 12, 13, 14, 15.

This project is not affilated with the llvm-project in anyway! It is merely a parser for some of their file formats to aid interoperability in Rust.

Contributing

All of the functionality required has been implemented, however there are areas to improve in handling unexpected or invalid files. To start fining issues there's a fuzz directory which will undoubtedly reveal some issues that can be fixed. Go into the fuzz directory for guides on how to run.

License

llvm_profparser is currently licensed under the terms of the Apache License (Version 2.0). See LICENSE for details. Test data included from the llvm-project residing in tests/data retains the llvm license. See the llvm-project for details.

llvm-profparser's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

llvm-profparser's Issues

Fails to parse Windows ARM llvm-profraw files

Hello,

We use tarpaulin to calculate code coverage and have recently began running our CI piplines with Windows ARM CI runners (In addition to standard Windows / Linux runners). The package is tested and code coverage is calculated fine on all runners except for our Windows-ARM runners with the same error as reported in xd009642/tarpaulin#1282.

I'm not sure if it is in issue with your custom profparser, or if Windows-ARM generates a bad profraw file, so I've attached the profraw file that is being parsed when we end up seeing the error:

INFO cargo_tarpaulin::statemachine::instrumented: Merging coverage reports
ERROR cargo_tarpaulin: Parsing failed

**Update, can't attach the profraw file, so you can access it in a temporary repo I uploaded it to: https://github.com/Javagedes/testing123

LLVM 17/18 proftext parsing failure

I don't care a great deal about these because they're not something tarpaulin requires, but it would be generally nice to fix them. For llvm 17 and 18 I've removed the following test vector from proftext parsing:

flatten_instr.proftext:

# IR level Instrumentation Flag
:ir
# Always instrument the function entry block
:entry_first
foo
# Func Hash:
1111
# Num Counters:
5
# Counter Values:
10000
50
2000
40
6000

bar.cc:bar
# Func Hash:
2222
# Num Counters:
10
# Counter Values:
0
0
0
0
0
0
0
0
0
0

Fails to build on i386 and armv7: the trait bound `u64: ToUsize` is not satisfied

error[E0277]: the trait bound `u64: ToUsize` is not satisfied
   --> /wrkdirs/usr/ports/devel/tarpaulin/work/tarpaulin-0.23.1/cargo-crates/llvm_profparser-0.3.0/src/instrumentation_profile/raw_profile.rs:308:35
    |
308 |             let (bytes, _) = take(header.padding_bytes_before_counters)(input)?;
    |                              ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `ToUsize` is not implemented for `u64`
    |                              |
    |                              required by a bound introduced by this call
    |
    = help: the following other types implement trait `ToUsize`:
              u16
              u32
              u8
              usize
note: required by a bound in `nom::bytes::complete::take`
   --> /wrkdirs/usr/ports/devel/tarpaulin/work/tarpaulin-0.23.1/cargo-crates/nom-7.1.1/src/bytes/complete.rs:408:6
    |
408 |   C: ToUsize,
    |      ^^^^^^^ required by this bound in `nom::bytes::complete::take`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `llvm_profparser` due to previous error

rust-1.66.1
FreeBSD 13.1

New similarity testing method

Parse the profile data. Write it out into the text format. Load both text formats into the internal struct and then use the Eq operator.

Or merge them all into profdata, load and then do the same. Either way it's the same method. (Maybe do both?)

Implement LLVM 13 support

As the issue title states, LLVM 13 changes the coverage format again, get new test vectors, add to deserializer of profraw and go go go

Index out of bounds when parsing profdata

I tried to use cov show as a replacement for llvm-cov show on the example C++ program from https://clang.llvm.org/docs/SourceBasedCodeCoverage.html but encountered the following panic:

thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 7', src/coverage/coverage_mapping.rs:514:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panicking.rs:142:14
   2: core::panicking::panic_bounds_check
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panicking.rs:84:5
   3: llvm_profparser::coverage::coverage_mapping::parse_counter
             at ./src/coverage/coverage_mapping.rs:514:13
   4: llvm_profparser::coverage::coverage_mapping::parse_mapping_regions
             at ./src/coverage/coverage_mapping.rs:386:31
   5: llvm_profparser::coverage::coverage_mapping::parse_coverage_functions
             at ./src/coverage/coverage_mapping.rs:332:17
   6: llvm_profparser::coverage::coverage_mapping::read_object_file::{{closure}}
             at ./src/coverage/coverage_mapping.rs:70:18
   7: core::option::Option<T>::map
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/option.rs:929:29
   8: llvm_profparser::coverage::coverage_mapping::read_object_file
             at ./src/coverage/coverage_mapping.rs:67:19
   9: llvm_profparser::coverage::coverage_mapping::CoverageMapping::new
             at ./src/coverage/coverage_mapping.rs:107:31
  10: cov::ShowCommand::run
             at ./src/bin/cov.rs:46:23
  11: cov::main
             at ./src/bin/cov.rs:75:35
  12: core::ops::function::FnOnce::call_once
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/ops/function.rs:248:5

I know your project is mostly targeted for parsing profiling data from rust programs but since the coverage mapping format is the same it should work universally for other profdata too. Right?

Here are my steps to reproduce:

cd /tmp
git clone https://github.com/xd009642/llvm-profparser.git
cd llvm-profparser

cat <<EOF > foo.cc
#define BAR(x) ((x) || (x))
template <typename T> void foo(T x) {
  for (unsigned I = 0; I < 10; ++I) { BAR(I); }
}
int main() {
  foo<int>(0);
  foo<float>(0);
  return 0;
}
EOF

clang++ -fprofile-instr-generate -fcoverage-mapping foo.cc -o foo
LLVM_PROFILE_FILE="foo.profraw" ./foo
llvm-profdata merge -sparse foo.profraw -o foo.profdata

# Works
llvm-cov show ./foo -instr-profile=foo.profdata

# Works not
RUST_BACKTRACE=1 cargo run --bin cov -- show --instr-profile foo.profdata --object ./foo

OS: Arch Linux
Clang/LLVM version: 14.0.6

Any help to debug this further is highly appreciated!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.