From 5ab02cf659844946a7b8caaa51b8fdc11064ed15 Mon Sep 17 00:00:00 2001 From: Dedmen Miller Date: Mon, 28 Oct 2024 17:18:27 +0100 Subject: [PATCH] Update Tracy from 0.7.15 to 0.11.2 --- CMakeLists.txt | 14 +++++++++++++ src/AdapterTracy.cpp | 44 ++++++++++++++++++++++++----------------- src/AdapterTracy.hpp | 3 ++- src/CMakeLists.txt | 3 ++- src/EngineProfiling.cpp | 4 +++- src/NetworkProfiler.cpp | 2 +- tracy | 2 +- 7 files changed, 49 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f366eb0..c381675 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,4 +45,18 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(CMAKE_SUPPRESS_REGENERATION true) set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE) + +set(TRACY_ENABLE ON) +set(TRACY_ON_DEMAND ON) +set(TRACY_NO_CALLSTACK ON) # This is for native profiling, which we aren't doing +set(TRACY_NO_CODE_TRANSFER ON) +set(TRACY_NO_SAMPLING ON) # No need, too much extra data +set(TRACY_NO_SYSTEM_TRACING ON) # No need, too much extra data +set(TRACY_FIBERS ON) # Arma coroutines (and might use it for scheduled scripts?) +#set(TRACY_NO_CRASH_HANDLER ON) # Might interfere with Arma's handler? +set(TRACY_NO_VSYNC_CAPTURE ON) # Doesn't compile, probably too old win SDK version? + +add_subdirectory (tracy) + add_subdirectory(src) + diff --git a/src/AdapterTracy.cpp b/src/AdapterTracy.cpp index ab83dcd..ae8b6bc 100644 --- a/src/AdapterTracy.cpp +++ b/src/AdapterTracy.cpp @@ -1,10 +1,16 @@ #include "AdapterTracy.hpp" +// They are set by cmake #define TRACY_ENABLE #define TRACY_ON_DEMAND -#define TRACY_FIBERS -#include -#include +#define TRACY_FIBERS // Arma coroutines(and might use it for scheduled scripts?) +#define TRACY_NO_CALLSTACK // This is for native profiling, which we aren't doing +#define TRACY_NO_CODE_TRANSFER +#define TRACY_NO_SAMPLING // No need, too much extra data +#define TRACY_NO_SYSTEM_TRACING // No need, too much extra data +#define TRACY_NO_VSYNC_CAPTURE // Doesn't compile, probably too old win SDK version? +#include // CMake does it +#include #include #include //#TODO libpthread and libdl on linux @@ -31,7 +37,7 @@ extern bool InstructionCallstack; extern bool logPacketContent; extern bool checkMainThread; -void TracyParameterUpdated(uint32_t idx, int32_t val) { +void TracyParameterUpdated(void* data, uint32_t idx, int32_t val) { switch (idx) { case TP_OmitFilePath: GProfilerAdapter->setOmitFilePaths(val != 0); @@ -61,12 +67,12 @@ void TracyParameterUpdated(uint32_t idx, int32_t val) { AdapterTracy::AdapterTracy() { type = AdapterType::Tracy; - TracyParameterRegister(TracyParameterUpdated); + TracyParameterRegister(TracyParameterUpdated, nullptr); } AdapterTracy::~AdapterTracy() { - tracy::s_profiler.RequestShutdown(); - if (!tracy::s_profiler.HasShutdownFinished()) + tracy::GetProfiler().RequestShutdown(); + if (!tracy::GetProfiler().HasShutdownFinished()) std::this_thread::sleep_for(5s); //If this doesn't cut it, then F you. HasShutdownFinished broke and never turned true so this is the fix now. } @@ -124,7 +130,7 @@ std::shared_ptr AdapterTracy::enterScope(std::shared_ptr(&info->info, threadID); + //auto ret = std::make_shared(&info->info, tracy::t_withThreadId{threadID}); //return ret; } @@ -183,11 +189,11 @@ void AdapterTracy::setDescriptionNoStorage(const intercept::types::r_string& des void AdapterTracy::addLog(intercept::types::r_string message) { if (message.empty()) return; - tracy::Profiler::Message(message.c_str(), message.length()); + tracy::Profiler::Message(message.c_str(), message.length(), 0); } void AdapterTracy::setCounter(intercept::types::r_string name, float val) { - counterCache.insert(name); + counterCache.insert(name); // The name needs to be kept alive, tracy will async request it tracy::Profiler::PlotData(name.c_str(), val); } @@ -195,6 +201,10 @@ void AdapterTracy::setCounter(const char* name, float val) const { tracy::Profiler::PlotData(name, val); } +void AdapterTracy::setCounter(const char* name, int64_t val) const { + tracy::Profiler::PlotData(name, val); +} + std::shared_ptr AdapterTracy::createScopeStatic(const char* name, const char* filename, uint32_t fileline) const { auto info = std::make_shared(); info->info = tracy::SourceLocationData{nullptr, name, filename,fileline, 0}; @@ -202,7 +212,7 @@ std::shared_ptr AdapterTracy::createScopeStatic(const char* name, con } bool AdapterTracy::isConnected() { - return tracy::s_profiler.IsConnected(); + return tracy::GetProfiler().IsConnected(); } @@ -292,11 +302,9 @@ void AdapterTracy::LeaveFiber() } void AdapterTracy::ensureReady() { - if (tracy::s_token.ptr) return; - - tracy::rpmalloc_thread_initialize(); - tracy::s_token_detail = tracy::moodycamel::ProducerToken(tracy::s_queue); - tracy::s_token = tracy::ProducerWrapper{tracy::s_queue.get_explicit_producer(tracy::s_token_detail) }; - - + //if (tracy::s_token.ptr) return; + // + //tracy::rpmalloc_thread_initialize(); + //tracy::s_token_detail = tracy::moodycamel::ProducerToken(tracy::s_queue); + //tracy::s_token = tracy::ProducerWrapper{tracy::s_queue.get_explicit_producer(tracy::s_token_detail) }; } diff --git a/src/AdapterTracy.hpp b/src/AdapterTracy.hpp index 8f6db1e..6f8454a 100644 --- a/src/AdapterTracy.hpp +++ b/src/AdapterTracy.hpp @@ -35,7 +35,8 @@ class AdapterTracy final : public ProfilerAdapter void setDescriptionNoStorage(const intercept::types::r_string& descr); void addLog(intercept::types::r_string message) override; void setCounter(intercept::types::r_string name, float val) override; - void setCounter(const char* name, float val) const; + void setCounter(const char* name, float val) const; + void setCounter(const char* name, int64_t val) const; std::shared_ptr createScopeStatic(const char* name, const char* filename, uint32_t fileline) const; static bool isConnected(); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4ce1e25..e9ccfb4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,7 +6,7 @@ set(LIB_BASE_PATH "${CMAKE_SOURCE_DIR}/lib") set(INTERCEPT_INCLUDE_PATH "${INTERCEPT_CLIENT_PATH}/headers" "${INTERCEPT_CLIENT_PATH}/headers/shared" "${INTERCEPT_CLIENT_PATH}/headers/client/" "${INTERCEPT_CLIENT_PATH}/headers/client/sqf") set(BROFILER_INCLUDE_PATH "${BROFILER_BASE_PATH}/BrofilerCore" "${BROFILER_BASE_PATH}/ThirdParty/TaskScheduler/Scheduler/Include") -set(TRACY_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/tracy") +set(TRACY_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/tracy/public") set(JSON_INCLUDE_PATH "${LIB_BASE_PATH}/json/single_include") if(USE_64BIT_BUILD) @@ -76,6 +76,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${JSON_INCLUDE_PATH} ) target_link_libraries (${INTERCEPT_PLUGIN_NAME} ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(${INTERCEPT_PLUGIN_NAME} ${LINK_LIBS}) +#target_link_libraries(${INTERCEPT_PLUGIN_NAME} PUBLIC Tracy::TracyClient) # Tracy compiles it as MD instead of MT set_target_properties(${INTERCEPT_PLUGIN_NAME} PROPERTIES PREFIX "") set_target_properties(${INTERCEPT_PLUGIN_NAME} PROPERTIES FOLDER ArmaScriptProfiler) diff --git a/src/EngineProfiling.cpp b/src/EngineProfiling.cpp index e901a6d..c4a0c9a 100644 --- a/src/EngineProfiling.cpp +++ b/src/EngineProfiling.cpp @@ -83,6 +83,7 @@ bool PCounter::shouldTime() { if (cat && cat[0] == 'd' && cat[1] == 'r' && cat[2] == 'w') return false; //drw if (cat && cat[0] == 'd' && cat[1] == 'd' && cat[2] == '1') return false; //dd11 if (cat && cat[0] == 't' && cat[1] == 'e' && cat[2] == 'x' && cat[3] == 0) return false; //tex + if (cat && cat[0] == 'o' && cat[1] == 'g' && cat[2] == 'g' && cat[3] == 0) return false; //ogg jumps between new/different threads alot if (name && name[0] == 'I' && name[1] == 'G' && name[2] == 'S' && name[3] == 'M') return false; //IGSMM no idea what that is, but generates a lot of calls if (name && name[0] == 'm' && name[1] == 'a' && name[2] == 'n' && name[3] == 'C') return false; //Man update error. calltime is about constant and uninteresting @@ -349,6 +350,8 @@ SwitchToFiberReplacement( void EngineProfiling::init() { + isMainThread = true; + tracyConnected = AdapterTracy::isConnected(); tracyConnectionChanged.connect([](bool state) { @@ -414,7 +417,6 @@ void EngineProfiling::init() { void EngineProfiling::setMainThreadOnly() { checkMainThread = true; - isMainThread = true; } void EngineProfiling::setNoFile() { diff --git a/src/NetworkProfiler.cpp b/src/NetworkProfiler.cpp index 7a165d4..2e1fd4a 100644 --- a/src/NetworkProfiler.cpp +++ b/src/NetworkProfiler.cpp @@ -5,7 +5,7 @@ #define TRACY_ENABLE #define TRACY_ON_DEMAND -#include +#include #include extern void diag_log(r_string msg); diff --git a/tracy b/tracy index 72ae4d2..0c8fdcc 160000 --- a/tracy +++ b/tracy @@ -1 +1 @@ -Subproject commit 72ae4d2ee41165de61f73d404f78db984f2414e6 +Subproject commit 0c8fdcc50796a1e568f4d979cf3071831bb5360a