Skip to content

Commit 5138af7

Browse files
authored
Merge pull request #12 from jorisv/topic/ninjatracing
Add ninjatracing instruction
2 parents 94fb20c + 046c4ad commit 5138af7

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

README.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,11 @@ Run the CI and follow the output. Note: the option `continue-on-error: True` can
297297
Consider using the action with `limit-access-to-actor: true`, to limit access to your account.
298298
299299
300-
## Profile C++ compile time
300+
## Profile C++ compile time of a translation unit
301301
302302
When doing heavy template meta-programming in C++ it can be useful to analyze what part of the code is taking a long time to compile.
303303
304-
[clang](https://clang.llvm.org) allows to profile the compilation time. To activate this function, add the `-ftime-trace` option while building.
304+
[clang](https://clang.llvm.org) allows to profile the compilation time of a translation unit. To activate this function, add the `-ftime-trace` option while building.
305305
306306
In a CMake project, you can do this with the following command line:
307307
@@ -317,7 +317,7 @@ find . -iname "*.json"
317317
318318
Then, you can open the file with the [Chromium tracing tool](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool/). Open the `about:tracing` URL in Chromium and load the .json. You will have the following display:
319319
320-
![Compile time profile displayed with Chromimum](./resources/cpp-compilation-time-profile.png)
320+
![Compile time translation unit profile displayed with Chromimum](./resources/cpp-compilation-time-profile.png)
321321
322322
### Note for GNU/Linux users
323323
@@ -329,6 +329,41 @@ Then, when running CMake **for the first time** use the following command:
329329
CC=clang CXX=clang++ cmake ..
330330
```
331331
332+
333+
## Profile C++ compile time of a CMake target
334+
335+
When building a CMake target, it's interesting to profile which translation unit took most of the compile time.
336+
337+
Ninja and [ninjatracing](https://github.com/nico/ninjatracing) allow to do visualize the whole target build time.
338+
339+
First clone [ninjatracing](https://github.com/nico/ninjatracing) somewhere.
340+
341+
Then configure your CMake build to use Ninja. Run the following command in a **NEW** build directory:
342+
343+
```bash
344+
cmake .. -GNinja
345+
```
346+
347+
Now, build your project with Ninja:
348+
349+
```bash
350+
ninja
351+
```
352+
353+
The `.ninja_log` file should had been created in the build directory.
354+
You can convert it to a file compatible with the [Chromium tracing tool](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool/).
355+
356+
Run the following command:
357+
358+
```bash
359+
path/to/ninjatracing .ninja_log > trace.json
360+
```
361+
362+
Now, you can visualize it with the [Chromium tracing tool](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool/). Open the `about:tracing` URL in Chromium and load the .json. You will have the following display:
363+
364+
![Compile time CMake target profile displayed with Chromimum](./resources/cpp-cmake-target-compilation-time-profile.png)
365+
366+
332367
## Launch a process on a particular CPU/CORE/PU
333368
334369
[hwloc tools](https://www.open-mpi.org/projects/hwloc/) allow to study computer and computer cluster topology.
443 KB
Loading

0 commit comments

Comments
 (0)