A C++ Template Metaprogram Debugger and Profiler
Welcome to the website of Templight. This is a clang patch which makes the compiler capable of tracing template instantiations. You may also be interested in Templar and ProfileDataViewer client tools. These GUI applications let you analyse the content of the trace file. A Youtube video from C++Now 2013, Aspen, Co on debugging and profiling C++ template metaprograms by Zoltán Porkoláb.
Some repository soon will be available. Until then:
First you have to download the templight patch appropriate to the clang version you want to use. Currently we support clang version 3.2 and 3.3.
To download and build clang see Getting Started: Building and Running Clang. Note also that Python is needed for running the test suite. Get it at: http://www.python.org/download
Checkout LLVM:
Now you can trace the template instantiations and memoizations during compilation. Doing so you have to add the -templight compiler switch to your build command.
Flag for tracing template instantiations
Format of Templight output file (yaml/xml/text, default is yaml)
Flag for tracing memory usage during template instantiations
Write Templight output to file
For flushing Templight trace immediately instead of store the trace in a buffer. This can lead to greater distortion but can be useful when the compiler crashes.
Tracing template instantiations to standard output. You can use templight as a unix filter when use this flag together with -templight-safe-mode.
Set the capacity of internal template trace buffer. The default value is 500.000 events. To minimize distortion Templight does not increase internal buffer during execution.
After that you will have a foo.cpp.trace.xml next to foo.cpp. We call this XML file a trace file, and it is not really meant for human readers.
If you are interested in the memory usage of the compiler during template actions, you can use the following command:
Notice that now you will get a foo.cpp.memory.trace.xml file next to foo.cpp. The scheme is the same but this XML contains the number of dynamically allocated bytes of the compiler at each trace entry.
By default, the trace can contain 500.000 trace events. If it is not enough, you can increase this number:
Trace files are not meant for human readers. We also have GUI tools for analysing the contents of a trace file.
It is our main tool for template debugging. You can analyse the instantiations step-by-step, can set up breakpoints, filter out the irrelevant instantiations, etc.
requirements: Qt 4.6 or newer, Graphviz 2.28.0
It is a Qt-based project. To build it you must enter the directory where the Templar.pro project file is:
Templar does not work with newer versions of Graphviz. Martin Schulze created a modified Templar version working with Qt4/5 and Graphviz 2.34.0 (using CGraph). https://github.com/schulmar/Templar.
It is a proof-of-concept program to view the profiling results. Later it will be integrated in to an other tool. You can analyse the time measurements data with this program.
requirements: Qt 4.6 or newer
It is a Qt-based project. To build it you must enter the directory where the Qt project file is:
The trace generated by templight is an ideal base for implementing your own tools. If you have one, please contact us, we are happy to refer your tool.
Last updated 2013-05-15 11:27:25 CET