mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 02:31:48 +00:00
Send delta times for context switches.
This commit is contained in:
parent
25b3cdc1ee
commit
8fa5188176
@ -1315,6 +1315,7 @@ void Profiler::Worker()
|
||||
|
||||
m_threadCtx = 0;
|
||||
m_refTimeSerial = 0;
|
||||
m_refTimeCtx = 0;
|
||||
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
OnDemandPayloadMessage onDemand;
|
||||
@ -1785,6 +1786,22 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
|
||||
MemWrite( &item->plotData.time, dt );
|
||||
break;
|
||||
}
|
||||
case QueueType::ContextSwitch:
|
||||
{
|
||||
int64_t t = MemRead<int64_t>( &item->contextSwitch.time );
|
||||
int64_t dt = t - m_refTimeCtx;
|
||||
m_refTimeCtx = t;
|
||||
MemWrite( &item->contextSwitch.time, dt );
|
||||
break;
|
||||
}
|
||||
case QueueType::ThreadWakeup:
|
||||
{
|
||||
int64_t t = MemRead<int64_t>( &item->threadWakeup.time );
|
||||
int64_t dt = t - m_refTimeCtx;
|
||||
m_refTimeCtx = t;
|
||||
MemWrite( &item->threadWakeup.time, dt );
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert( false );
|
||||
break;
|
||||
@ -1820,6 +1837,9 @@ Profiler::DequeueStatus Profiler::DequeueContextSwitches( tracy::moodycamel::Con
|
||||
timeStop = -1;
|
||||
return DequeueStatus::Success;
|
||||
}
|
||||
int64_t dt = csTime - m_refTimeCtx;
|
||||
m_refTimeCtx = csTime;
|
||||
MemWrite( &item->contextSwitch.time, dt );
|
||||
if( !AppendData( item, QueueDataSize[(int)QueueType::ContextSwitch] ) ) return DequeueStatus::ConnectionLost;
|
||||
}
|
||||
else if( idx == (uint8_t)QueueType::ThreadWakeup )
|
||||
@ -1830,6 +1850,9 @@ Profiler::DequeueStatus Profiler::DequeueContextSwitches( tracy::moodycamel::Con
|
||||
timeStop = -1;
|
||||
return DequeueStatus::Success;
|
||||
}
|
||||
int64_t dt = csTime - m_refTimeCtx;
|
||||
m_refTimeCtx = csTime;
|
||||
MemWrite( &item->threadWakeup.time, dt );
|
||||
if( !AppendData( item, QueueDataSize[(int)QueueType::ThreadWakeup] ) ) return DequeueStatus::ConnectionLost;
|
||||
}
|
||||
item++;
|
||||
|
@ -545,6 +545,7 @@ private:
|
||||
uint64_t m_threadCtx;
|
||||
int64_t m_refTimeThread;
|
||||
int64_t m_refTimeSerial;
|
||||
int64_t m_refTimeCtx;
|
||||
|
||||
void* m_stream; // LZ4_stream_t*
|
||||
char* m_buffer;
|
||||
|
@ -9,7 +9,7 @@
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
enum : uint32_t { ProtocolVersion = 19 };
|
||||
enum : uint32_t { ProtocolVersion = 20 };
|
||||
enum : uint32_t { BroadcastVersion = 0 };
|
||||
|
||||
using lz4sz_t = uint32_t;
|
||||
|
@ -39,6 +39,8 @@ enum class QueueType : uint8_t
|
||||
GpuZoneBeginCallstackSerial,
|
||||
GpuZoneEndSerial,
|
||||
PlotData,
|
||||
ContextSwitch,
|
||||
ThreadWakeup,
|
||||
Terminate,
|
||||
KeepAlive,
|
||||
ThreadContext,
|
||||
@ -59,8 +61,6 @@ enum class QueueType : uint8_t
|
||||
CallstackFrameSize,
|
||||
CallstackFrame,
|
||||
SysTimeReport,
|
||||
ContextSwitch,
|
||||
ThreadWakeup,
|
||||
TidToPid,
|
||||
StringData,
|
||||
ThreadName,
|
||||
@ -417,6 +417,8 @@ static const size_t QueueDataSize[] = {
|
||||
sizeof( QueueHeader ) + sizeof( QueueGpuZoneBegin ), // serial, callstack
|
||||
sizeof( QueueHeader ) + sizeof( QueueGpuZoneEnd ), // serial
|
||||
sizeof( QueueHeader ) + sizeof( QueuePlotData ),
|
||||
sizeof( QueueHeader ) + sizeof( QueueContextSwitch ),
|
||||
sizeof( QueueHeader ) + sizeof( QueueThreadWakeup ),
|
||||
// above items must be first
|
||||
sizeof( QueueHeader ), // terminate
|
||||
sizeof( QueueHeader ), // keep alive
|
||||
@ -438,8 +440,6 @@ static const size_t QueueDataSize[] = {
|
||||
sizeof( QueueHeader ) + sizeof( QueueCallstackFrameSize ),
|
||||
sizeof( QueueHeader ) + sizeof( QueueCallstackFrame ),
|
||||
sizeof( QueueHeader ) + sizeof( QueueSysTime ),
|
||||
sizeof( QueueHeader ) + sizeof( QueueContextSwitch ),
|
||||
sizeof( QueueHeader ) + sizeof( QueueThreadWakeup ),
|
||||
sizeof( QueueHeader ) + sizeof( QueueTidToPid ),
|
||||
// keep all QueueStringTransfer below
|
||||
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // string data
|
||||
|
@ -4478,7 +4478,9 @@ void Worker::ProcessSysTime( const QueueSysTime& ev )
|
||||
|
||||
void Worker::ProcessContextSwitch( const QueueContextSwitch& ev )
|
||||
{
|
||||
const auto time = TscTime( ev.time - m_data.baseTime );
|
||||
const auto refTime = m_refTimeCtx + ev.time;
|
||||
m_refTimeCtx = refTime;
|
||||
const auto time = TscTime( refTime - m_data.baseTime );
|
||||
if( m_data.lastTime < time ) m_data.lastTime = time;
|
||||
|
||||
if( ev.cpu >= m_data.cpuDataCount ) m_data.cpuDataCount = ev.cpu + 1;
|
||||
@ -4571,7 +4573,9 @@ void Worker::ProcessContextSwitch( const QueueContextSwitch& ev )
|
||||
|
||||
void Worker::ProcessThreadWakeup( const QueueThreadWakeup& ev )
|
||||
{
|
||||
const auto time = TscTime( ev.time - m_data.baseTime );
|
||||
const auto refTime = m_refTimeCtx + ev.time;
|
||||
m_refTimeCtx = refTime;
|
||||
const auto time = TscTime( refTime - m_data.baseTime );
|
||||
if( m_data.lastTime < time ) m_data.lastTime = time;
|
||||
|
||||
auto it = m_data.ctxSwitch.find( ev.thread );
|
||||
|
@ -626,6 +626,7 @@ private:
|
||||
uint64_t m_threadCtx = 0;
|
||||
int64_t m_refTimeThread = 0;
|
||||
int64_t m_refTimeSerial = 0;
|
||||
int64_t m_refTimeCtx = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user