I need to figure out which translation units need to be restructured to improve compile times, How do I get hold of the compilation time, using cmake, for my translation units ?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
I would expect to replace the compiler (and/or linker) with 'time original-cmd'. Using plain 'make', I'd say:
The 'time' program would run the command and report on the time it took. The equivalent mechanism would work with 'cmake'. If you need to capture the command as well as the time, then you can write your own command analogous to time (a shell script would do) that records the data you want in the way you want.
Following properties could be used to time compiler and linker invocations:
Those properties could be set globally, per directory and per target. That way you can only have a subset of your targets (say tests) to be impacted by this property. Also you can have different "launchers" for each target that also could be useful.
Keep in mind, that using "time" directly is not portable, because this utility is not available on all platforms supported by CMake. However, CMake provides "time" functionality in its command-line tool mode. For example:
Example CMake output:
Note, that as of CMake 3.4 only Makefile and Ninja generators support this properties.
Also note, that as of CMake 3.4
cmake -E time
has problems with spaces inside arguments. For example:will be interpreted as:
I submitted patch that fixes this problem.
To expand on the previous answer, here's a concrete solution that I just wrote up — which is to say, it definitely works in practice, not just in theory, but it has been used by only one person for approximately three minutes, so it probably has some infelicities.
I put the above two lines in
/tmp/time-clang
and then ranYou can use
-DCMAKE_CXX_COMPILER=
to hook the C++ compiler in exactly the same way.I didn't use
make -j8
because I didn't want the results to get interleaved in weird ways.I had to put an explicit hashbang
#!/bin/bash
on my script because the default shell (dash
, I think?) on Ubuntu 12.04 wasn't happy with those redirection operators.