Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to measure compile time per object in CMake?

I'm searching for tool that helps calculate compilation time using CMake. Target project builds a lot of files, so I need to craft some "table" per each module. For example, project consists of 2 files - main.cc and libs.cc I need to calculate build time for libs and main differently.

I'm trying to set wrapper for g++, but in make -j4 it has some "race condition". Strings with Building status and building time are crossing.

.......
[  3%] Building CXX object irohad/simulator/CMakeFiles/block_creator_common.dir/block_creator_common.o
0.12    1.42
[  4%] Building CXX object schema/CMakeFiles/yac_grpc.dir/yac.grpc.pb.o
0.13    1.36
0.10    0.71
.......

Set new "Compiler" - wrapper for g++

#!/bin/bash
{ /usr/bin/time -f "%S\t%U" g++ "$@"; } 2> >(cat <(echo "g++ $@") - | cat)

and then

cmake -H. -Bbuild -DCMAKE_CXX_COMPILER=/path/to/script.sh
make | tee -a buildResults.txt


like image 946
Alexey Rodionov Avatar asked Oct 24 '25 02:10

Alexey Rodionov


2 Answers

Please try adding following lines in the cmake, to measure time you can compile with single cpu and then run in parallel mode

set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time")

set_property(TARGET <your target> PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time")

replace per your project name.

Hope this helps.

like image 76
sbh Avatar answered Oct 26 '25 17:10

sbh


you can try this

set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time") set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CMAKE_COMMAND} -E time")

like image 30
Mirror Avatar answered Oct 26 '25 17:10

Mirror