Analyze configure times with cmake

Notes published the
1 minute to read, 182 words
Categories: c c++
Keywords: JSON c c++ cmake profiling

With clang it is possible to analyze the build times in great details thanks to -ftime-trace.

But while building a program, the compiler (and linker), are not the only processes that can take a lot of time.

Configuring a project, executing custom scripts for generating code, or simply detecting dependencies between targets, can be time-consuming.

While most pieces of advice written for clang are also true for CMake (verify if antivirus is interfering, remove dead code, …​), it does not change the fact that it is hard to know in advance how useful they are.

Since cmake 3.18 CMake supports the switches --profiling-format and --profiling-output.

For most use cases, when configuring a CMake project, adding --profiling-format=google-trace --profiling-output=perfcmake.json as parameters will let CMake generate a file named perfcmake.json.

This file contains a detailed overview of how much time is spent executing a single program. As CMake is mostly single-threaded (and it is by design), the data is easy to analyze. This makes it possible to understand where it makes sense to spend some time to try to optimize your configure time.

Do you want to share your opinion? Or is there an error, some parts that are not clear enough?

You can contact me anytime.