Skip to content

Commit

Permalink
Update Tracy from 0.7.15 to 0.11.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dedmen committed Oct 28, 2024
1 parent 7ceed93 commit 5ab02cf
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 23 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

44 changes: 26 additions & 18 deletions src/AdapterTracy.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#include "AdapterTracy.hpp"

// They are set by cmake
#define TRACY_ENABLE
#define TRACY_ON_DEMAND
#define TRACY_FIBERS
#include <TracyClient.cpp>
#include <Tracy.hpp>
#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 <TracyClient.cpp> // CMake does it
#include <tracy/Tracy.hpp>
#include <unordered_set>
#include <string_view>
//#TODO libpthread and libdl on linux
Expand All @@ -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);
Expand Down Expand Up @@ -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.
}

Expand Down Expand Up @@ -124,7 +130,7 @@ std::shared_ptr<ScopeTempStorage> AdapterTracy::enterScope(std::shared_ptr<Scope
//if (!info || !isConnected()) return nullptr; //#TODO debugbreak? log error?
//ensureReady();
//
//auto ret = std::make_shared<ScopeTempStorageTracy>(&info->info, threadID);
//auto ret = std::make_shared<ScopeTempStorageTracy>(&info->info, tracy::t_withThreadId{threadID});
//return ret;
}

Expand Down Expand Up @@ -183,26 +189,30 @@ 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);
}

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<ScopeInfo> AdapterTracy::createScopeStatic(const char* name, const char* filename, uint32_t fileline) const {
auto info = std::make_shared<ScopeInfoTracy>();
info->info = tracy::SourceLocationData{nullptr, name, filename,fileline, 0};
return info;
}

bool AdapterTracy::isConnected() {
return tracy::s_profiler.IsConnected();
return tracy::GetProfiler().IsConnected();
}


Expand Down Expand Up @@ -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) };
}
3 changes: 2 additions & 1 deletion src/AdapterTracy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScopeInfo> createScopeStatic(const char* name, const char* filename, uint32_t fileline) const;
static bool isConnected();
Expand Down
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/EngineProfiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -349,6 +350,8 @@ SwitchToFiberReplacement(

void EngineProfiling::init() {

isMainThread = true;

tracyConnected = AdapterTracy::isConnected();
tracyConnectionChanged.connect([](bool state)
{
Expand Down Expand Up @@ -414,7 +417,6 @@ void EngineProfiling::init() {

void EngineProfiling::setMainThreadOnly() {
checkMainThread = true;
isMainThread = true;
}

void EngineProfiling::setNoFile() {
Expand Down
2 changes: 1 addition & 1 deletion src/NetworkProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#define TRACY_ENABLE
#define TRACY_ON_DEMAND
#include <Tracy.hpp>
#include <tracy/Tracy.hpp>
#include <pointers.hpp>

extern void diag_log(r_string msg);
Expand Down
2 changes: 1 addition & 1 deletion tracy
Submodule tracy updated 499 files

0 comments on commit 5ab02cf

Please sign in to comment.