2
0
mirror of https://github.com/wolfpld/tracy synced 2026-01-19 04:52:09 +00:00

Transfer code location strings.

This commit is contained in:
Bartosz Taudul
2019-10-27 18:34:26 +01:00
parent bbdbf2bc78
commit 154a3ead5f
5 changed files with 63 additions and 3 deletions

View File

@@ -2054,7 +2054,9 @@ void Profiler::SendString( uint64_t str, const char* ptr, QueueType type )
type == QueueType::PlotName ||
type == QueueType::FrameName ||
type == QueueType::ExternalName ||
type == QueueType::ExternalThreadName );
type == QueueType::ExternalThreadName ||
type == QueueType::CodeLocationString
);
QueueItem item;
MemWrite( &item.hdr.type, type );
@@ -2258,6 +2260,16 @@ bool Profiler::HandleServerQuery()
SysTraceSendExternalName( ptr );
break;
#endif
case ServerQueryCodeLocationString:
{
#ifdef TRACY_HAS_CALLSTACK
const auto name = DecodeCallstackPtrFast( ptr );
#else
const auto name = "???";
#endif
SendString( ptr, name, QueueType::CodeLocationString );
break;
}
default:
assert( false );
break;

View File

@@ -46,7 +46,8 @@ enum ServerQuery : uint8_t
ServerQueryCallstackFrame,
ServerQueryFrameName,
ServerQueryDisconnect,
ServerQueryExternalName
ServerQueryExternalName,
ServerQueryCodeLocationString
};
struct ServerQueryPacket

View File

@@ -75,6 +75,7 @@ enum class QueueType : uint8_t
FrameImageData,
ExternalName,
ExternalThreadName,
CodeLocationString,
NUM_TYPES
};
@@ -472,6 +473,7 @@ static const size_t QueueDataSize[] = {
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // frame image data
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // external name
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // external thread name
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // code location string
};
static_assert( QueueItemSize == 32, "Queue item size not 32 bytes" );

View File

@@ -247,6 +247,7 @@ Worker::Worker( const char* addr, int port )
, m_pendingSourceLocation( 0 )
, m_pendingCallstackFrames( 0 )
, m_pendingCallstackSubframes( 0 )
, m_pendingCodeLocationStrings( 0 )
, m_callstackFrameStaging( nullptr )
, m_traceVersion( CurrentVersion )
, m_loadTime( 0 )
@@ -2158,6 +2159,19 @@ std::pair<const char*, const char*> Worker::GetExternalName( uint64_t id ) const
}
}
const char* Worker::GetCodeLocationName( uint64_t ptr ) const
{
const auto it = m_data.codeLocationNames.find( ptr );
if( it == m_data.codeLocationNames.end() )
{
return "???";
}
else
{
return it->second;
}
}
const char* Worker::GetZoneName( const SourceLocation& srcloc ) const
{
if( srcloc.name.active )
@@ -2458,7 +2472,8 @@ void Worker::Exec()
{
if( m_pendingStrings != 0 || m_pendingThreads != 0 || m_pendingSourceLocation != 0 || m_pendingCallstackFrames != 0 ||
!m_pendingCustomStrings.empty() || m_data.plots.IsPending() || m_pendingCallstackPtr != 0 ||
m_pendingExternalNames != 0 || m_pendingCallstackSubframes != 0 || !m_pendingFrameImageData.empty() )
m_pendingExternalNames != 0 || m_pendingCallstackSubframes != 0 || !m_pendingFrameImageData.empty() ||
m_pendingCodeLocationStrings != 0 )
{
continue;
}
@@ -2559,6 +2574,9 @@ bool Worker::DispatchProcess( const QueueItem& ev, char*& ptr )
case QueueType::ExternalThreadName:
AddExternalThreadName( ev.stringTransfer.ptr, ptr, sz );
break;
case QueueType::CodeLocationString:
AddCodeLocationString( ev.stringTransfer.ptr, ptr, sz );
break;
default:
assert( false );
break;
@@ -2856,6 +2874,16 @@ void Worker::CheckExternalName( uint64_t id )
Query( ServerQueryExternalName, id );
}
void Worker::CheckCodeLocationString( uint64_t id )
{
if( m_data.codeLocationNames.find( id ) != m_data.codeLocationNames.end() ) return;
m_data.codeLocationNames.emplace( id, "???" );
m_pendingCodeLocationStrings++;
Query( ServerQueryCodeLocationString, id );
}
void Worker::AddSourceLocation( const QueueSourceLocation& srcloc )
{
assert( m_pendingSourceLocation > 0 );
@@ -2974,6 +3002,16 @@ void Worker::AddExternalThreadName( uint64_t ptr, char* str, size_t sz )
it->second.second = sl.ptr;
}
void Worker::AddCodeLocationString( uint64_t ptr, char* str, size_t sz )
{
assert( m_pendingCodeLocationStrings > 0 );
m_pendingCodeLocationStrings--;
auto it = m_data.codeLocationNames.find( ptr );
assert( it != m_data.codeLocationNames.end() && strcmp( it->second, "???" ) == 0 );
const auto sl = StoreString( str, sz );
it->second = sl.ptr;
}
static const uint8_t DxtcIndexTable[256] = {
85, 87, 86, 84, 93, 95, 94, 92, 89, 91, 90, 88, 81, 83, 82, 80,
117, 119, 118, 116, 125, 127, 126, 124, 121, 123, 122, 120, 113, 115, 114, 112,
@@ -4663,6 +4701,7 @@ void Worker::ProcessSysCallEnter( const QueueSysCallEnter& ev )
if( !td ) return;
if( td->sysCalls.empty() )
{
CheckCodeLocationString( ev.address );
const auto refTime = m_refTimeCtx + ev.time;
m_refTimeCtx = refTime;
const auto time = TscTime( refTime - m_data.baseTime );
@@ -4671,6 +4710,7 @@ void Worker::ProcessSysCallEnter( const QueueSysCallEnter& ev )
else
{
if( td->sysCalls.back().end < 0 ) return;
CheckCodeLocationString( ev.address );
const auto refTime = m_refTimeCtx + ev.time;
m_refTimeCtx = refTime;
const auto time = TscTime( refTime - m_data.baseTime );

View File

@@ -173,6 +173,7 @@ private:
flat_hash_map<charutil::StringKey, uint32_t, charutil::StringKey::HasherPOT, charutil::StringKey::Comparator> stringMap;
flat_hash_map<uint64_t, const char*, nohash<uint64_t>> threadNames;
flat_hash_map<uint64_t, std::pair<const char*, const char*>, nohash<uint64_t>> externalNames;
flat_hash_map<uint64_t, const char*, nohash<uint64_t>> codeLocationNames;
flat_hash_map<uint64_t, SourceLocation, nohash<uint64_t>> sourceLocation;
Vector<SourceLocation*> sourceLocationPayload;
@@ -355,6 +356,7 @@ public:
bool IsThreadLocal( uint64_t id ) const;
const SourceLocation& GetSourceLocation( int16_t srcloc ) const;
std::pair<const char*, const char*> GetExternalName( uint64_t id ) const;
const char* GetCodeLocationName( uint64_t ptr ) const;
const char* GetZoneName( const SourceLocation& srcloc ) const;
const char* GetZoneName( const ZoneEvent& ev ) const;
@@ -529,6 +531,7 @@ private:
void CheckString( uint64_t ptr );
void CheckThreadString( uint64_t id );
void CheckExternalName( uint64_t id );
void CheckCodeLocationString( uint64_t id );
void AddSourceLocation( const QueueSourceLocation& srcloc );
void AddSourceLocationPayload( uint64_t ptr, char* data, size_t sz );
@@ -538,6 +541,7 @@ private:
void AddCustomString( uint64_t ptr, char* str, size_t sz );
void AddExternalName( uint64_t ptr, char* str, size_t sz );
void AddExternalThreadName( uint64_t ptr, char* str, size_t sz );
void AddCodeLocationString( uint64_t ptr, char* str, size_t sz );
void AddFrameImageData( uint64_t ptr, char* data, size_t sz );
tracy_force_inline void AddCallstackPayload( uint64_t ptr, char* data, size_t sz );
@@ -618,6 +622,7 @@ private:
uint32_t m_pendingSourceLocation;
uint32_t m_pendingCallstackFrames;
uint8_t m_pendingCallstackSubframes;
uint32_t m_pendingCodeLocationStrings;
CallstackFrameData* m_callstackFrameStaging;
uint64_t m_callstackFrameStagingPtr;