# Measuring the times while building

**URL:** https://discourse.cmake.org/t/measuring-the-times-while-building/3660
**Category:** Usage
**Created:** [June 30, 2021, 7:13am UTC](https://discourse.cmake.org/t/measuring-the-times-while-building/3660 "2021-06-30T07:13:55Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![NeoCortex97](https://discourse.cmake.org/user_avatar/discourse.cmake.org/neocortex97/32/1599_2.png) [@NeoCortex97](https://discourse.cmake.org/u/NeoCortex97)
#### Post date: [June 30, 2021, 7:13am UTC](https://discourse.cmake.org/t/measuring-the-times-while-building/3660/1 "2021-06-30T07:13:55Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [June 30, 2021, 1:02pm UTC](https://discourse.cmake.org/t/measuring-the-times-while-building/3660/2 "2021-06-30T13:02:58Z")

</div>

> [@NeoCortex97](#):
>
> 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).

---

<div class="post-metadata">

### Author: ![NeoCortex97](https://discourse.cmake.org/user_avatar/discourse.cmake.org/neocortex97/32/1599_2.png) [@NeoCortex97](https://discourse.cmake.org/u/NeoCortex97)
#### Post date: [June 30, 2021, 9:12pm UTC](https://discourse.cmake.org/t/measuring-the-times-while-building/3660/3 "2021-06-30T21:12:56Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [July 1, 2021, 8:58am UTC](https://discourse.cmake.org/t/measuring-the-times-while-building/3660/4 "2021-07-01T08:58:33Z")

</div>

> [@NeoCortex97](#):
>
> And I want to get this information Independent if I am using ninja, make or something else

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

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [July 1, 2021, 4:46pm UTC](https://discourse.cmake.org/t/measuring-the-times-while-building/3660/5 "2021-07-01T16:46:21Z")

</div>

This one gets the information at least: [GitHub - nico/ninjatracing: Convert .ninja\_log files to chrome's about:tracing format.](https://github.com/nico/ninjatracing)

Getting useful graphs from `about:tracing` can be more difficult (it crashed on some particularly large builds I’ve tried), but [the `catapult` project](https://github.com/catapult-project/catapult/tree/master/tracing) is what you should look for there.

---

<div class="post-metadata">

### Author: ![NeoCortex97](https://discourse.cmake.org/user_avatar/discourse.cmake.org/neocortex97/32/1599_2.png) [@NeoCortex97](https://discourse.cmake.org/u/NeoCortex97)
#### Post date: [July 1, 2021, 5:55pm UTC](https://discourse.cmake.org/t/measuring-the-times-while-building/3660/6 "2021-07-01T17:55:53Z")

</div>

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

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [July 1, 2021, 9:03pm UTC](https://discourse.cmake.org/t/measuring-the-times-while-building/3660/7 "2021-07-01T21:03:14Z")

</div>

You might want to use [`<LANG>_COMPILER_LAUNCHER`](https://cmake.org/cmake/help/latest/prop_tgt/LANG_COMPILER_LAUNCHER.html) to wrap the compiler call with the time measurement.

---

<div class="post-metadata">

### Author: ![jtxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jtxa/32/1535_2.png) [@jtxa](https://discourse.cmake.org/u/jtxa)
#### Post date: [July 2, 2021, 12:49am UTC](https://discourse.cmake.org/t/measuring-the-times-while-building/3660/8 "2021-07-02T00:49:15Z")

</div>

If clang \>= 9 is an option, the [ClangBuildAnalyzer](https://github.com/aras-p/ClangBuildAnalyzer) produces a nice summary. Listing which modules, headers, functions or templates were the most expensive ones.

---

<div class="post-metadata">

### Author: ![NeoCortex97](https://discourse.cmake.org/user_avatar/discourse.cmake.org/neocortex97/32/1599_2.png) [@NeoCortex97](https://discourse.cmake.org/u/NeoCortex97)
#### Post date: [July 2, 2021, 6:11am UTC](https://discourse.cmake.org/t/measuring-the-times-while-building/3660/9 "2021-07-02T06:11:59Z")

</div>

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.
