Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiling the C++ compilation process

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?

like image 491
Jack Poulson Avatar asked Nov 26 '12 06:11

Jack Poulson


People also ask

What is C compilation process?

Compilation process in C is also known as the process of converting Human Understandable Code (C Program) into a Machine Understandable Code (Binary Code)) Compilation process in C involves four steps: pre-processing, compiling, assembling, and linking.

What are the 3 steps of the compilation process?

There are three basic steps involved in compiling a C program: preprocessing, compilation of C source code to machine code (or assembly) (also called object code), and linking of multiple object files into a single binary executable program.

What are the four stages of the compilation process?

The compilation process can be divided into four steps, i.e., Pre-processing, Compiling, Assembling, and Linking. The preprocessor takes the source code as an input, and it removes all the comments from the source code. The preprocessor takes the preprocessor directive and interprets it.


1 Answers

For GCC there are debugging options to find how much time is spent within each of the phases of C++ compilation?

-Q Makes the compiler print out each function name as it is compiled, and print some statistics about each pass when it finishes.

-ftime-report Makes the compiler print some statistics about the time consumed by each pass when it finishes.

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.

like image 168
osgx Avatar answered Oct 13 '22 22:10

osgx