diff --git a/cmake/build_helpers.cmake b/cmake/build_helpers.cmake index c2ce8c12d..eb2abebc6 100644 --- a/cmake/build_helpers.cmake +++ b/cmake/build_helpers.cmake @@ -543,13 +543,9 @@ macro(setupDebugCompressionFlag) if (NOT DEBUG_COMPRESSION_FLAG) # Cache variable if (ZSTD_AVAILABLE_COMPILER AND ZSTD_AVAILABLE_LINKER) - message("Using Zstd compression for debug info because both compiler and linker support it") set(DEBUG_COMPRESSION_FLAG "-gz=zstd" CACHE STRING "Cache to use for debug info compression") elseif (COMPRESS_AVAILABLE_COMPILER AND COMPRESS_AVAILABLE_LINKER) - message("Using default compression for debug info because both compiler and linker support it") set(DEBUG_COMPRESSION_FLAG "-gz" CACHE STRING "Cache to use for debug info compression") - else() - message("No compression available for debug info") endif() endif() diff --git a/cmake/modules/ImHexPlugin.cmake b/cmake/modules/ImHexPlugin.cmake index f176c6e70..a55aa09ac 100644 --- a/cmake/modules/ImHexPlugin.cmake +++ b/cmake/modules/ImHexPlugin.cmake @@ -37,7 +37,7 @@ macro(add_imhex_plugin) # Add include directories and link libraries target_include_directories(${IMHEX_PLUGIN_NAME} PUBLIC ${IMHEX_PLUGIN_INCLUDES}) target_link_libraries(${IMHEX_PLUGIN_NAME} PUBLIC ${IMHEX_PLUGIN_LIBRARIES}) - target_link_libraries(${IMHEX_PLUGIN_NAME} PRIVATE libimhex ${FMT_LIBRARIES} imgui_all_includes libwolv) + target_link_libraries(${IMHEX_PLUGIN_NAME} PRIVATE libimhex ${FMT_LIBRARIES} imgui_all_includes libwolv tracing) addIncludesFromLibrary(${IMHEX_PLUGIN_NAME} libpl) addIncludesFromLibrary(${IMHEX_PLUGIN_NAME} libpl-gen) diff --git a/lib/trace/CMakeLists.txt b/lib/trace/CMakeLists.txt index 7ad260d1a..93df6f83f 100644 --- a/lib/trace/CMakeLists.txt +++ b/lib/trace/CMakeLists.txt @@ -1,7 +1,7 @@ project(tracing) option(IMHEX_TRACE_EXCEPTIONS "Hook thrown exceptions to display a stack trace when possible" ON) -option(IMHEX_INSTRUMENT_FUNCTIONS "Hook all function entries and exits to profile things in Tracy" OFF) +option(IMHEX_INSTRUMENT_FUNCTIONS "Hook all function entries and exits to profile things in Tracy" ON) add_library(tracing OBJECT source/stacktrace.cpp @@ -42,20 +42,23 @@ endif() if (IMHEX_INSTRUMENT_FUNCTIONS) target_sources(tracing PUBLIC - source/instr_entry.cpp source/instrumentation.cpp ) + set(TRACY_ON_DEMAND ON CACHE INTERNAL "TRACY_ON_DEMAND") + set(TRACY_DELAYED_INIT ON CACHE INTERNAL "TRACY_DELAYED_INIT") + set(TRACY_ONLY_LOCALHOST ON CACHE INTERNAL "TRACY_ONLY_LOCALHOST") + set(TRACY_NO_FRAME_IMAGE ON CACHE INTERNAL "TRACY_NO_FRAME_IMAGE") + set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "BUILD_SHARED_LIBS") FetchContent_Declare( tracy GIT_REPOSITORY https://github.com/wolfpld/tracy.git - GIT_TAG v0.10 + GIT_TAG master GIT_SHALLOW TRUE GIT_PROGRESS TRUE ) FetchContent_MakeAvailable(tracy) target_compile_options(TracyClient PRIVATE "-Wno-error") - - target_compile_options(tracing PUBLIC "-finstrument-functions") - target_link_libraries(tracing PRIVATE TracyClient) + target_link_libraries(tracing PUBLIC TracyClient) + target_compile_definitions(tracing PUBLIC IMHEX_USE_INSTRUMENTATION=1) endif() diff --git a/lib/trace/include/hex/trace/instrumentation.hpp b/lib/trace/include/hex/trace/instrumentation.hpp index dac38ca9b..11897da56 100644 --- a/lib/trace/include/hex/trace/instrumentation.hpp +++ b/lib/trace/include/hex/trace/instrumentation.hpp @@ -1,6 +1,18 @@ #pragma once -#include -#include +#if defined(IMHEX_USE_INSTRUMENTATION) + #include + #define IMHEX_TRACE_SCOPE ZoneScoped + #define IMHEX_TRACE_SCOPE_NAME(name) ZoneScoped; ZoneName(name, strlen(name)) + #define IMHEX_START_FRAME_MARK FrameMarkStart("Frame") + #define IMHEX_END_FRAME_MARK FrameMarkEnd("Frame") + #define IMHEX_TRACE_MESSAGE(message) TracyMessage(message, strlen(message)) + +#else + + #define IMHEX_TRACE_SCOPE_NAME(name) + #define IMHEX_END_FRAME_MARK + +#endif \ No newline at end of file diff --git a/lib/trace/source/instr_entry.cpp b/lib/trace/source/instr_entry.cpp deleted file mode 100644 index e255f0143..000000000 --- a/lib/trace/source/instr_entry.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include - -namespace hex { - - void functionEntry(void *); - void functionExit(void *); - -} - -extern "C" { - - static std::mutex s_mutex; - - [[gnu::no_instrument_function]] - void __cyg_profile_func_enter(void *functionAddress, void *) { - std::scoped_lock lock(s_mutex); - - hex::functionEntry(functionAddress); - } - - [[gnu::no_instrument_function]] - void __cyg_profile_func_exit(void *functionAddress, void *) { - std::scoped_lock lock(s_mutex); - - hex::functionExit(functionAddress); - } - -} \ No newline at end of file diff --git a/lib/trace/source/instrumentation.cpp b/lib/trace/source/instrumentation.cpp index c540104d1..c3f6454f7 100644 --- a/lib/trace/source/instrumentation.cpp +++ b/lib/trace/source/instrumentation.cpp @@ -1,13 +1 @@ -#include - -namespace hex { - - void functionEntry([[maybe_unused]] void *functionAddress) { - - } - - void functionExit([[maybe_unused]] void *functionAddress) { - - } - -} \ No newline at end of file +#include \ No newline at end of file diff --git a/main/gui/CMakeLists.txt b/main/gui/CMakeLists.txt index ec10adadc..6526536eb 100644 --- a/main/gui/CMakeLists.txt +++ b/main/gui/CMakeLists.txt @@ -57,7 +57,7 @@ set_target_properties(main PROPERTIES target_compile_definitions(main PRIVATE IMHEX_PROJECT_NAME="${PROJECT_NAME}") -target_link_libraries(main PRIVATE libromfs-imhex libimhex libwolv ${LIBBACKTRACE_LIBRARIES} LLVMDemangle) +target_link_libraries(main PRIVATE libromfs-imhex libimhex libwolv ${LIBBACKTRACE_LIBRARIES} LLVMDemangle tracing) if (WIN32) target_link_libraries(main PRIVATE usp10 wsock32 ws2_32 Dwmapi.lib) else () diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 945f25635..ad4918b83 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -17,6 +17,8 @@ #include #include +#include + #include #include @@ -236,7 +238,9 @@ namespace hex { glfwSetWindowSizeLimits(m_window, lastWindowSize.x, lastWindowSize.y, lastWindowSize.x, lastWindowSize.y); } + IMHEX_START_FRAME_MARK; this->fullFrame(); + IMHEX_END_FRAME_MARK; ImHexApi::System::impl::setLastFrameTime(glfwGetTime() - m_lastStartFrameTime); @@ -288,6 +292,8 @@ namespace hex { } void Window::frameBegin() { + IMHEX_TRACE_SCOPE; + // Start new ImGui Frame ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); @@ -547,6 +553,8 @@ namespace hex { } void Window::drawView(const std::string &name, const std::unique_ptr &view) { + IMHEX_TRACE_SCOPE_NAME(name.c_str()); + // Draw always visible views view->drawAlwaysVisibleContent(); @@ -607,6 +615,8 @@ namespace hex { } void Window::frame() { + IMHEX_TRACE_SCOPE; + // Loop through all views and draw them for (auto &[name, view] : ContentRegistry::Views::impl::getEntries()) { ImGui::GetCurrentContext()->NextWindowData.ClearFlags(); @@ -624,6 +634,8 @@ namespace hex { } void Window::frameEnd() { + IMHEX_TRACE_SCOPE; + EventFrameEnd::post(); TutorialManager::drawTutorial();