diff --git a/CMakePresets.json b/CMakePresets.json index 34a8131a..ad7ebb2d 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -72,6 +72,34 @@ { "name": "testing", "inherits": ["debug", "config-testing"] + }, + { + "name": "timetrace-windows", + "inherits": ["release"], + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + }, + "cacheVariables": { + "CMAKE_C_COMPILER": "clang-cl", + "CMAKE_CXX_COMPILER": "clang-cl", + "CMAKE_CXX_FLAGS": "/clang:-ftime-trace /EHsc" + } + }, + { + "name": "timetrace-unix", + "inherits": ["release"], + "condition": { + "type": "notEquals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + }, + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++", + "CMAKE_CXX_FLAGS": "-ftime-trace" + } } ], "buildPresets": [ @@ -102,6 +130,14 @@ { "name": "testing", "configurePreset": "testing" + }, + { + "name": "timetrace-windows", + "configurePreset": "timetrace-windows" + }, + { + "name": "timetrace-unix", + "configurePreset": "timetrace-unix" } ], "testPresets": [ diff --git a/justfile b/justfile index 68236c5a..5785c0e8 100644 --- a/justfile +++ b/justfile @@ -9,6 +9,9 @@ set positional-arguments # Default build preset; override with `just preset=name `. preset := env_var_or_default("PRESET", "dev") +# OS-specific preset selector for the build-time profiler. +timetrace_preset := if os() == "windows" { "timetrace-windows" } else { "timetrace-unix" } + [private] default: @just --list @@ -50,6 +53,20 @@ lint *args: configure clazy *args: configure pwsh tools/run-clazy.ps1 {{args}} +# Profile build time with -ftime-trace and emit a ClangBuildAnalyzer report. +# Requires Clang (clang-cl on Windows) and ClangBuildAnalyzer on PATH. +[group('dev')] +analyze-build-time: + cmake --preset {{timetrace_preset}} + cmake --build --preset {{timetrace_preset}} + ClangBuildAnalyzer --all build/{{timetrace_preset}} build/{{timetrace_preset}}/cba.bin + ClangBuildAnalyzer --analyze build/{{timetrace_preset}}/cba.bin + +# Re-emit the ClangBuildAnalyzer report from an existing timetrace build. +[group('dev')] +analyze-build-time-report: + ClangBuildAnalyzer --analyze build/{{timetrace_preset}}/cba.bin + # Remove all build directories. [group('dev')] clean: