Skip to content

[llvm-cov] 'llvm-cov show' output for template functions with lots of instantiations is overwhelming #134927

Open
@bartlettroscoe

Description

@bartlettroscoe

Description

As of LLVM 20.1, the llvm-cov show command produces an overwhelming amount of output in the HTML file if there are a lot of template instantiations. Even if there are not a large number of template instantiations, the HTML file is still very hard to follow. For example, for the Trilinos C++ file Teuchos_RCP.hpp, if you only build and run the Teuchos test suite, you get a fairly reasonable output HTML file Teuchos_RCP.html (see reduced version for just the lines 121-149 attached) which looks like:


Image


See full image here. As you see in that image, just with three instantiations, the main template function is obscured by the template instantiations.

But when you have lot of template instantiations, the HTML file becomes completely unreadable. When you build and run the entire Trilinos test suite, the generated file Teuchos_RCP.html becomes about impossible to follow with over 150 instantiations (see reduced version for just the lines 121-149 attached) which looks like:


Image


(I can't show all of the branches for even the first if() statement!.)

And if you consider that fact that there are over 150 instantiations of this function, trying to figure out where you are in the source file is about impossible.

Now, compare that to the gcovr produced coverage for LLVM clang using the gcov-comparible coverage using --coverage and the tool llvm-cov gcov for the same builds of and test suites. Running gcovr -r <src-dir> --object-directory . --gcov-executable="llvm-cov gcov" --txt-metric branch --gcov-ignore-parse-errors=suspicious_hits.warn_once_per_file --html-nested <output-file> produces coverage for Teuchos_RCP.hpp (see attached) that looks like:


Image


Notice how you don't get any clutter for the template instantiations at all. The file is very easy to follow. However, the branch coverage is confusing and may not even be correct, a shown by:


Image


However, those branches don't make a lot of sense to me. The description of branch coverage with llvm-cov show with the source-based coverage is much more logical and direct (IMHO). (Which is one reason I want to use the newer source-based coverage over the older gcov-compatible coverage and gcovr.)

Suggested solution

We can have our cake and eat it too. All we need to do is to have llv-cov show wrap the branch and line coverage details inside of <details> ... </details> blocks. For example, taking the direct output from llvm-cov show shown here and adding <details> ... </details> blocks by applying this diff gives you the new HTML file shown here showing:


Image


NOTE: I manually computed the combined branch coverage counts for the different instantiations. The real implementation would do this automatically.

Now you can expand and contract the branch coverage like:


Image


and:


Image


And you can expand the template instantiations like:


Image


Now, applying this to the Teuchos_RCP.hpp.html file that has over 130 template instantiations you get the file the attached file which looks like:


Image


And as you can see, the page Teuchos_RCP.hpp is very easy to read. And you can expand whatever details you want to see for specific instantiations.

All files

A tarred-gziped directory of all of the files mentioned above, and more, is attached.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions