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
This commit is contained in:
Bartosz Taudul
2026-05-06 02:13:38 +02:00
parent b1768b98a5
commit 4d094c108d
5 changed files with 86 additions and 4 deletions

View File

@@ -43,13 +43,11 @@
# include <sys/mman.h>
# include <sys/system_properties.h>
# include <stdio.h>
# include <stdint.h>
# include <algorithm>
# include <vector>
#endif
#ifdef __QNX__
# include <stdint.h>
# include <stdio.h>
# include <string.h>
# include <sys/syspage.h>
@@ -62,6 +60,7 @@
#include <chrono>
#include <limits>
#include <new>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
@@ -2608,6 +2607,24 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
int64_t t = MemRead<int64_t>( &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<int64_t>( &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;
}

View File

@@ -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

View File

@@ -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 ),

View File

@@ -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;

View File

@@ -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 );