I tend to write rather large templated header-only C++ libraries and my users commonly complain about compilation times. After thinking about the matter, it occurred to me that I have no idea where the time is going. Is there some simple way to profile the C++ compilation process with common compilers, such as g++, icc, and xlC? For instance, is it possible to get an idea of how much time is spent within each of the phases of C++ compilation?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Profiling Django with PyCharm
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
You can separate them out to some extent (I'm assuming
make
)-E
switch), and a.PHONY
target that depends on the preprocessor output files just like the normal binary target depends on.o
files. Measure how long it takes to build this target'PHONY
target that depends on all the.o
files but doesn't link them. Measure how long it takes to build this target (from clean)Now you have some idea how long it takes to pre-process, compile, and link. You can also compare optimized and non-optimized (
-O0
) versions of the second and third target, to see how long is spent in the optimizer.There's a tool from the Boost project, which could be useful for pretty much any compiler and build system.
The tool requires source code instrumentation with
TEMPLATE_PROFILE_ENTER()
andTEMPLATE_PROFILE_EXIT()
macro calls. These macros then generate specific diagnostics (warnings) at compile-time, which are timed and collected along with instantiation callstacks (which consequently allow building and visualizing callgraphs) by a script. Not bad, IMO.I didn't use it yet though.
I have not yet tried it, but templight looks VERY promising: https://github.com/mikael-s-persson/templight
You might be able to get some traction with some variant on
strace -e trace=process -f -r -ttt -T
, at least for compilers like g++ that are broken up into many processes.For GCC there are debugging options to find
how much time is spent within each of the phases of C++ compilation?
Passes are described in GCCINT 9: Passes and Files of the Compiler.
You can post output of g++ compilation of single source file with
-v -ftime-report
here to discuss it. There could be some help on the GCC mailing list.For compilers other than GCC (or GCC more ancient than 3.3.6) see the other options in this thread.