diff --git a/Tracy.hpp b/Tracy.hpp index 91e8decc..bad4f6db 100644 --- a/Tracy.hpp +++ b/Tracy.hpp @@ -36,6 +36,8 @@ #define TracyMessage(x,y) #define TracyMessageL(x) +#define TracyMessageC(x,y,z) +#define TracyMessageLC(x,y) #define TracyAlloc(x,y) #define TracyFree(x) @@ -96,6 +98,8 @@ #define TracyMessage( txt, size ) tracy::Profiler::Message( txt, size ); #define TracyMessageL( txt ) tracy::Profiler::Message( txt ); +#define TracyMessageC( txt, size, color ) tracy::Profiler::MessageColor( txt, size, color ); +#define TracyMessageLC( txt, color ) tracy::Profiler::MessageColor( txt, color ); #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK # define TracyAlloc( ptr, size ) tracy::Profiler::MemAllocCallstack( ptr, size, TRACY_CALLSTACK ); diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 37107797..ec757135 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -1339,6 +1339,7 @@ static void FreeAssociatedMemory( const QueueItem& item ) tracy_free( (void*)ptr ); break; case QueueType::Message: + case QueueType::MessageColor: ptr = MemRead( &item.message.text ); tracy_free( (void*)ptr ); break; @@ -1420,6 +1421,7 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token ) tracy_free( (void*)ptr ); break; case QueueType::Message: + case QueueType::MessageColor: ptr = MemRead( &item->message.text ); SendString( ptr, (const char*)ptr, QueueType::CustomStringData ); tracy_free( (void*)ptr ); diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index cfcf966e..5bc57b8e 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -256,6 +256,47 @@ public: tail.store( magic + 1, std::memory_order_release ); } + static tracy_force_inline void MessageColor( const char* txt, size_t size, uint32_t color ) + { +#ifdef TRACY_ON_DEMAND + if( !GetProfiler().IsConnected() ) return; +#endif + Magic magic; + auto token = GetToken(); + auto ptr = (char*)tracy_malloc( size+1 ); + memcpy( ptr, txt, size ); + ptr[size] = '\0'; + auto& tail = token->get_tail_index(); + auto item = token->enqueue_begin( magic ); + MemWrite( &item->hdr.type, QueueType::MessageColor ); + MemWrite( &item->messageColor.time, GetTime() ); + MemWrite( &item->messageColor.thread, GetThreadHandle() ); + MemWrite( &item->messageColor.text, (uint64_t)ptr ); + MemWrite( &item->messageColor.r, uint8_t( ( color ) & 0xFF ) ); + MemWrite( &item->messageColor.g, uint8_t( ( color >> 8 ) & 0xFF ) ); + MemWrite( &item->messageColor.b, uint8_t( ( color >> 16 ) & 0xFF ) ); + tail.store( magic + 1, std::memory_order_release ); + } + + static tracy_force_inline void MessageColor( const char* txt, uint32_t color ) + { +#ifdef TRACY_ON_DEMAND + if( !GetProfiler().IsConnected() ) return; +#endif + Magic magic; + auto token = GetToken(); + auto& tail = token->get_tail_index(); + auto item = token->enqueue_begin( magic ); + MemWrite( &item->hdr.type, QueueType::MessageLiteralColor ); + MemWrite( &item->messageColor.time, GetTime() ); + MemWrite( &item->messageColor.thread, GetThreadHandle() ); + MemWrite( &item->messageColor.text, (uint64_t)txt ); + MemWrite( &item->messageColor.r, uint8_t( ( color ) & 0xFF ) ); + MemWrite( &item->messageColor.g, uint8_t( ( color >> 8 ) & 0xFF ) ); + MemWrite( &item->messageColor.b, uint8_t( ( color >> 16 ) & 0xFF ) ); + tail.store( magic + 1, std::memory_order_release ); + } + static tracy_force_inline void MemAlloc( const void* ptr, size_t size ) { #ifdef TRACY_ON_DEMAND diff --git a/common/TracyProtocol.hpp b/common/TracyProtocol.hpp index 8ee317b6..6ed43394 100644 --- a/common/TracyProtocol.hpp +++ b/common/TracyProtocol.hpp @@ -9,7 +9,7 @@ namespace tracy { -enum : uint32_t { ProtocolVersion = 5 }; +enum : uint32_t { ProtocolVersion = 6 }; using lz4sz_t = uint32_t; diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index 148d47b9..e8328815 100644 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -11,6 +11,7 @@ enum class QueueType : uint8_t ZoneText, ZoneName, Message, + MessageColor, ZoneBeginAllocSrcLoc, ZoneBeginAllocSrcLocCallstack, CallstackMemory, @@ -39,6 +40,7 @@ enum class QueueType : uint8_t LockMark, PlotData, MessageLiteral, + MessageLiteralColor, GpuNewContext, GpuZoneBegin, GpuZoneBeginCallstack, @@ -190,6 +192,13 @@ struct QueueMessage uint64_t text; // ptr }; +struct QueueMessageColor : public QueueMessage +{ + uint8_t r; + uint8_t g; + uint8_t b; +}; + struct QueueGpuNewContext { int64_t cpuTime; @@ -311,6 +320,7 @@ struct QueueItem QueueLockMark lockMark; QueuePlotData plotData; QueueMessage message; + QueueMessageColor messageColor; QueueGpuNewContext gpuNewContext; QueueGpuZoneBegin gpuZoneBegin; QueueGpuZoneEnd gpuZoneEnd; @@ -335,6 +345,7 @@ static const size_t QueueDataSize[] = { sizeof( QueueHeader ) + sizeof( QueueZoneText ), sizeof( QueueHeader ) + sizeof( QueueZoneText ), // zone name sizeof( QueueHeader ) + sizeof( QueueMessage ), + sizeof( QueueHeader ) + sizeof( QueueMessageColor ), sizeof( QueueHeader ) + sizeof( QueueZoneBegin ), // allocated source location sizeof( QueueHeader ) + sizeof( QueueZoneBegin ), // allocated source location, callstack sizeof( QueueHeader ) + sizeof( QueueCallstackMemory ), @@ -364,6 +375,7 @@ static const size_t QueueDataSize[] = { sizeof( QueueHeader ) + sizeof( QueueLockMark ), sizeof( QueueHeader ) + sizeof( QueuePlotData ), sizeof( QueueHeader ) + sizeof( QueueMessage ), // literal + sizeof( QueueHeader ) + sizeof( QueueMessageColor ), // literal sizeof( QueueHeader ) + sizeof( QueueGpuNewContext ), sizeof( QueueHeader ) + sizeof( QueueGpuZoneBegin ), sizeof( QueueHeader ) + sizeof( QueueGpuZoneBegin ), // callstack diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index b710f69a..3d7e2c56 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -2500,6 +2500,12 @@ bool Worker::Process( const QueueItem& ev ) case QueueType::MessageLiteral: ProcessMessageLiteral( ev.message ); break; + case QueueType::MessageColor: + ProcessMessageColor( ev.messageColor ); + break; + case QueueType::MessageLiteralColor: + ProcessMessageLiteralColor( ev.messageColor ); + break; case QueueType::GpuNewContext: ProcessGpuNewContext( ev.gpuNewContext ); break; @@ -3073,6 +3079,30 @@ void Worker::ProcessMessageLiteral( const QueueMessage& ev ) InsertMessageData( msg, ev.thread ); } +void Worker::ProcessMessageColor( const QueueMessageColor& ev ) +{ + auto it = m_pendingCustomStrings.find( ev.text ); + assert( it != m_pendingCustomStrings.end() ); + auto msg = m_slab.Alloc(); + msg->time = TscTime( ev.time ); + msg->ref = StringRef( StringRef::Type::Idx, it->second.idx ); + msg->thread = ev.thread; + m_data.lastTime = std::max( m_data.lastTime, msg->time ); + InsertMessageData( msg, ev.thread ); + m_pendingCustomStrings.erase( it ); +} + +void Worker::ProcessMessageLiteralColor( const QueueMessageColor& ev ) +{ + CheckString( ev.text ); + auto msg = m_slab.Alloc(); + msg->time = TscTime( ev.time ); + msg->ref = StringRef( StringRef::Type::Ptr, ev.text ); + msg->thread = ev.thread; + m_data.lastTime = std::max( m_data.lastTime, msg->time ); + InsertMessageData( msg, ev.thread ); +} + void Worker::ProcessGpuNewContext( const QueueGpuNewContext& ev ) { assert( !m_gpuCtxMap[ev.context] ); diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 799dc859..7f34a045 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -367,6 +367,8 @@ private: tracy_force_inline void ProcessPlotData( const QueuePlotData& ev ); tracy_force_inline void ProcessMessage( const QueueMessage& ev ); tracy_force_inline void ProcessMessageLiteral( const QueueMessage& ev ); + tracy_force_inline void ProcessMessageColor( const QueueMessageColor& ev ); + tracy_force_inline void ProcessMessageLiteralColor( const QueueMessageColor& ev ); tracy_force_inline void ProcessGpuNewContext( const QueueGpuNewContext& ev ); tracy_force_inline void ProcessGpuZoneBegin( const QueueGpuZoneBegin& ev ); tracy_force_inline void ProcessGpuZoneBeginCallstack( const QueueGpuZoneBegin& ev );