2

Is there a way to get a summary of the instantiated templates (with what types and how many times - like a histogram) within a translation unit or for the whole project (shared object/executable)?

If I have a large codebase and I want to take advantage of the C++11 extern keyword I would like to know which templates are most used within my project (or from the internals of stl - like std::less<MyString> for example).

Also is it possible to have a weight assigned to each template instantiation (time spent by the compiler)?

Even if only one (c++11 enabled) compiler gives me such statistics I would be happy.

How difficult would it be to implement such a thing with Clang's LibTooling?

And is this even reasonable? Many people told me that I can reason which template instantiations I should extern without the use of a tool...

onqtam
  • 4,356
  • 2
  • 28
  • 50

1 Answers1

1

There are several ways to attack this problem.

If you are working with an open-source compiler, it's not hard to make a simple change to the source code that will trace all template substantiations.

If that sounds like too much hassle, you can also try to force the compiler to produce a warning on each template instantiation for a given symbol. Steven Watanabe has written a set of tools that can help you with that.

Finally, possibly the best options is to use the debugging symbols (or map files), generated by the compiler, to track down how many times each function appears in the final image and more importantly how much does it add to the weight in bytes. The best example for such a tool is Andrian Stone's SymbolSort, which is based on the Microsoft's toolset. Another similar tool is the Map File Browser.

zah
  • 5,314
  • 1
  • 34
  • 31
  • Hmmm seems nothing has changed since [this question](http://stackoverflow.com/questions/11403417/automatically-count-the-number-of-instantiated-classes-in-a-tmp) ... – onqtam Oct 14 '14 at 12:20