Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiling compilation time

Tags:

c++

build

I have a C++ code which I am compiling using VC7 and it is taking a lot of time to build it. Is there any way I could profile it and find why it is taking time to build ?

like image 458
Naveen Avatar asked Feb 17 '09 10:02

Naveen


People also ask

Why does compilation take so long?

Header files Every single compilation unit requires hundreds or even thousands of headers to be (1) loaded and (2) compiled. Every one of them typically has to be recompiled for every compilation unit, because the preprocessor ensures that the result of compiling a header might vary between every compilation unit.

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 is the meaning of compile time?

In computer science, compile time (or compile-time) describes the time window during which a computer program is compiled. The term is used as an adjective to describe concepts related to the context of program compilation, as opposed to concepts related to the context of program execution (runtime).


6 Answers

In Visual Studio 2008, there's a setting for turning on build timing. It might be there in VC7 as well...

Tools / Options / Projects and Solutions / VC++ Project Settings / Build Timing: Yes

This applies to C++ projects, which (as of VS2008) don't use MSBuild. For MSBuild-based projects (such as C#), you want to increase the verbosity:

Tools / Options / Projects and Solutions / Build and Run / MSBuild project build output verbosity

By default, it's set to "Minimal".

like image 117
Roger Lipscombe Avatar answered Oct 04 '22 20:10

Roger Lipscombe


If the code is template-intensive, then you could try doing the template instantiation profiling. Steven Watanabe came up with the profiler and if I remember correctly it was supposed to work with VS (don't know the version).

like image 27
Anonymous Avatar answered Oct 04 '22 21:10

Anonymous


Recent Microsoft's C++ Build Insights SDK has introduced an option /timetrace to its vcperf which allows you to profile your build and visualise the build times of specific components in form of a flame graph inside of any chromium-based browser.

Assuming you have vcperf downloaded and installed, you need to:

  1. Start its session by executing
vcperf /start SessionName
  1. Run your build (the events are captured system-wide by vcperf)
  2. Stop the session
vcperf /stop SessionName /timetrace output.json

You can now run your chromium-based browser, type in <browser_name>://tracing, (for example chrome://tracing) and load up the output.json file for visualisation.

Example visualisation taken from here.

like image 37
Sand3r Avatar answered Oct 04 '22 22:10

Sand3r


Is the source code on a network? This sometimes slows the compilation a lot.

like image 25
Toon Krijthe Avatar answered Oct 04 '22 21:10

Toon Krijthe


My guess is that it would be difficult to get useful results from profiling. You could look at the create times of each .obj file and check if there are any files that are particularly slow, but I doubt this would be the case.

Have you gone through the compiler options such as pre-compiled headers to see what improvements ths provides? Similarly, turning off the optimizer where it is not required can speed the build up significantly. My advice would be to take some time to try out a few 'what if' scenarios.

like image 21
SmacL Avatar answered Oct 04 '22 20:10

SmacL


If your code makes extensive use of template, you might be interested in Templight, a tool developed by a hungarian research team for debugging and profiling C++ template metaprograms (paper). It seems very promising, but I'm not sure the tool is available for download...

like image 44
Luc Touraille Avatar answered Oct 04 '22 22:10

Luc Touraille