From 4a13694794a602f333df1e55a75cfd992ed36c3b Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 13 Sep 2020 23:42:56 +0200 Subject: [PATCH] Added a CMake profiling build type. --- CMakeLists.txt | 6 +++++- INSTALL.md | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c07145015..49d5dc2b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,7 +119,7 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") endif() endif() -# Set up compiler flags for debug or release builds. +# Set up compiler and linker flags for debug, profiling or release builds. if(CMAKE_BUILD_TYPE MATCHES Debug) # Enable the C++11 standard and disable optimizations as it's a debug build. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O0") @@ -132,6 +132,10 @@ if(CMAKE_BUILD_TYPE MATCHES Debug) if(NOT APPLE AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_DEBUG") endif() +elseif(CMAKE_BUILD_TYPE MATCHES Profiling) + # For the profiling build, we enable optimizations and supply the required profiler flags. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -pg -g") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O2 -pg") else() # Enable the C++11 standard and enable optimizations as it's a release build. # This will also disable all assert() macros. Strip the binary as well. diff --git a/INSTALL.md b/INSTALL.md index ec7a7bdb1..4d635a460 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -47,14 +47,27 @@ cmake . make ``` -To generate a debug build, run this instead: +To create a debug build, run this instead: ``` cmake -DCMAKE_BUILD_TYPE=Debug . make ``` Keep in mind though that a debug version will be much slower due to all compiler optimizations being disabled. -To build with CEC support, add the corresponding option, for example: +To create a profiling build, run this: +``` +cmake -DCMAKE_BUILD_TYPE=Profiling . +make +``` + +You can then profile the code with valgrind: +``` +valgrind --tool=callgrind ./emulationstation +``` + +The output file from valgrind can be loaded into a tool such as KCachegrind for data analysis. + +To build ES with CEC support, add the corresponding option, for example: ``` cmake -DCMAKE_BUILD_TYPE=Debug -DCEC=on .