diff --git a/public/client/TracyProfiler.cpp b/public/client/TracyProfiler.cpp index a381f65b..ea168e4f 100644 --- a/public/client/TracyProfiler.cpp +++ b/public/client/TracyProfiler.cpp @@ -2496,7 +2496,8 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token ) { auto ptr = (const char*)MemRead( &item->sourceCodeMetadata.ptr ); auto size = MemRead( &item->sourceCodeMetadata.size ); - SendLongString( (uint64_t)ptr, ptr, size, QueueType::SourceCode ); + auto id = MemRead( &item->sourceCodeMetadata.id ); + SendLongString( (uint64_t)id, ptr, size, QueueType::SourceCode ); tracy_free_fast( (void*)ptr ); ++item; continue; @@ -3167,11 +3168,11 @@ void Profiler::QueueKernelCode( uint64_t symbol, uint32_t size ) #endif } -void Profiler::QueueSourceCodeQuery() +void Profiler::QueueSourceCodeQuery( uint32_t id ) { assert( m_exectime != 0 ); assert( m_queryData ); - m_symbolQueue.emplace( SymbolQueueItem { SymbolQueueItemType::SourceCode, uint64_t( m_queryData ), uint64_t( m_queryImage ) } ); + m_symbolQueue.emplace( SymbolQueueItem { SymbolQueueItemType::SourceCode, uint64_t( m_queryData ), uint64_t( m_queryImage ), id } ); m_queryData = nullptr; m_queryImage = nullptr; } @@ -3264,7 +3265,7 @@ void Profiler::HandleSymbolQueueItem( const SymbolQueueItem& si ) break; } case SymbolQueueItemType::SourceCode: - HandleSourceCodeQuery( (char*)si.ptr, (char*)si.extra ); + HandleSourceCodeQuery( (char*)si.ptr, (char*)si.extra, si.id ); break; default: assert( false ); @@ -3382,7 +3383,7 @@ bool Profiler::HandleServerQuery() break; #endif case ServerQuerySourceCode: - QueueSourceCodeQuery(); + QueueSourceCodeQuery( uint32_t( ptr ) ); break; case ServerQueryDataTransfer: if( m_queryData ) @@ -3808,7 +3809,7 @@ void Profiler::HandleSymbolCodeQuery( uint64_t symbol, uint32_t size ) } } -void Profiler::HandleSourceCodeQuery( char* data, char* image ) +void Profiler::HandleSourceCodeQuery( char* data, char* image, uint32_t id ) { bool ok = false; struct stat st; @@ -3827,6 +3828,7 @@ void Profiler::HandleSourceCodeQuery( char* data, char* image ) TracyLfqPrepare( QueueType::SourceCodeMetadata ); MemWrite( &item->sourceCodeMetadata.ptr, (uint64_t)ptr ); MemWrite( &item->sourceCodeMetadata.size, (uint32_t)rd ); + MemWrite( &item->sourceCodeMetadata.id, id ); TracyLfqCommit; ok = true; } @@ -3857,6 +3859,7 @@ void Profiler::HandleSourceCodeQuery( char* data, char* image ) TracyLfqPrepare( QueueType::SourceCodeMetadata ); MemWrite( &item->sourceCodeMetadata.ptr, (uint64_t)ptr ); MemWrite( &item->sourceCodeMetadata.size, (uint32_t)rd ); + MemWrite( &item->sourceCodeMetadata.id, id ); TracyLfqCommit; ok = true; } @@ -3882,6 +3885,7 @@ void Profiler::HandleSourceCodeQuery( char* data, char* image ) TracyLfqPrepare( QueueType::SourceCodeMetadata ); MemWrite( &item->sourceCodeMetadata.ptr, (uint64_t)ptr ); MemWrite( &item->sourceCodeMetadata.size, (uint32_t)sz ); + MemWrite( &item->sourceCodeMetadata.id, id ); TracyLfqCommit; ok = true; } @@ -3891,6 +3895,7 @@ void Profiler::HandleSourceCodeQuery( char* data, char* image ) if( !ok ) { TracyLfqPrepare( QueueType::AckSourceCodeNotAvailable ); + MemWrite( &item->sourceCodeNotAvailable, id ); TracyLfqCommit; } diff --git a/public/client/TracyProfiler.hpp b/public/client/TracyProfiler.hpp index c4f71275..23603535 100644 --- a/public/client/TracyProfiler.hpp +++ b/public/client/TracyProfiler.hpp @@ -177,6 +177,7 @@ class Profiler SymbolQueueItemType type; uint64_t ptr; uint64_t extra; + uint32_t id; }; public: @@ -808,13 +809,13 @@ private: void QueueSymbolQuery( uint64_t symbol ); void QueueExternalName( uint64_t ptr ); void QueueKernelCode( uint64_t symbol, uint32_t size ); - void QueueSourceCodeQuery(); + void QueueSourceCodeQuery( uint32_t id ); bool HandleServerQuery(); void HandleDisconnect(); void HandleParameter( uint64_t payload ); void HandleSymbolCodeQuery( uint64_t symbol, uint32_t size ); - void HandleSourceCodeQuery( char* data, char* image ); + void HandleSourceCodeQuery( char* data, char* image, uint32_t id ); void AckServerQuery(); void AckSymbolCodeNotAvailable(); diff --git a/public/common/TracyProtocol.hpp b/public/common/TracyProtocol.hpp index 207b8786..d73840b2 100644 --- a/public/common/TracyProtocol.hpp +++ b/public/common/TracyProtocol.hpp @@ -9,7 +9,7 @@ namespace tracy constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; } -enum : uint32_t { ProtocolVersion = 62 }; +enum : uint32_t { ProtocolVersion = 63 }; enum : uint16_t { BroadcastVersion = 3 }; using lz4sz_t = uint32_t; diff --git a/public/common/TracyQueue.hpp b/public/common/TracyQueue.hpp index 7c5ae4d9..431fa484 100644 --- a/public/common/TracyQueue.hpp +++ b/public/common/TracyQueue.hpp @@ -615,6 +615,11 @@ struct QueueParamSetup int32_t val; }; +struct QueueSourceCodeNotAvailable +{ + uint32_t id; +}; + struct QueueCpuTopology { uint32_t package; @@ -640,6 +645,7 @@ struct QueueSourceCodeMetadata { uint64_t ptr; uint32_t size; + uint32_t id; }; struct QueueHeader @@ -733,6 +739,7 @@ struct QueueItem QueueExternalNameMetadata externalNameMetadata; QueueSymbolCodeMetadata symbolCodeMetadata; QueueSourceCodeMetadata sourceCodeMetadata; + QueueSourceCodeNotAvailable sourceCodeNotAvailable; QueueFiberEnter fiberEnter; QueueFiberLeave fiberLeave; }; @@ -835,7 +842,7 @@ static constexpr size_t QueueDataSize[] = { sizeof( QueueHeader ) + sizeof( QueuePlotConfig ), sizeof( QueueHeader ) + sizeof( QueueParamSetup ), sizeof( QueueHeader ), // server query acknowledgement - sizeof( QueueHeader ), // source code not available + sizeof( QueueHeader ) + sizeof( QueueSourceCodeNotAvailable ), sizeof( QueueHeader ), // symbol code not available sizeof( QueueHeader ) + sizeof( QueueCpuTopology ), sizeof( QueueHeader ), // single string data diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 1dce5e92..fd04ab8a 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -3444,8 +3444,9 @@ void Worker::QuerySourceFile( const char* fn, const char* image ) { if( image ) QueryDataTransfer( image, strlen( image ) + 1 ); QueryDataTransfer( fn, strlen( fn ) + 1 ); - m_sourceCodeQuery.emplace_back( fn ); - Query( ServerQuerySourceCode, 0 ); + m_sourceCodeQuery.emplace( m_nextSourceCodeQuery, fn ); + Query( ServerQuerySourceCode, m_nextSourceCodeQuery ); + m_nextSourceCodeQuery++; } void Worker::QueryDataTransfer( const void* ptr, size_t size ) @@ -3503,7 +3504,7 @@ bool Worker::DispatchProcess( const QueueItem& ev, const char*& ptr ) m_serverQuerySpaceLeft++; break; case QueueType::SourceCode: - AddSourceCode( ptr, sz ); + AddSourceCode( (uint32_t)ev.stringTransfer.ptr, ptr, sz ); m_serverQuerySpaceLeft++; break; default: @@ -4161,11 +4162,12 @@ void Worker::AddSymbolCode( uint64_t ptr, const char* data, size_t sz ) } -void Worker::AddSourceCode( const char* data, size_t sz ) +void Worker::AddSourceCode( uint32_t id, const char* data, size_t sz ) { - assert( !m_sourceCodeQuery.empty() ); - auto file = m_sourceCodeQuery.front(); - m_sourceCodeQuery.erase( m_sourceCodeQuery.begin() ); + auto it = m_sourceCodeQuery.find( id ); + assert( it != m_sourceCodeQuery.end() ); + auto file = it->second; + m_sourceCodeQuery.erase( it ); if( m_data.sourceFileCache.find( file ) != m_data.sourceFileCache.end() ) return; auto src = (char*)m_slab.AllocBig( sz ); memcpy( src, data, sz ); @@ -4941,8 +4943,7 @@ bool Worker::Process( const QueueItem& ev ) m_serverQuerySpaceLeft++; break; case QueueType::AckSourceCodeNotAvailable: - assert( !m_sourceCodeQuery.empty() ); - m_sourceCodeQuery.erase( m_sourceCodeQuery.begin() ); + ProcessSourceCodeNotAvailable( ev.sourceCodeNotAvailable ); m_serverQuerySpaceLeft++; break; case QueueType::AckSymbolCodeNotAvailable: @@ -7031,6 +7032,13 @@ void Worker::ProcessParamSetup( const QueueParamSetup& ev ) m_params.push_back( Parameter { ev.idx, StringRef( StringRef::Ptr, ev.name ), bool( ev.isBool ), ev.val } ); } +void Worker::ProcessSourceCodeNotAvailable( const QueueSourceCodeNotAvailable& ev ) +{ + auto it = m_sourceCodeQuery.find( ev.id ); + assert( it != m_sourceCodeQuery.end() ); + m_sourceCodeQuery.erase( it ); +} + void Worker::ProcessCpuTopology( const QueueCpuTopology& ev ) { auto package = m_data.cpuTopology.find( ev.package ); diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 6b324de5..888f6080 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -744,6 +744,7 @@ private: tracy_force_inline void ProcessHwSampleBranchRetired( const QueueHwSample& ev ); tracy_force_inline void ProcessHwSampleBranchMiss( const QueueHwSample& ev ); tracy_force_inline void ProcessParamSetup( const QueueParamSetup& ev ); + tracy_force_inline void ProcessSourceCodeNotAvailable( const QueueSourceCodeNotAvailable& ev ); tracy_force_inline void ProcessCpuTopology( const QueueCpuTopology& ev ); tracy_force_inline void ProcessMemNamePayload( const QueueMemNamePayload& ev ); tracy_force_inline void ProcessFiberEnter( const QueueFiberEnter& ev ); @@ -861,7 +862,7 @@ private: void AddExternalThreadName( uint64_t ptr, const char* str, size_t sz ); void AddFrameImageData( uint64_t ptr, const char* data, size_t sz ); void AddSymbolCode( uint64_t ptr, const char* data, size_t sz ); - void AddSourceCode( const char* data, size_t sz ); + void AddSourceCode( uint32_t id, const char* data, size_t sz ); tracy_force_inline void AddCallstackPayload( uint64_t ptr, const char* data, size_t sz ); tracy_force_inline void AddCallstackAllocPayload( uint64_t ptr, const char* data, size_t sz ); @@ -1062,7 +1063,8 @@ private: size_t m_tmpBufSize = 0; unordered_flat_map m_nextCallstack; - std::vector m_sourceCodeQuery; + unordered_flat_map m_sourceCodeQuery; + uint32_t m_nextSourceCodeQuery = 0; }; }