<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/134927>134927</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[llvm-cov] llvm-cov show output for template functions with lots of instantiations is overwhelming
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bartlettroscoe
</td>
</tr>
</table>
<pre>
## 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](https://github.com/trilinos/Trilinos/blob/master/packages/teuchos/core/src/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](https://github.com/user-attachments/files/19654776/llvm-cov_show.Teuchos_RCP.hpp.reduced.html.txt) which looks like:
----

----
See full image [here](https://github.com/user-attachments/assets/04402892-3158-4e5f-b888-a12c2e8420d6). 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](https://github.com/user-attachments/files/19656287/llvm-cov_show.Teuchos_RCP.hpp.all_packages.reduced.html.txt) which looks like:
----

----
(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 --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:
----

----
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:
----

----
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 hear [attached](https://github.com/user-attachments/files/19654776/llvm-cov_show.Teuchos_RCP.hpp.reduced.html.txt) and adding `<details> ... </details>` blocks by applying [this diff](https://github.com/user-attachments/files/19656401/llvm-cov_show.Teuchos_RCP.hpp.reduced.collapsible.html.diff.txt) gives you the new HTML file shown [here](https://github.com/user-attachments/files/19656409/llvm-cov_show.Teuchos_RCP.hpp.reduced.collapsible.html.txt) showing:
----

----
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:
----

----
and:
----

----
And you can expand the template instantiations like:
----

----
Now, applying this to the `Teuchos_RCP.hpp.html` file that has over 130 template instantiations you get the file the [attached file](https://github.com/user-attachments/files/19656556/llvm-cov_show.Teuchos_RCP.hpp.all_packages.reduced.collapsible.html.txt) which looks like:
----

----
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.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMWNtu3DgS_Rr6hWBDou4PfvAljQkwl8VMsHk0KKrU4pgiBZJyp_9-UVRf3O12sjuZYPYhSFsSyWLVOacOKbxXGwNwS4p7UjzeiDkM1t22wgUNITjrpYWb1na7W8IzwjP6CF46NQVlDUnuSHJ356nt6c8___sXypNVSvgDDQNQUiZav4xM2hfqB7slZUKlHUdhOjo5280SPBWG2hdw2wH0qMyGitHOJuB8dg7THKgycbKfPv3yM-2VBqp6fOCACvxHtY1fBxgnLQJQZXwQ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