From ccaef5ba0bf889f7c82e98d9c81efa8b05ccb174 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 7 May 2026 01:28:12 +0200 Subject: [PATCH] ZoneBegin / ZoneBeginCallstack with 32 and 16 bit time data. --- public/client/TracyProfiler.cpp | 52 ++++++++++++++++++++++++++ public/common/TracyQueue.hpp | 22 +++++++++++ server/TracyWorker.cpp | 66 ++++++++++++++++++++++++++++++++- server/TracyWorker.hpp | 6 +++ 4 files changed, 144 insertions(+), 2 deletions(-) diff --git a/public/client/TracyProfiler.cpp b/public/client/TracyProfiler.cpp index 55b8860f..af010c58 100644 --- a/public/client/TracyProfiler.cpp +++ b/public/client/TracyProfiler.cpp @@ -2599,6 +2599,32 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token ) int64_t t = MemRead( &item->zoneBegin.time ); int64_t dt = t - refThread; refThread = t; + if( dt >= 0 ) + { + if( dt < ProtocolOffset16Bit ) + { + const uint64_t srcloc = MemRead( &item->zoneBegin.srcloc ); + idx = QueueType( idx ) == QueueType::ZoneBegin ? (int)QueueType::ZoneBegin16 : (int)QueueType::ZoneBeginCallstack16; + MemWrite( &item->hdr.idx, idx ); + MemWrite( &item->zoneBegin16.time, uint16_t( dt ) ); + MemWrite( &item->zoneBegin16.srcloc, srcloc ); + break; + } + else if( dt < ProtocolOffset32Bit ) + { + dt -= ProtocolOffset16Bit; + const uint64_t srcloc = MemRead( &item->zoneBegin.srcloc ); + idx = QueueType( idx ) == QueueType::ZoneBegin ? (int)QueueType::ZoneBegin32 : (int)QueueType::ZoneBeginCallstack32; + MemWrite( &item->hdr.idx, idx ); + MemWrite( &item->zoneBegin32.time, uint32_t( dt ) ); + MemWrite( &item->zoneBegin32.srcloc, srcloc ); + break; + } + else + { + dt -= ProtocolOffset32Bit; + } + } MemWrite( &item->zoneBegin.time, dt ); break; } @@ -3049,6 +3075,32 @@ Profiler::DequeueStatus Profiler::DequeueSerial() int64_t t = MemRead( &item->zoneBegin.time ); int64_t dt = t - refThread; refThread = t; + if( dt >= 0 ) + { + if( dt < ProtocolOffset16Bit ) + { + const uint64_t srcloc = MemRead( &item->zoneBegin.srcloc ); + idx = QueueType( idx ) == QueueType::ZoneBegin ? (int)QueueType::ZoneBegin16 : (int)QueueType::ZoneBeginCallstack16; + MemWrite( &item->hdr.idx, idx ); + MemWrite( &item->zoneBegin16.time, uint16_t( dt ) ); + MemWrite( &item->zoneBegin16.srcloc, srcloc ); + break; + } + else if( dt < ProtocolOffset32Bit ) + { + dt -= ProtocolOffset16Bit; + const uint64_t srcloc = MemRead( &item->zoneBegin.srcloc ); + idx = QueueType( idx ) == QueueType::ZoneBegin ? (int)QueueType::ZoneBegin32 : (int)QueueType::ZoneBeginCallstack32; + MemWrite( &item->hdr.idx, idx ); + MemWrite( &item->zoneBegin32.time, uint32_t( dt ) ); + MemWrite( &item->zoneBegin32.srcloc, srcloc ); + break; + } + else + { + dt -= ProtocolOffset32Bit; + } + } MemWrite( &item->zoneBegin.time, dt ); break; } diff --git a/public/common/TracyQueue.hpp b/public/common/TracyQueue.hpp index 7c4acda3..e45eb09f 100644 --- a/public/common/TracyQueue.hpp +++ b/public/common/TracyQueue.hpp @@ -27,7 +27,11 @@ enum class QueueType : uint8_t CallstackSampleContextSwitch, FrameImage, ZoneBegin, + ZoneBegin32, + ZoneBegin16, ZoneBeginCallstack, + ZoneBeginCallstack32, + ZoneBeginCallstack16, ZoneEnd, ZoneEnd32, ZoneEnd16, @@ -155,6 +159,18 @@ struct QueueZoneBeginThread : public QueueZoneBegin uint32_t thread; }; +struct QueueZoneBegin32 +{ + uint32_t time; + uint64_t srcloc; +}; + +struct QueueZoneBegin16 +{ + uint16_t time; + uint64_t srcloc; +}; + struct QueueZoneEnd { int64_t time; @@ -796,6 +812,8 @@ struct QueueItem QueueZoneBegin zoneBegin; QueueZoneBeginLean zoneBeginLean; QueueZoneBeginThread zoneBeginThread; + QueueZoneBegin32 zoneBegin32; + QueueZoneBegin16 zoneBegin16; QueueZoneEnd zoneEnd; QueueZoneEnd32 zoneEnd32; QueueZoneEnd16 zoneEnd16; @@ -907,7 +925,11 @@ static constexpr size_t QueueDataSize[] = { sizeof( QueueHeader ) + sizeof( QueueCallstackSample ), // context switch sizeof( QueueHeader ) + sizeof( QueueFrameImage ), sizeof( QueueHeader ) + sizeof( QueueZoneBegin ), + sizeof( QueueHeader ) + sizeof( QueueZoneBegin32 ), + sizeof( QueueHeader ) + sizeof( QueueZoneBegin16 ), sizeof( QueueHeader ) + sizeof( QueueZoneBegin ), // callstack + sizeof( QueueHeader ) + sizeof( QueueZoneBegin32 ), // callstack + sizeof( QueueHeader ) + sizeof( QueueZoneBegin16 ), // callstack sizeof( QueueHeader ) + sizeof( QueueZoneEnd ), sizeof( QueueHeader ) + sizeof( QueueZoneEnd32 ), sizeof( QueueHeader ) + sizeof( QueueZoneEnd16 ), diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index a1611641..aab75ef0 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -4498,10 +4498,22 @@ bool Worker::Process( const QueueItem& ev ) ProcessThreadContext( ev.threadCtx ); break; case QueueType::ZoneBegin: - ProcessZoneBegin( ev.zoneBegin ); + ProcessZoneBegin64( ev.zoneBegin ); + break; + case QueueType::ZoneBegin32: + ProcessZoneBegin32( ev.zoneBegin32 ); + break; + case QueueType::ZoneBegin16: + ProcessZoneBegin16( ev.zoneBegin16 ); break; case QueueType::ZoneBeginCallstack: - ProcessZoneBeginCallstack( ev.zoneBegin ); + ProcessZoneBeginCallstack64( ev.zoneBegin ); + break; + case QueueType::ZoneBeginCallstack32: + ProcessZoneBeginCallstack32( ev.zoneBegin32 ); + break; + case QueueType::ZoneBeginCallstack16: + ProcessZoneBeginCallstack16( ev.zoneBegin16 ); break; case QueueType::ZoneBeginAllocSrcLoc: ProcessZoneBeginAllocSrcLoc( ev.zoneBeginLean ); @@ -4879,6 +4891,31 @@ void Worker::ProcessZoneBegin( const QueueZoneBegin& ev ) ProcessZoneBeginImpl( zone, ev ); } +void Worker::ProcessZoneBegin64( const QueueZoneBegin& ev ) +{ + QueueZoneBegin unpack = ev; + if( ev.time >= 0 ) unpack.time += ProtocolOffset32Bit; + ProcessZoneBegin( unpack ); +} + +void Worker::ProcessZoneBegin32( const QueueZoneBegin32& ev ) +{ + QueueZoneBegin unpack; + unpack.time = int64_t( ev.time + ProtocolOffset16Bit ); + unpack.srcloc = ev.srcloc; + + ProcessZoneBegin( unpack ); +} + +void Worker::ProcessZoneBegin16( const QueueZoneBegin16& ev ) +{ + QueueZoneBegin unpack; + unpack.time = ev.time; + unpack.srcloc = ev.srcloc; + + ProcessZoneBegin( unpack ); +} + void Worker::ProcessZoneBeginCallstack( const QueueZoneBegin& ev ) { auto zone = AllocZoneEvent(); @@ -4891,6 +4928,31 @@ void Worker::ProcessZoneBeginCallstack( const QueueZoneBegin& ev ) it->second = 0; } +void Worker::ProcessZoneBeginCallstack64( const QueueZoneBegin& ev ) +{ + QueueZoneBegin unpack = ev; + if( ev.time >= 0 ) unpack.time += ProtocolOffset32Bit; + ProcessZoneBeginCallstack( unpack ); +} + +void Worker::ProcessZoneBeginCallstack32( const QueueZoneBegin32& ev ) +{ + QueueZoneBegin unpack; + unpack.time = int64_t( ev.time + ProtocolOffset16Bit ); + unpack.srcloc = ev.srcloc; + + ProcessZoneBeginCallstack( unpack ); +} + +void Worker::ProcessZoneBeginCallstack16( const QueueZoneBegin16& ev ) +{ + QueueZoneBegin unpack; + unpack.time = ev.time; + unpack.srcloc = ev.srcloc; + + ProcessZoneBeginCallstack( unpack ); +} + void Worker::ProcessZoneBeginAllocSrcLoc( const QueueZoneBeginLean& ev ) { auto zone = AllocZoneEvent(); diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 04299cce..b032fbd1 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -722,7 +722,13 @@ private: tracy_force_inline bool Process( const QueueItem& ev ); tracy_force_inline void ProcessThreadContext( const QueueThreadContext& ev ); tracy_force_inline void ProcessZoneBegin( const QueueZoneBegin& ev ); + tracy_force_inline void ProcessZoneBegin64( const QueueZoneBegin& ev ); + tracy_force_inline void ProcessZoneBegin32( const QueueZoneBegin32& ev ); + tracy_force_inline void ProcessZoneBegin16( const QueueZoneBegin16& ev ); tracy_force_inline void ProcessZoneBeginCallstack( const QueueZoneBegin& ev ); + tracy_force_inline void ProcessZoneBeginCallstack64( const QueueZoneBegin& ev ); + tracy_force_inline void ProcessZoneBeginCallstack32( const QueueZoneBegin32& ev ); + tracy_force_inline void ProcessZoneBeginCallstack16( const QueueZoneBegin16& ev ); tracy_force_inline void ProcessZoneBeginAllocSrcLoc( const QueueZoneBeginLean& ev ); tracy_force_inline void ProcessZoneBeginAllocSrcLocCallstack( const QueueZoneBeginLean& ev ); tracy_force_inline void ProcessZoneEnd( const QueueZoneEnd& ev );