Add callstack sample events with 32 and 16 bit timestamps.

This commit is contained in:
Bartosz Taudul
2026-05-07 02:12:22 +02:00
parent ccaef5ba0b
commit 305382453d
4 changed files with 112 additions and 4 deletions

View File

@@ -2580,6 +2580,24 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
int64_t t = MemRead<int64_t>( &item->callstackSampleFat.time );
int64_t dt = t - refCtx;
refCtx = t;
if( dt >= 0 )
{
if( dt < ProtocolOffset16Bit )
{
idx = QueueType( idx ) == QueueType::CallstackSample ? (int)QueueType::CallstackSample16 : (int)QueueType::CallstackSampleContextSwitch16;
MemWrite( &item->hdr.idx, idx );
}
else if( dt < ProtocolOffset32Bit )
{
dt -= ProtocolOffset16Bit;
idx = QueueType( idx ) == QueueType::CallstackSample ? (int)QueueType::CallstackSample32 : (int)QueueType::CallstackSampleContextSwitch32;
MemWrite( &item->hdr.idx, idx );
}
else
{
dt -= ProtocolOffset32Bit;
}
}
MemWrite( &item->callstackSampleFat.time, dt );
break;
}

View File

@@ -24,7 +24,11 @@ enum class QueueType : uint8_t
Callstack,
CallstackAlloc,
CallstackSample,
CallstackSample32,
CallstackSample16,
CallstackSampleContextSwitch,
CallstackSampleContextSwitch32,
CallstackSampleContextSwitch16,
FrameImage,
ZoneBegin,
ZoneBegin32,
@@ -638,8 +642,8 @@ struct QueueCallstackAllocFatThread : public QueueCallstackAllocFat
struct QueueCallstackSample
{
int64_t time;
uint32_t thread;
int64_t time;
};
struct QueueCallstackSampleFat : public QueueCallstackSample
@@ -647,6 +651,18 @@ struct QueueCallstackSampleFat : public QueueCallstackSample
uint64_t ptr;
};
struct QueueCallstackSample32
{
uint32_t thread;
uint32_t time;
};
struct QueueCallstackSample16
{
uint32_t thread;
uint16_t time;
};
struct QueueCallstackFrameSize
{
uint64_t ptr;
@@ -878,6 +894,8 @@ struct QueueItem
QueueCallstackAllocFatThread callstackAllocFatThread;
QueueCallstackSample callstackSample;
QueueCallstackSampleFat callstackSampleFat;
QueueCallstackSample32 callstackSample32;
QueueCallstackSample16 callstackSample16;
QueueCallstackFrameSize callstackFrameSize;
QueueCallstackFrameSizeFat callstackFrameSizeFat;
QueueCallstackFrame callstackFrame;
@@ -922,7 +940,11 @@ static constexpr size_t QueueDataSize[] = {
sizeof( QueueHeader ), // callstack
sizeof( QueueHeader ), // callstack alloc
sizeof( QueueHeader ) + sizeof( QueueCallstackSample ),
sizeof( QueueHeader ) + sizeof( QueueCallstackSample ), // context switch
sizeof( QueueHeader ) + sizeof( QueueCallstackSample32 ),
sizeof( QueueHeader ) + sizeof( QueueCallstackSample16 ),
sizeof( QueueHeader ) + sizeof( QueueCallstackSample ), // context switch
sizeof( QueueHeader ) + sizeof( QueueCallstackSample32 ), // context switch
sizeof( QueueHeader ) + sizeof( QueueCallstackSample16 ), // context switch
sizeof( QueueHeader ) + sizeof( QueueFrameImage ),
sizeof( QueueHeader ) + sizeof( QueueZoneBegin ),
sizeof( QueueHeader ) + sizeof( QueueZoneBegin32 ),

View File

@@ -4722,10 +4722,22 @@ bool Worker::Process( const QueueItem& ev )
ProcessCallstack();
break;
case QueueType::CallstackSample:
ProcessCallstackSample( ev.callstackSample );
ProcessCallstackSample64( ev.callstackSample );
break;
case QueueType::CallstackSample32:
ProcessCallstackSample32( ev.callstackSample32 );
break;
case QueueType::CallstackSample16:
ProcessCallstackSample16( ev.callstackSample16 );
break;
case QueueType::CallstackSampleContextSwitch:
ProcessCallstackSampleContextSwitch( ev.callstackSample );
ProcessCallstackSampleContextSwitch64( ev.callstackSample );
break;
case QueueType::CallstackSampleContextSwitch32:
ProcessCallstackSampleContextSwitch32( ev.callstackSample32 );
break;
case QueueType::CallstackSampleContextSwitch16:
ProcessCallstackSampleContextSwitch16( ev.callstackSample16 );
break;
case QueueType::CallstackFrameSize:
ProcessCallstackFrameSize( ev.callstackFrameSize );
@@ -6650,6 +6662,31 @@ void Worker::ProcessCallstackSample( const QueueCallstackSample& ev )
}
}
void Worker::ProcessCallstackSample64( const QueueCallstackSample& ev )
{
QueueCallstackSample unpack = ev;
if( ev.time >= 0 ) unpack.time += ProtocolOffset32Bit;
ProcessCallstackSample( unpack );
}
void Worker::ProcessCallstackSample32( const QueueCallstackSample32& ev )
{
QueueCallstackSample unpack = {
.thread = ev.thread,
.time = int64_t( ev.time + ProtocolOffset16Bit )
};
ProcessCallstackSample( unpack );
}
void Worker::ProcessCallstackSample16( const QueueCallstackSample16& ev )
{
QueueCallstackSample unpack = {
.thread = ev.thread,
.time = int64_t( ev.time )
};
ProcessCallstackSample( unpack );
}
void Worker::ProcessCallstackSampleContextSwitch( const QueueCallstackSample& ev )
{
assert( m_pendingCallstackId != 0 );
@@ -6671,6 +6708,31 @@ void Worker::ProcessCallstackSampleContextSwitch( const QueueCallstackSample& ev
td.ctxSwitchSamples.push_back( sd );
}
void Worker::ProcessCallstackSampleContextSwitch64( const QueueCallstackSample& ev )
{
QueueCallstackSample unpack = ev;
if( ev.time >= 0 ) unpack.time += ProtocolOffset32Bit;
ProcessCallstackSampleContextSwitch( unpack );
}
void Worker::ProcessCallstackSampleContextSwitch32( const QueueCallstackSample32& ev )
{
QueueCallstackSample unpack = {
.thread = ev.thread,
.time = int64_t( ev.time + ProtocolOffset16Bit )
};
ProcessCallstackSampleContextSwitch( unpack );
}
void Worker::ProcessCallstackSampleContextSwitch16( const QueueCallstackSample16& ev )
{
QueueCallstackSample unpack = {
.thread = ev.thread,
.time = int64_t( ev.time )
};
ProcessCallstackSampleContextSwitch( unpack );
}
void Worker::ProcessCallstackFrameSize( const QueueCallstackFrameSize& ev )
{
assert( !m_callstackFrameStaging );

View File

@@ -793,7 +793,13 @@ private:
tracy_force_inline void ProcessCallstackSerial();
tracy_force_inline void ProcessCallstack();
tracy_force_inline void ProcessCallstackSample( const QueueCallstackSample& ev );
tracy_force_inline void ProcessCallstackSample64( const QueueCallstackSample& ev );
tracy_force_inline void ProcessCallstackSample32( const QueueCallstackSample32& ev );
tracy_force_inline void ProcessCallstackSample16( const QueueCallstackSample16& ev );
tracy_force_inline void ProcessCallstackSampleContextSwitch( const QueueCallstackSample& ev );
tracy_force_inline void ProcessCallstackSampleContextSwitch64( const QueueCallstackSample& ev );
tracy_force_inline void ProcessCallstackSampleContextSwitch32( const QueueCallstackSample32& ev );
tracy_force_inline void ProcessCallstackSampleContextSwitch16( const QueueCallstackSample16& ev );
tracy_force_inline void ProcessCallstackFrameSize( const QueueCallstackFrameSize& ev );
tracy_force_inline void ProcessCallstackFrame( const QueueCallstackFrame& ev, bool querySymbols );
tracy_force_inline void ProcessSymbolInformation( const QueueSymbolInformation& ev );