Make sure source file data is properly tracked.

This commit is contained in:
Bartosz Taudul 2022-10-13 19:00:22 +02:00
parent fc85e46f31
commit b88ef29792
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
6 changed files with 44 additions and 21 deletions

View File

@ -2496,7 +2496,8 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
{
auto ptr = (const char*)MemRead<uint64_t>( &item->sourceCodeMetadata.ptr );
auto size = MemRead<uint32_t>( &item->sourceCodeMetadata.size );
SendLongString( (uint64_t)ptr, ptr, size, QueueType::SourceCode );
auto id = MemRead<uint32_t>( &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;
}

View File

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

View File

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

View File

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

View File

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

View File

@ -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<uint64_t, uint32_t> m_nextCallstack;
std::vector<const char*> m_sourceCodeQuery;
unordered_flat_map<uint32_t, const char*> m_sourceCodeQuery;
uint32_t m_nextSourceCodeQuery = 0;
};
}