1
0
mirror of synced 2025-02-02 04:17:56 +01:00

impr: Simplify tracy integration

This commit is contained in:
WerWolv 2024-06-01 23:57:34 +02:00
parent 3e0bb6d8be
commit 92b5fd84c2
8 changed files with 38 additions and 55 deletions

View File

@ -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()

View File

@ -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)

View File

@ -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()

View File

@ -1,6 +1,18 @@
#pragma once
#include <map>
#include <memory>
#if defined(IMHEX_USE_INSTRUMENTATION)
#include <tracy/Tracy.hpp>
#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

View File

@ -1,28 +0,0 @@
#include <mutex>
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);
}
}

View File

@ -1,13 +1 @@
#include <hex/trace/instrumentation.hpp>
namespace hex {
void functionEntry([[maybe_unused]] void *functionAddress) {
}
void functionExit([[maybe_unused]] void *functionAddress) {
}
}
#include <hex/trace/instrumentation.hpp>

View File

@ -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 ()

View File

@ -17,6 +17,8 @@
#include <hex/ui/view.hpp>
#include <hex/ui/popup.hpp>
#include <hex/trace/instrumentation.hpp>
#include <chrono>
#include <csignal>
@ -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> &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();