From 8c7b60fbe63b6011421d9a2b4d1708426a3244fd Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 14 Oct 2017 13:23:13 +0200 Subject: [PATCH] Allow sending text messages. --- client/Tracy.hpp | 4 ++++ client/TracyProfiler.hpp | 17 +++++++++++++++++ common/TracyQueue.hpp | 10 ++++++++++ 3 files changed, 31 insertions(+) diff --git a/client/Tracy.hpp b/client/Tracy.hpp index 95f7fc25..c6437627 100644 --- a/client/Tracy.hpp +++ b/client/Tracy.hpp @@ -18,6 +18,8 @@ #define TracyPlot(x,y) +#define TracyMesage(x,y) + #else #include "TracyLock.hpp" @@ -39,6 +41,8 @@ #define TracyPlot( name, val ) tracy::Profiler::PlotData( name, val ); +#define TracyMessage( txt, size ) tracy::Profiler::Message( txt, size ); + #endif #endif diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 17faeff7..5558ba86 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -127,6 +127,23 @@ public: tail.store( magic + 1, std::memory_order_release ); } + static tracy_force_inline void Message( const char* txt, size_t size ) + { + uint32_t cpu; + Magic magic; + auto ptr = new char[size+1]; + memcpy( ptr, txt, size ); + ptr[size] = '\0'; + auto& token = s_token.ptr; + auto& tail = token->get_tail_index(); + auto item = token->enqueue_begin( magic ); + item->hdr.type = QueueType::Message; + item->message.time = GetTime( cpu ); + item->message.thread = GetThreadHandle(); + item->message.text = (uint64_t)ptr; + tail.store( magic + 1, std::memory_order_release ); + } + static bool ShouldExit(); private: diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index 4947e1b9..7abafc09 100644 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -23,6 +23,7 @@ enum class QueueType : uint8_t LockMark, PlotData, PlotName, + Message, NUM_TYPES }; @@ -125,6 +126,13 @@ struct QueuePlotData } data; }; +struct QueueMessage +{ + int64_t time; + uint64_t thread; + uint64_t text; // ptr +}; + struct QueueHeader { union @@ -151,6 +159,7 @@ struct QueueItem QueueLockRelease lockRelease; QueueLockMark lockMark; QueuePlotData plotData; + QueueMessage message; }; }; @@ -174,6 +183,7 @@ static const size_t QueueDataSize[] = { sizeof( QueueHeader ) + sizeof( QueueLockMark ), sizeof( QueueHeader ) + sizeof( QueuePlotData ), sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // plot name + sizeof( QueueHeader ) + sizeof( QueueMessage ), }; static_assert( QueueItemSize == 32, "Queue item size not 32 bytes" );