linux-test-project / lcov

LCOV
GNU General Public License v2.0
888 stars 236 forks source link

Add option to collapse function with template as a single function in report #164

Open Matti-Lehtonen opened 1 year ago

Matti-Lehtonen commented 1 year ago

Add some option to report functions with template as single function in generated (html) reports

template <class type>
type sum( type x, type y) {
  return x+y;
}

int main() {
  auto result1 = sum(0u,1u);
  auto result2 = sum(0.0f,1.0f);
  auto result3 = sum(0.0,1.0);
  exit(0);
}

So instead of having a coverage report with three (3) functions of sum, actually report with single sum function would be preferred.

henry2cox commented 1 year ago

I actually implemented that 😊 I called them ‘function aliases” – enabled by adding “--filter function” to your genhtml command line. It decides that two names are aliases if they have the same file and line location. The ‘leader’ is the shortest name (fewest characters); tie break uses alphabetic sort. I recommend you use “—cpp-demangle” for C++ code, to get more meaningful names (and better sorting).

You can find that feature as well as several others at https://github.com/henry2cox/lcov/tree/diffcov_initial (Pull request in progress – but not yet merged to lcov master.)

Hope this helps

Henry

Matti-Lehtonen commented 1 year ago

Thanx!

Matti-Lehtonen commented 1 year ago

Hi,

just my two cents ..

There are at least two "methods" to create function aliases, like

  1. GCC's function alias attribute. There reporting the shortest name is suitable.
  2. However, use of templates (especially nested templates) probably will cause nasty and long function names, even if the shortest one is picked. If the function name has a pattern indicating the existence of use of template, could all templates just be replaced with "<...>" string?

Matti L

On Thu, 8 Sept 2022 at 18:01, Henry Cox @.***> wrote:

I actually implemented that 😊 I called them ‘function aliases” – enabled by adding “--filter function” to your genhtml command line. It decides that two names are aliases if they have the same file and line location. The ‘leader’ is the shortest name (fewest characters); tie break uses alphabetic sort. I recommend you use “—cpp-demangle” for C++ code, to get more meaningful names (and better sorting).

You can find that feature as well as several others at https://github.com/henry2cox/lcov/tree/diffcov_initial (Pull request in progress – but not yet merged to lcov master.)

Hope this helps

Henry

— Reply to this email directly, view it on GitHub https://github.com/linux-test-project/lcov/issues/164#issuecomment-1240840179, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQRA3ICDAH4IKAEQQREUT6LV5H5UNANCNFSM6AAAAAAQH2QFSQ . You are receiving this because you authored the thread.Message ID: @.***>

henry2cox commented 1 year ago

That seems like a good idea.

The simple scheme won’t work quite right when there is template specialization:

Yet another issue is that this feature would need to be tested quite thoroughly – to make sure that there is no mis-attributed or dropped code. Internally, we use the tool with some moderately large projects, and it would be very, very hard to manually review to make sure nothing of importance changed. I’m also not sure how many of the special scenarios happen in our code – so I need tests which explicitly trigger those cases…and then hope that there are no other scenarios that I didn’t think of. ☹

An additional complication is that the featrue needs to work for systemverilog. Offhand, I’m not sure what the implications are. Again – the easiest hack would be to just turn off this transform unless we are sure that this is C++ source code.

Unless you object strongly, I’m going to shelve this enhancement request for the moment. I’ll put a “todo” comment in the source – and may get back to it one d If you feel like trolling through the code to implement this yourself…I certainly would not say “no” 😊

Henry

liuluheng commented 1 year ago

@henry2cox any update for this? Is the “--filter function” feature can be merged to master?

henry2cox commented 1 year ago

The basic 'function alias' feature described above was merged to master many months ago, and was released in lcov 2.0 back in May. The feature requested here (more careful handling of template naming and template aliases) is more complicated and has not been done (at least, not by me). Depending on what you are trying to do, the existing implementation may or may not be sufficient. If not: please try to explain what you need; it is possible that your requirement is different than @Matti-Lehtonen, and interesting to others as well. You might also want to take a look at the --show-proportion flag - which is also related to function coverage (but not to aliasing).