mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
Change thread id size from 64 to 32 bits.
Both Windows and Linux use 32-bit thread identifiers. MacOS has a 64-bit counter, but in practice it will never overflow during profiling and no false aliasing will happen. These changes are only done client-side and in the network protocol. The server still uses 64-bit thread identifiers, to enable virtual threads, etc.
This commit is contained in:
@@ -127,7 +127,7 @@ struct ProducerWrapper
|
||||
|
||||
struct ThreadHandleWrapper
|
||||
{
|
||||
uint64_t val;
|
||||
uint32_t val;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1057,7 +1057,7 @@ TRACY_API int64_t GetInitTime() { return GetProfilerData().initTime; }
|
||||
TRACY_API std::atomic<uint32_t>& GetLockCounter() { return GetProfilerData().lockCounter; }
|
||||
TRACY_API std::atomic<uint8_t>& GetGpuCtxCounter() { return GetProfilerData().gpuCtxCounter; }
|
||||
TRACY_API GpuCtxWrapper& GetGpuCtx() { return GetProfilerThreadData().gpuCtx; }
|
||||
TRACY_API uint64_t GetThreadHandle() { return detail::GetThreadHandleImpl(); }
|
||||
TRACY_API uint32_t GetThreadHandle() { return detail::GetThreadHandleImpl(); }
|
||||
std::atomic<ThreadNameData*>& GetThreadNameData() { return GetProfilerData().threadNameData; }
|
||||
|
||||
# ifdef TRACY_ON_DEMAND
|
||||
@@ -1116,7 +1116,7 @@ TRACY_API int64_t GetInitTime() { return s_initTime.val; }
|
||||
TRACY_API std::atomic<uint32_t>& GetLockCounter() { return s_lockCounter; }
|
||||
TRACY_API std::atomic<uint8_t>& GetGpuCtxCounter() { return s_gpuCtxCounter; }
|
||||
TRACY_API GpuCtxWrapper& GetGpuCtx() { return s_gpuCtx; }
|
||||
TRACY_API uint64_t GetThreadHandle() { return s_threadHandle.val; }
|
||||
TRACY_API uint32_t GetThreadHandle() { return s_threadHandle.val; }
|
||||
|
||||
std::atomic<ThreadNameData*>& GetThreadNameData() { return s_threadNameData; }
|
||||
|
||||
@@ -1957,7 +1957,7 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
|
||||
{
|
||||
bool connectionLost = false;
|
||||
const auto sz = GetQueue().try_dequeue_bulk_single( token,
|
||||
[this, &connectionLost] ( const uint64_t& threadId )
|
||||
[this, &connectionLost] ( const uint32_t& threadId )
|
||||
{
|
||||
if( threadId != m_threadCtx )
|
||||
{
|
||||
|
||||
@@ -62,7 +62,7 @@ TRACY_API Profiler& GetProfiler();
|
||||
TRACY_API std::atomic<uint32_t>& GetLockCounter();
|
||||
TRACY_API std::atomic<uint8_t>& GetGpuCtxCounter();
|
||||
TRACY_API GpuCtxWrapper& GetGpuCtx();
|
||||
TRACY_API uint64_t GetThreadHandle();
|
||||
TRACY_API uint32_t GetThreadHandle();
|
||||
TRACY_API bool ProfilerAvailable();
|
||||
TRACY_API int64_t GetFrequencyQpc();
|
||||
|
||||
@@ -704,7 +704,7 @@ private:
|
||||
#endif
|
||||
}
|
||||
|
||||
static tracy_force_inline void SendMemAlloc( QueueType type, const uint64_t thread, const void* ptr, size_t size )
|
||||
static tracy_force_inline void SendMemAlloc( QueueType type, const uint32_t thread, const void* ptr, size_t size )
|
||||
{
|
||||
assert( type == QueueType::MemAlloc || type == QueueType::MemAllocCallstack || type == QueueType::MemAllocNamed || type == QueueType::MemAllocCallstackNamed );
|
||||
|
||||
@@ -727,7 +727,7 @@ private:
|
||||
GetProfiler().m_serialQueue.commit_next();
|
||||
}
|
||||
|
||||
static tracy_force_inline void SendMemFree( QueueType type, const uint64_t thread, const void* ptr )
|
||||
static tracy_force_inline void SendMemFree( QueueType type, const uint32_t thread, const void* ptr )
|
||||
{
|
||||
assert( type == QueueType::MemFree || type == QueueType::MemFreeCallstack || type == QueueType::MemFreeNamed || type == QueueType::MemFreeCallstackNamed );
|
||||
|
||||
@@ -756,7 +756,7 @@ private:
|
||||
uint64_t m_resolution;
|
||||
uint64_t m_delay;
|
||||
std::atomic<int64_t> m_timeBegin;
|
||||
uint64_t m_mainThread;
|
||||
uint32_t m_mainThread;
|
||||
uint64_t m_epoch, m_exectime;
|
||||
std::atomic<bool> m_shutdown;
|
||||
std::atomic<bool> m_shutdownManual;
|
||||
@@ -768,7 +768,7 @@ private:
|
||||
std::atomic<uint32_t> m_zoneId;
|
||||
int64_t m_samplingPeriod;
|
||||
|
||||
uint64_t m_threadCtx;
|
||||
uint32_t m_threadCtx;
|
||||
int64_t m_refTimeThread;
|
||||
int64_t m_refTimeSerial;
|
||||
int64_t m_refTimeCtx;
|
||||
|
||||
@@ -159,10 +159,8 @@ void WINAPI EventRecordCallback( PEVENT_RECORD record )
|
||||
|
||||
TracyLfqPrepare( QueueType::ContextSwitch );
|
||||
MemWrite( &item->contextSwitch.time, hdr.TimeStamp.QuadPart );
|
||||
memcpy( &item->contextSwitch.oldThread, &cswitch->oldThreadId, sizeof( cswitch->oldThreadId ) );
|
||||
memcpy( &item->contextSwitch.newThread, &cswitch->newThreadId, sizeof( cswitch->newThreadId ) );
|
||||
memset( ((char*)&item->contextSwitch.oldThread)+4, 0, 4 );
|
||||
memset( ((char*)&item->contextSwitch.newThread)+4, 0, 4 );
|
||||
MemWrite( &item->contextSwitch.oldThread, cswitch->oldThreadId );
|
||||
MemWrite( &item->contextSwitch.newThread, cswitch->newThreadId );
|
||||
MemWrite( &item->contextSwitch.cpu, record->BufferContext.ProcessorNumber );
|
||||
MemWrite( &item->contextSwitch.reason, cswitch->oldThreadWaitReason );
|
||||
MemWrite( &item->contextSwitch.state, cswitch->oldThreadState );
|
||||
@@ -174,8 +172,7 @@ void WINAPI EventRecordCallback( PEVENT_RECORD record )
|
||||
|
||||
TracyLfqPrepare( QueueType::ThreadWakeup );
|
||||
MemWrite( &item->threadWakeup.time, hdr.TimeStamp.QuadPart );
|
||||
memcpy( &item->threadWakeup.thread, &rt->threadId, sizeof( rt->threadId ) );
|
||||
memset( ((char*)&item->threadWakeup.thread)+4, 0, 4 );
|
||||
MemWrite( &item->threadWakeup.thread, rt->threadId );
|
||||
TracyLfqCommit;
|
||||
}
|
||||
else if( hdr.EventDescriptor.Opcode == 1 || hdr.EventDescriptor.Opcode == 3 )
|
||||
@@ -205,7 +202,7 @@ void WINAPI EventRecordCallback( PEVENT_RECORD record )
|
||||
memcpy( trace+1, sw->stack, sizeof( uint64_t ) * sz );
|
||||
TracyLfqPrepare( QueueType::CallstackSample );
|
||||
MemWrite( &item->callstackSampleFat.time, sw->eventTimeStamp );
|
||||
MemWrite( &item->callstackSampleFat.thread, (uint64_t)sw->stackThread );
|
||||
MemWrite( &item->callstackSampleFat.thread, sw->stackThread );
|
||||
MemWrite( &item->callstackSampleFat.ptr, (uint64_t)trace );
|
||||
TracyLfqCommit;
|
||||
}
|
||||
@@ -1026,7 +1023,7 @@ static void SetupSampling( int64_t& samplingPeriod )
|
||||
|
||||
TracyLfqPrepare( QueueType::CallstackSample );
|
||||
MemWrite( &item->callstackSampleFat.time, t0 );
|
||||
MemWrite( &item->callstackSampleFat.thread, (uint64_t)tid );
|
||||
MemWrite( &item->callstackSampleFat.thread, tid );
|
||||
MemWrite( &item->callstackSampleFat.ptr, (uint64_t)trace );
|
||||
TracyLfqCommit;
|
||||
}
|
||||
@@ -1500,7 +1497,7 @@ static void HandleTraceLine( const char* line )
|
||||
AdvanceTo<8>( line, "prev_pid" );
|
||||
line += 9;
|
||||
|
||||
const auto oldPid = ReadNumber( line );
|
||||
const auto oldPid = uint32_t( ReadNumber( line ) );
|
||||
line++;
|
||||
|
||||
AdvanceTo<10>( line, "prev_state" );
|
||||
@@ -1512,7 +1509,7 @@ static void HandleTraceLine( const char* line )
|
||||
AdvanceTo<8>( line, "next_pid" );
|
||||
line += 9;
|
||||
|
||||
const auto newPid = ReadNumber( line );
|
||||
const auto newPid = uint32_t( ReadNumber( line ) );
|
||||
|
||||
uint8_t reason = 100;
|
||||
|
||||
@@ -1532,7 +1529,7 @@ static void HandleTraceLine( const char* line )
|
||||
AdvanceTo<4>( line, "pid=" );
|
||||
line += 4;
|
||||
|
||||
const auto pid = ReadNumber( line );
|
||||
const auto pid = uint32_t( ReadNumber( line ) );
|
||||
|
||||
TracyLfqPrepare( QueueType::ThreadWakeup );
|
||||
MemWrite( &item->threadWakeup.time, time );
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace details
|
||||
ConcurrentQueueProducerTypelessBase* next;
|
||||
std::atomic<bool> inactive;
|
||||
ProducerToken* token;
|
||||
uint64_t threadId;
|
||||
uint32_t threadId;
|
||||
|
||||
ConcurrentQueueProducerTypelessBase()
|
||||
: next(nullptr), inactive(false), token(nullptr), threadId(0)
|
||||
|
||||
Reference in New Issue
Block a user