0

I use CMake to generate some makefiles that will compile multiple targets using G++ on Linux. I would like to create some metrics about the compilation such as :

  • Time needed to build each target
  • G++ warnings and errors

The only solution I came up with so far is to redirect the output of make and parse the whole file but this seems really heavy. I cannot use the G++ flag -fdiagnostics-format=json feature since I cannot upgrade to GCC-9.

Any suggestions? Thank you very much

2 Answers2

1

As far as timing is concerned, consider using Ninja instead of Make. When you build it produces a file called ${CMAKE_BINARY_DIR}/.ninja_log that can be converted to a format compatible with Chrome's about:tracing flame graph format.

There's a script for doing that here: https://github.com/nico/ninjatracing

Alex Reinking
  • 16,724
  • 5
  • 52
  • 86
  • 1
    I think this is what I am looking for, thank you !! I'll try this out right away and keep you posted. :) – ElCactouss Jul 04 '22 at 13:58
  • I've managed to generate the json from the ninja_logs file but I apparently cannot use ninja either because the compilation order is not supported by CMake according to this post https://stackoverflow.com/questions/55225997/manipulate-build-order-for-independent-targets-in-ninja-cmake, but thank you for your suggestion it's much appreciated – ElCactouss Jul 04 '22 at 19:47
0

Something you could do is set the compiler to be a program or shell script that wraps the G++ functionality and add some (similar to how some ccache integrations work):

# Makefile
CC := g++-with-metrics.sh
# g++-with-metric.sh

# 1. Start timer

# 2. Run command, save output (to variable or tmpfile)

# 3. Stop timer, log result

# 4. Parse output for warnings and errors, log result
Andreas
  • 5,086
  • 3
  • 16
  • 36