Is it possible to disable branch coverage generation?

Branch coverage was introduced with LLVM 12 ([Coverage] Add support for Branch Coverage in LLVM Source-Based Code … · llvm/llvm-project@9f2967b · GitHub).

But if I understand that diff and current behavior correctly:

  1. There is no option to disable this new information from being added to the .profraw files resulting from a coverage run.
  2. There is no option in llvm-cov to skip the exporting of this information. (I wonder if -skip-branches would be a useful addition, analagous to the existing -skip-functions.)

I want to be sure about #1 though: if one knows that branch coverage information will not be considered later, is it possible to entirely skip generating it in the first place?

Thanks!

Tagging @evodius96 (author of the patch I mentioned above).

Hi @justincady!

So branch coverage is largely built based on existing counter data, so it’s not possible to prevent only branch covered information from being added to the .profraw files. By default, it is not enabled in the llvm-cov source-level file view ("llvm-cov show"), and while it is on by default in the report ("llvm_cov report"), it can be disabled using --show-branch-summary=false

When you refer to llvm-cov 'exporting, are you referring to lcov or json exporting (via “llvm_cov export”)? Presently it is always included there, although we could conceivably introduce an option to prevent that. But it is just considered data that can be ignored by LCOV or a json parser, so I’m not sure I see the value in adding an option like that.

Are you concerned about Branch Coverage adding more memory overhead than you need? It should be fairly minimal overhead compared to region coverage, although there are limited cases in which we could reduce the number of counters required.

Sorry, just saw your reference to --skip-functions, which is used with llvm_cov export. I do think it would be very straightforward to add something like that for branch coverage.

Thanks, @evodius96!

When you refer to llvm-cov 'exporting, are you referring to lcov or json exporting (via “ llvm_cov export ”)?

The use case that brought this question about was llvm-cov export -format lcov. But as you addressed, I was also concerned about the data generation (e.g. the profraw itself). Specifically…

Are you concerned about Branch Coverage adding more memory overhead than you need? It should be fairly minimal overhead compared to region coverage, although there are limited cases in which we could reduce the number of counters required.

Yes, this was my concern, but your explanation here and noting that it’s built upon existing counter data eases that concern. :slight_smile: Thank you for the details.

Sorry, just saw your reference to --skip-functions, which is used with llvm_cov export . I do think it would be very straightforward to add something like that for branch coverage.

Yes, I do think this option would be useful to have.

Just to further clarify: we ran into issues in which the downstream lcov processing tools are incredibly slow when dealing with a lot of branch coverage data. Hence the request for information about its generation and for that llvm-cov option.

we ran into issues in which the downstream lcov processing tools are incredibly slow when dealing with a lot of branch coverage data. Hence the request for information about its generation and for that llvm-cov option.

OK that’s reasonable! I’m OK to add a --skip-branches option to llvm-cov, but it may be a month or so before I can look into it; I’m also planning to upstream some additional functionality around that time. If you’d like to take a stab at adding it before then, I’d be more than willing to review it!

Sounds great. If I’m able to get to it sooner I’ll send the review your way. :slight_smile:

Thanks!