Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I profile a complete C++ build?

I'm developing an application in C++ on Windows XP, using Eclipse as my IDE, and a Makefile-based build system (with custom tools to generate the Makefiles). In addition, I'm using LZZ, which allows me to write a single file, which then gets split into a header and an implementation file. I'm using TDM's port of GCC 4.

What tools or techniques could I use to determine exactly how much time each part of the build process takes, and why it is slow?

Of particular interest would be:

  • How much time does make need to figure out to parse the Makefiles, figure out the dependencies, check the timestamps, etc?
  • How much time does Eclipse need before and after the build?
  • How much time does GCC spend on parsing system and boost headers?

P.S.: This is my home project, so expensive tools are out of reach for me, but could be documented here anyway if they are particularly relevant.

like image 924
Carl Seleborg Avatar asked Jan 27 '10 20:01

Carl Seleborg


People also ask

What are the 4 phases of building C code in order?

Compiling a C program is a multi-stage process. At an overview level, the process can be split into four separate stages: Preprocessing, compilation, assembly, and linking.


1 Answers

Since Make and GCC are very verbose about what they're doing, a very crude way to get a high-level overview of time spent is to pipe make's output through a script that timestamps each line:

make | perl -MTime::HiRes -pe "printf '%.5f ', Time::HiRes::time()"

(I'm using ActivePerl to do this, but from what I gather, Strawberry Perl may now be the recommended Perl version for Windows.)

Reformat or process the timestamps to your liking.

To get more details about GCC in particular, use the --time-report option.

To find out how much overhead Eclipse adds, use a stopwatch to time builds from Eclipse and from the command line.

like image 116
Josh Kelley Avatar answered Sep 19 '22 00:09

Josh Kelley