Measuring the times while building

Is there any practical way to generate build benchmarks? I want them to try and find code that takes time to compile in a huge code base, so I can try to improve the code in question.

Ros catkin does it, so I suppose it would be possible. But my main question is, if it is possible without externally controlling the build.

What do you mean by “externally controlling the build”? Do you mean time ninja or something is not suitable? I think you can extract timings from .ninja_log if you parse it out, but I don’t think other generators have such support (maybe Visual Studio gives per-target timings though).

As far as I know catkin wraps the targets with a script that measures tee times and reports them to an application of some sort.

Since the exact things catkin does are not really documented, everything is a little vague.

But catkin shows a list of targets that are build, when they are build and how long building this target took.

I would prefer having at least the time information as well.

And I want to get this information Independent if I am using ninja, make or something else

I the absolute worst case I write a python script that calls cmake build and parses the command line output in real-time.

There are tools to parse the ninja .ninja_log file to json or chrome’s about:tracing formats.

This one gets the information at least: GitHub - nico/ninjatracing: Convert .ninja_log files to chrome's about:tracing format.

Getting useful graphs from about:tracing can be more difficult (it crashed on some particularly large builds I’ve tried), but the catapult project is what you should look for there.

Okay, I’ll have a look at catapult. Simply parsing ninja outputs is not a valid option, because the thing I am trying is not guaranteed to build with ninja.

Also using --time-trace is way more detailed than I thought.

My goal was to simply get the time the compiler took to compile one of the targets, so I can print it on the comandline

You might want to use <LANG>_COMPILER_LAUNCHER to wrap the compiler call with the time measurement.

If clang >= 9 is an option, the ClangBuildAnalyzer produces a nice summary. Listing which modules, headers, functions or templates were the most expensive ones.

I found the clangBuildAnalyzer on my own and it sounds interesting.

@McMartin thanks for this Tipp. That seems to be what I wanted originally posting this question.

I am going to supply both options.