From 99c0d2d74432613ab7c78b6184e1daf84b113ddb Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Wed, 11 Jun 2025 01:03:12 +0200 Subject: [PATCH] Enable callgrind for specific scenarios (#276) --- CMakeLists.txt | 8 ++++++++ ISLE/isledebug.cpp | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3806a1f..0ac7a25f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -488,6 +488,14 @@ if (ISLE_BUILD_APP) ) target_compile_definitions(isle PRIVATE ISLE_DEBUG) target_link_libraries(isle PRIVATE imgui) + find_path(valgrind_INCLUDE_PATH NAMES valgrind/callgrind.h) + if(valgrind_INCLUDE_PATH) + # Run isle under valgrind to create a profile. Use e.g. kcachegrind to view the profile. + # > valgrind --tool=callgrind --dump-instr=yes --simulate-cache=yes --collect-jumps=yes \ + # > --collect-atstart=no --instr-atstart=no ./isle --debug + target_compile_definitions(isle PRIVATE ISLE_VALGRIND) + target_include_directories(isle PRIVATE ${valgrind_INCLUDE_PATH}) + endif() endif() endif() diff --git a/ISLE/isledebug.cpp b/ISLE/isledebug.cpp index a917e9bd..fc451c2d 100644 --- a/ISLE/isledebug.cpp +++ b/ISLE/isledebug.cpp @@ -16,6 +16,10 @@ #include #include +#ifdef ISLE_VALGRIND +#include +#endif + #define SCANCODE_KEY_PAUSE SDL_SCANCODE_KP_0 #define SCANCODE_KEY_RESUME SDL_SCANCODE_KP_PERIOD @@ -28,6 +32,10 @@ static SDL_Renderer* g_debugRenderer; static SDL_Texture* g_videoPalette; static IDirect3DRMMiniwinDevice* g_d3drmMiniwinDevice; +#ifdef ISLE_VALGRIND +static bool g_instrumentationEnabled; +#endif + class DebugViewer { public: static void InsidePlantManager() @@ -257,6 +265,19 @@ void IsleDebug_Render() Lego()->Resume(); } } +#ifdef ISLE_VALGRIND + if (ImGui::MenuItem(g_instrumentationEnabled ? "Disable instrumentation" : "Enable instrumentation")) { + g_instrumentationEnabled = !g_instrumentationEnabled; + if (g_instrumentationEnabled) { + CALLGRIND_START_INSTRUMENTATION; + CALLGRIND_TOGGLE_COLLECT; + } + else { + CALLGRIND_TOGGLE_COLLECT; + CALLGRIND_STOP_INSTRUMENTATION; + } + } +#endif ImGui::EndMainMenuBar(); ImGui::ShowDemoWindow(nullptr); LegoOmni* lego = Lego();