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

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