Skip to content

Conversation

@cgkantidis
Copy link
Contributor

To run the profiler, after building the PROFILE config, run:

CPUPROFILE=prof.out /path/to/build/PROFILE/duplo files.txt duplo.json
pprof --lines --web /path/to/build/PROFILE/duplo prof.out

@dlidstrom
Copy link
Owner

I assume using cmake as usual will not add profiling. How does one invoke cmake to add these build settings?

@cgkantidis
Copy link
Contributor Author

Your assumption is correct.

In Linux, the default generator used by cmake is Unix Makefiles, which is a single-config generator, so you need to specify the config through CMAKE_BUILD_TYPE, which defaults to "Debug".

So, using Unix Makefiles as Generator, if you want to build a Debug, an ASAN and a PROFILE build, you do it like so:

cmake -B build-debug -DCMAKE_BUILD_TYPE=Debug
cmake --build build-debug
cmake -B build-asan -DCMAKE_BUILD_TYPE=ASAN
cmake --build build-asan
cmake -B build-profile -DCMAKE_BUILD_TYPE=PROFILE
cmake --build build-profile

Linux also supports multi-config builds, through the "Ninja Multi-Config" generator (see cmake --help for a list of available generators).

In that case you have a single build directory, and you can build multiple configs in there:

cmake -G 'Ninja Multi-Config' -B build
cmake --build build
cmake --build build --config ASAN
cmake --build build --config PROFILE

I believe Visual Studio is a multi-config generator, and you can select through a drop-down menu the config you want to build. But I've never used VS, so I can't attest to that.

In any case, this commit doesn't change any default config.

It just makes more configs available.

@cgkantidis
Copy link
Contributor Author

Something else I should note is that we add the configs only when not using MSVC, because MSVC doesn't have TSAN and UBSAN support.

I think it does have ASAN support (see https://learn.microsoft.com/en-us/cpp/sanitizers/asan?view=msvc-170) but since I'm not using Windows I cannot validate that it would work.

I'm also not sure if gperftools are available on Windows.

@dlidstrom
Copy link
Owner

I'm fine with Linux/Unix only for these advanced use cases. This is all very interesting and I've learnt a lot about cmake from you (and earlier contributors too should be noted). Thank you!
I'll merge this 👍🏻

@dlidstrom dlidstrom merged commit fab33bd into dlidstrom:main Apr 1, 2025
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants