From 4d094c108dfc7b73bdc33f4e5de9d55c6d4c014a Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 6 May 2026 02:13:38 +0200 Subject: [PATCH] Add zone end messages with 32 and 16 byte time deltas. Change in test application: compressed data: 130 Mpbps -> 105 Mbps uncompressed: 830 Mbps -> 740 Mbps --- public/client/TracyProfiler.cpp | 39 +++++++++++++++++++++++++++++++-- public/common/TracyProtocol.hpp | 5 ++++- public/common/TracyQueue.hpp | 16 ++++++++++++++ server/TracyWorker.cpp | 27 ++++++++++++++++++++++- server/TracyWorker.hpp | 3 +++ 5 files changed, 86 insertions(+), 4 deletions(-) diff --git a/public/client/TracyProfiler.cpp b/public/client/TracyProfiler.cpp index 7d527517..55b8860f 100644 --- a/public/client/TracyProfiler.cpp +++ b/public/client/TracyProfiler.cpp @@ -43,13 +43,11 @@ # include # include # include -# include # include # include #endif #ifdef __QNX__ -# include # include # include # include @@ -62,6 +60,7 @@ #include #include #include +#include #include #include #include @@ -2608,6 +2607,24 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token ) int64_t t = MemRead( &item->zoneEnd.time ); int64_t dt = t - refThread; refThread = t; + if( dt >= 0 ) + { + if( dt < ProtocolOffset16Bit ) + { + idx = (int)QueueType::ZoneEnd16; + MemWrite( &item->hdr.idx, idx ); + } + else if( dt < ProtocolOffset32Bit ) + { + dt -= ProtocolOffset16Bit; + idx = (int)QueueType::ZoneEnd32; + MemWrite( &item->hdr.idx, idx ); + } + else + { + dt -= ProtocolOffset32Bit; + } + } MemWrite( &item->zoneEnd.time, dt ); break; } @@ -3054,6 +3071,24 @@ Profiler::DequeueStatus Profiler::DequeueSerial() int64_t t = MemRead( &item->zoneEnd.time ); int64_t dt = t - refThread; refThread = t; + if( dt >= 0 ) + { + if( dt < ProtocolOffset16Bit ) + { + idx = (int)QueueType::ZoneEnd16; + MemWrite( &item->hdr.idx, idx ); + } + else if( dt < ProtocolOffset32Bit ) + { + dt -= ProtocolOffset16Bit; + idx = (int)QueueType::ZoneEnd32; + MemWrite( &item->hdr.idx, idx ); + } + else + { + dt -= ProtocolOffset32Bit; + } + } MemWrite( &item->zoneEnd.time, dt ); break; } diff --git a/public/common/TracyProtocol.hpp b/public/common/TracyProtocol.hpp index 74a037ba..5c799138 100644 --- a/public/common/TracyProtocol.hpp +++ b/public/common/TracyProtocol.hpp @@ -10,7 +10,7 @@ namespace tracy constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; } -constexpr uint32_t ProtocolVersion = 77; +constexpr uint32_t ProtocolVersion = 78; constexpr uint16_t BroadcastVersion = 3; using lz4sz_t = uint32_t; @@ -155,6 +155,9 @@ struct BroadcastMessage_v0 #pragma pack( pop ) +constexpr uint64_t ProtocolOffset16Bit = (1ull << 16); +constexpr uint64_t ProtocolOffset32Bit = (1ull << 16) + (1ull << 32); + } #endif diff --git a/public/common/TracyQueue.hpp b/public/common/TracyQueue.hpp index e5f684c6..7c4acda3 100644 --- a/public/common/TracyQueue.hpp +++ b/public/common/TracyQueue.hpp @@ -29,6 +29,8 @@ enum class QueueType : uint8_t ZoneBegin, ZoneBeginCallstack, ZoneEnd, + ZoneEnd32, + ZoneEnd16, LockWait, LockObtain, LockRelease, @@ -158,6 +160,16 @@ struct QueueZoneEnd int64_t time; }; +struct QueueZoneEnd32 +{ + uint32_t time; +}; + +struct QueueZoneEnd16 +{ + uint16_t time; +}; + struct QueueZoneEndThread : public QueueZoneEnd { uint32_t thread; @@ -785,6 +797,8 @@ struct QueueItem QueueZoneBeginLean zoneBeginLean; QueueZoneBeginThread zoneBeginThread; QueueZoneEnd zoneEnd; + QueueZoneEnd32 zoneEnd32; + QueueZoneEnd16 zoneEnd16; QueueZoneEndThread zoneEndThread; QueueZoneValidation zoneValidation; QueueZoneValidationThread zoneValidationThread; @@ -895,6 +909,8 @@ static constexpr size_t QueueDataSize[] = { sizeof( QueueHeader ) + sizeof( QueueZoneBegin ), sizeof( QueueHeader ) + sizeof( QueueZoneBegin ), // callstack sizeof( QueueHeader ) + sizeof( QueueZoneEnd ), + sizeof( QueueHeader ) + sizeof( QueueZoneEnd32 ), + sizeof( QueueHeader ) + sizeof( QueueZoneEnd16 ), sizeof( QueueHeader ) + sizeof( QueueLockWait ), sizeof( QueueHeader ) + sizeof( QueueLockObtain ), sizeof( QueueHeader ) + sizeof( QueueLockRelease ), diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 502d7a84..a1611641 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -4510,7 +4510,13 @@ bool Worker::Process( const QueueItem& ev ) ProcessZoneBeginAllocSrcLocCallstack( ev.zoneBeginLean ); break; case QueueType::ZoneEnd: - ProcessZoneEnd( ev.zoneEnd ); + ProcessZoneEnd64( ev.zoneEnd ); + break; + case QueueType::ZoneEnd32: + ProcessZoneEnd32( ev.zoneEnd32 ); + break; + case QueueType::ZoneEnd16: + ProcessZoneEnd16( ev.zoneEnd16 ); break; case QueueType::ZoneValidation: ProcessZoneValidation( ev.zoneValidation ); @@ -5009,6 +5015,25 @@ void Worker::ProcessZoneEnd( const QueueZoneEnd& ev ) #endif } +void Worker::ProcessZoneEnd64( const QueueZoneEnd& ev ) +{ + QueueZoneEnd unpack = ev; + if( ev.time >= 0 ) unpack.time += ProtocolOffset32Bit; + ProcessZoneEnd( unpack ); +} + +void Worker::ProcessZoneEnd32( const QueueZoneEnd32& ev ) +{ + QueueZoneEnd unpack = { .time = int64_t( ev.time + ProtocolOffset16Bit ) }; + ProcessZoneEnd( unpack ); +} + +void Worker::ProcessZoneEnd16( const QueueZoneEnd16& ev ) +{ + QueueZoneEnd unpack = { .time = ev.time }; + ProcessZoneEnd( unpack ); +} + void Worker::ZoneStackFailure( uint64_t thread, const ZoneEvent* ev ) { m_failure = Failure::ZoneStack; diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 324cfd40..04299cce 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -726,6 +726,9 @@ private: tracy_force_inline void ProcessZoneBeginAllocSrcLoc( const QueueZoneBeginLean& ev ); tracy_force_inline void ProcessZoneBeginAllocSrcLocCallstack( const QueueZoneBeginLean& ev ); tracy_force_inline void ProcessZoneEnd( const QueueZoneEnd& ev ); + tracy_force_inline void ProcessZoneEnd64( const QueueZoneEnd& ev ); + tracy_force_inline void ProcessZoneEnd32( const QueueZoneEnd32& ev ); + tracy_force_inline void ProcessZoneEnd16( const QueueZoneEnd16& ev ); tracy_force_inline void ProcessZoneValidation( const QueueZoneValidation& ev ); tracy_force_inline void ProcessFrameMark( const QueueFrameMark& ev ); tracy_force_inline void ProcessFrameMarkStart( const QueueFrameMark& ev );