From 6c5a25c3163f9cfe9ac0e762551cd7a6c35a5029 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Sun, 22 Nov 2020 09:42:39 +0100 Subject: [PATCH] support coz profiling --- CMakeLists.txt | 15 +++++++++++++-- cmake/modules/Findcoz-profiler.cmake | 23 +++++++++++++++++++++++ src/include/stratagus.h | 4 ++++ src/stratagus/mainloop.cpp | 4 ++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 cmake/modules/Findcoz-profiler.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b1af5531..d2642d586 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -817,8 +817,14 @@ if(WIN32 AND MSVC) endif() if(CMAKE_BUILD_TYPE STREQUAL "Profile") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg") + find_package(coz-profiler) + if(COZ-PROFILER_FOUND) + add_definitions(-DHAVE_COZ_PROFILER) + include_directories(${COZ_INCLUDE_DIRS}) + set(stratagus_LIBS ${stratagus_LIBS} ${COZ_LIBRARIES} -ldl) + endif() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg -g -ggdb") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg -g -ggdb") endif() # TODO: Add support for other compilers @@ -909,6 +915,11 @@ endif() if(CMAKE_BUILD_TYPE STREQUAL "Profile") message("Profiling mode: Yes (Disable by param -DCMAKE_BUILD_TYPE=Release)") + if(COZ-PROFILER_FOUND) + message("Coz profiler enabled build: Yes") + else() + message("Coz profiler enabled build: No") + endif() else() message("Profiling mode: No (Enable by param -DCMAKE_BUILD_TYPE=Profile)") endif() diff --git a/cmake/modules/Findcoz-profiler.cmake b/cmake/modules/Findcoz-profiler.cmake new file mode 100644 index 000000000..54f89b45b --- /dev/null +++ b/cmake/modules/Findcoz-profiler.cmake @@ -0,0 +1,23 @@ +find_path(COZ_INCLUDE_DIRS NAMES coz.h) + +find_library(COZ_LIBRARIES NAMES coz PATH_SUFFIXES coz-profiler) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(coz-profiler + DEFAULT_MSG + COZ_LIBRARIES + COZ_INCLUDE_DIRS) + +if(COZ-PROFILER_FOUND) + add_library(coz::coz INTERFACE IMPORTED) + set_target_properties(coz::coz + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + ${COZ_INCLUDE_DIRS} + INTERFACE_LINK_LIBRARIES + ${COZ_LIBRARIES}) +else(COZ-PROFILER_FOUND) + set(COZ_LIBRARIES) + set(COZ_INCLUDE_DIRS) +endif(COZ-PROFILER_FOUND) + +mark_as_advanced(COZ_INCLUDE_DIRS COZ_LIBRARIES) diff --git a/src/include/stratagus.h b/src/include/stratagus.h index cd00cfcf3..2f80a1303 100644 --- a/src/include/stratagus.h +++ b/src/include/stratagus.h @@ -30,6 +30,10 @@ #ifndef __STRATAGUS_H__ #define __STRATAGUS_H__ +#ifdef HAVE_COZ_PROFILER +#include +#endif + //@{ /*============================================================================ diff --git a/src/stratagus/mainloop.cpp b/src/stratagus/mainloop.cpp index b7d7bc525..f0fc3e2ea 100644 --- a/src/stratagus/mainloop.cpp +++ b/src/stratagus/mainloop.cpp @@ -313,6 +313,10 @@ static void GameLogicLoop() if (!NetworkInSync) { NetworkRecover(); // recover network } + +#ifdef HAVE_COZ_PROFILER + COZ_PROGRESS_NAMED("GameLogicLoop") +#endif } //#define REALVIDEO