microsoft / vcperf

A build analysis tool for the MSVC toolchain.
MIT License
296 stars 35 forks source link

Evaluate total impact of template library #24

Open stgatilov opened 3 years ago

stgatilov commented 3 years ago

First of all, thank you very much for C++ Build Insights! I had to analyze build times in the past, but usually had to estimate template issues using object files (with SymbolSort).

I have a project, where Eigen template library was added recently. I'm trying to understand how much build time its template code takes. The same question can be asked for std:: code, boost:: or any other template library.


Parsing library headers is easy to take into account: open "Files" view, filter table data by "Included Path" containing "Eigen" as substring, then look at "Exclusive Duration" of root node "Parsing". Unfortunately, it is not easy to do the same for template instantiations.

First of all, vcperf removes some template instantiations, as noticed in https://github.com/microsoft/vcperf/issues/16. As far as I understand, the raw trace contains all template instantiations, but the analysis removes small ones to make analyzed trace smaller and more responsive when opened in WPA. I worked around this problem by hacking ExpensiveTemplateInstantiationCache::DetermineTopPrimaryTemplates.

Second, only "Duration" is displayed for template instantiations in WPA. It is inclusive, so it cannot be aggregated. I can workaround it by replacing td.WallClockTimeResponsibility with td.ExclusiveDuration in TemplateInstantiationsView::OnTemplateInstantiationStart. Perhaps ExclusiveCPUTime makes even more sense here.

The last inconvenience is that I don't know how to compute sum of column value over all selected/filtered entries in WPA table (except for copying everything to csv and writing simple script). The "Files" view allows summation by having "Activity Name" = "Parsing" key column, but there is no such column in "Template Instantiations" view. Perhaps the most useful additional key column would be "root namespace" (prefix of "Primary Template Name" before ::) like "Eigen", "std" or "boost".


Is it possible to configure the columns displayed in WPA views? I see that I can add more fields in vcperf code, but WPA does not display them. I tried editing CppBuildInsightsEtw.xml, but it did not help.

P.S. I guess the best approach would be to write a custom analyzer which will aggregate data on-the-fly, without creating massive traces with all template instantiations.

stgatilov commented 3 years ago

I implemented a custom analyzer for the purpose in my fork. It filters parsing/instantiation activities by wildcard and displays total time.

In the end, it was rather simple to write the code, although I'm not sure I did everything correctly...

helena-gregg commented 3 years ago

This looks great! What parts do you think might be incorrect? If this would be useful to lots of users, we might want to add this into the product.

stgatilov commented 3 years ago

For example, if you look at readme, you will see three numbers in reports. The first two numbers should match in theory, but they don't match in reality. Somehow, exclusive time is not equal to inclusive time minus inclusive time or all children (common parts?) I must admit that the whole inclusive/exclusive thing is a bit complicated, and it is easy to make an error somewhere.