tags:

views:

20

answers:

2

I have a big C++ project that is built using scons. Its building slow and I want to make some changes to try to make it build faster. Now I'd like to focus my time speeding up the parts of the build that are slowest.

How can I work out which files are taking the longest to compile?

+1  A: 

If you're using LInux, you could wrapper gcc or g++ so that invocations of of the compiler use the gtime utility. Every call to the compiler would look like:

/usr/bin/time /usr/bin/g++ [rest of command]

BASH has some magical syntax that helps you avoid having to re-escape your arguments:

#!/bin/bash -f
PATH_TO_COMPILER_DIR=/usr/bin
/usr/bin/time $PATH_TO_COMPILER_DIR/"$@"

Then point your $PATH variable to have your compiler wrapper.

Then run SCons with only 1 parallel thread via option -j1.

Ross Rogers
+1, Doesn't quite solve the issue in the way I'd like, but it gave me some ideas that I used in my solution.
Michael Anderson
+1  A: 

I solved this by adding some extra stuff to the start of the CXXCOM variable. Scons uses this variable to do the actual compilation:

if os.getenv('BUILD_STYLE')=='timing':
  cxxcom = env['CXXCOM']
  env.Replace( CXXCOM = 'time '+cxxcom )

I then run scons using something like this

BUILD_STYLE=timing scons > timing_log.txt

and finally tidy up the log using some vim macros.

Michael Anderson