Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging GCC Compile Times [duplicate]

Tags:

c++

gcc

I'm creating a fairly large library in C++(0X) using gcc4.6 in linux. My library relies heavily on template classes, resulting in long compile times for applications which use the library. I would like to start speeding things up by providing explicit instantiations of the worst offending types/methods.

Is there a way to have gcc report the time spent compiling various types/methods so that I can apply my explicit instantiations in a principled way, rather than through intuition?

like image 862
rcv Avatar asked Jun 17 '11 19:06

rcv


People also ask

What is the O flag in gcc?

It indicates the output file, i.e. what your object-file or executable should be. You can see this information by doing gcc --help or man gcc .

How do you specify compiler optimizations in gcc?

GCC has a range of optimization levels, plus individual options to enable or disable particular optimizations. The overall compiler optimization level is controlled by the command line option -On, where n is the required optimization level, as follows: -O0 . (default).

How do I debug with gcc?

Basic UsageAll program to be debugged in gdb must be compiled by gcc with the option "-g" turning on. Continue with the "garbage" example, if we want to debug the program "garbage", we can simply start gdb by: gdb ./garbage.

What does optimization flag do?

Turning on optimization flags makes the compiler attempt to improve the performance and/or code size at the expense of compilation time and possibly the ability to debug the program. The compiler performs optimization based on the knowledge it has of the program.


2 Answers

g++ some_file.cc -ftime-report

will give you a rough estimate of time spent in different compiler phase. Most important ones in your case are name lookup and parsing.

No way to get a per class/function compile time alas.

STeven Watanabe has proposed a template profiler , available in boost sandbox that helps getting the number of potential instantiation of anything in a .cc

like image 90
Joel Falcou Avatar answered Sep 18 '22 17:09

Joel Falcou


I know that it's not what you're looking for, but maybe ccache/distcc may help to speed up compilation.

Also if you have multi core machine you may exploit make -jN to tell make run N jobs at once.

Don't forget about precompiled headers too.

like image 42
dimba Avatar answered Sep 21 '22 17:09

dimba