Implement transport of single string data.

In most cases only one string is sent per message and no pointer
tracking is needed.

This is only plumbing work, no changes to messages have been made yet.
This commit is contained in:
Bartosz Taudul 2020-07-25 23:13:01 +02:00
parent 7afdef3cdb
commit 81d5a8db5e
6 changed files with 39 additions and 2 deletions

View File

@ -2244,6 +2244,21 @@ void Profiler::SendString( uint64_t str, const char* ptr, size_t len, QueueType
AppendDataUnsafe( ptr, l16 ); AppendDataUnsafe( ptr, l16 );
} }
void Profiler::SendSingleString( const char* ptr, size_t len )
{
QueueItem item;
MemWrite( &item.hdr.type, QueueType::SingleStringData );
assert( len <= std::numeric_limits<uint16_t>::max() );
auto l16 = uint16_t( len );
NeedDataSize( QueueDataSize[(int)QueueType::SingleStringData] + sizeof( l16 ) + l16 );
AppendDataUnsafe( &item, QueueDataSize[(int)QueueType::SingleStringData] );
AppendDataUnsafe( &l16, sizeof( l16 ) );
AppendDataUnsafe( ptr, l16 );
}
void Profiler::SendLongString( uint64_t str, const char* ptr, size_t len, QueueType type ) void Profiler::SendLongString( uint64_t str, const char* ptr, size_t len, QueueType type )
{ {
assert( type == QueueType::FrameImageData || assert( type == QueueType::FrameImageData ||

View File

@ -484,6 +484,8 @@ public:
void SendString( uint64_t str, const char* ptr, QueueType type ) { SendString( str, ptr, strlen( ptr ), type ); } void SendString( uint64_t str, const char* ptr, QueueType type ) { SendString( str, ptr, strlen( ptr ), type ); }
void SendString( uint64_t str, const char* ptr, size_t len, QueueType type ); void SendString( uint64_t str, const char* ptr, size_t len, QueueType type );
void SendSingleString( const char* ptr ) { SendSingleString( ptr, strlen( ptr ) ); }
void SendSingleString( const char* ptr, size_t len );
// Allocated source location data layout: // Allocated source location data layout:

View File

@ -9,7 +9,7 @@ namespace tracy
constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; } constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; }
enum : uint32_t { ProtocolVersion = 37 }; enum : uint32_t { ProtocolVersion = 38 };
enum : uint32_t { BroadcastVersion = 1 }; enum : uint32_t { BroadcastVersion = 1 };
using lz4sz_t = uint32_t; using lz4sz_t = uint32_t;

View File

@ -83,6 +83,7 @@ enum class QueueType : uint8_t
ParamSetup, ParamSetup,
ParamPingback, ParamPingback,
CpuTopology, CpuTopology,
SingleStringData,
StringData, StringData,
ThreadName, ThreadName,
CustomStringData, CustomStringData,
@ -613,6 +614,7 @@ static constexpr size_t QueueDataSize[] = {
sizeof( QueueHeader ) + sizeof( QueueParamSetup ), sizeof( QueueHeader ) + sizeof( QueueParamSetup ),
sizeof( QueueHeader ), // param pingback sizeof( QueueHeader ), // param pingback
sizeof( QueueHeader ) + sizeof( QueueCpuTopology ), sizeof( QueueHeader ) + sizeof( QueueCpuTopology ),
sizeof( QueueHeader ), // single string data
// keep all QueueStringTransfer below // keep all QueueStringTransfer below
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // string data sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // string data
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // thread name sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // thread name

View File

@ -2672,7 +2672,7 @@ void Worker::Exec()
!m_pendingCustomStrings.empty() || m_data.plots.IsPending() || m_pendingCallstackPtr != 0 || !m_pendingCustomStrings.empty() || m_data.plots.IsPending() || m_pendingCallstackPtr != 0 ||
m_pendingExternalNames != 0 || m_pendingCallstackSubframes != 0 || m_pendingFrameImageData.image != nullptr || m_pendingExternalNames != 0 || m_pendingCallstackSubframes != 0 || m_pendingFrameImageData.image != nullptr ||
!m_pendingSymbols.empty() || !m_pendingSymbolCode.empty() || m_pendingCodeInformation != 0 || !m_pendingSymbols.empty() || !m_pendingSymbolCode.empty() || m_pendingCodeInformation != 0 ||
!m_serverQueryQueue.empty() || m_pendingSourceLocationPayload != 0 ) !m_serverQueryQueue.empty() || m_pendingSourceLocationPayload != 0 || m_pendingSingleString.ptr != nullptr )
{ {
continue; continue;
} }
@ -2941,6 +2941,16 @@ bool Worker::DispatchProcess( const QueueItem& ev, const char*& ptr )
} }
return true; return true;
} }
else if( ev.hdr.type == QueueType::SingleStringData )
{
ptr += sizeof( QueueHeader );
uint16_t sz;
memcpy( &sz, ptr, sizeof( sz ) );
ptr += sizeof( sz );
AddSingleString( ptr, sz );
ptr += sz;
return true;
}
else else
{ {
ptr += QueueDataSize[ev.hdr.idx]; ptr += QueueDataSize[ev.hdr.idx];
@ -3350,6 +3360,12 @@ void Worker::AddCustomString( uint64_t ptr, const char* str, size_t sz )
m_pendingCustomStrings.emplace( ptr, StoreString( str, sz ) ); m_pendingCustomStrings.emplace( ptr, StoreString( str, sz ) );
} }
void Worker::AddSingleString( const char* str, size_t sz )
{
assert( m_pendingSingleString.ptr == nullptr );
m_pendingSingleString = StoreString( str, sz );
}
void Worker::AddExternalName( uint64_t ptr, const char* str, size_t sz ) void Worker::AddExternalName( uint64_t ptr, const char* str, size_t sz )
{ {
assert( m_pendingExternalNames > 0 ); assert( m_pendingExternalNames > 0 );

View File

@ -738,6 +738,7 @@ private:
void AddString( uint64_t ptr, const char* str, size_t sz ); void AddString( uint64_t ptr, const char* str, size_t sz );
void AddThreadString( uint64_t id, const char* str, size_t sz ); void AddThreadString( uint64_t id, const char* str, size_t sz );
void AddCustomString( uint64_t ptr, const char* str, size_t sz ); void AddCustomString( uint64_t ptr, const char* str, size_t sz );
void AddSingleString( const char* str, size_t sz );
void AddExternalName( uint64_t ptr, const char* str, size_t sz ); void AddExternalName( uint64_t ptr, const char* str, size_t sz );
void AddExternalThreadName( uint64_t ptr, const char* str, size_t sz ); void AddExternalThreadName( uint64_t ptr, const char* str, size_t sz );
void AddFrameImageData( uint64_t ptr, const char* data, size_t sz ); void AddFrameImageData( uint64_t ptr, const char* data, size_t sz );
@ -856,6 +857,7 @@ private:
unordered_flat_set<uint64_t> m_pendingSymbolCode; unordered_flat_set<uint64_t> m_pendingSymbolCode;
unordered_flat_set<StringRef, StringRefHasher, StringRefComparator> m_pendingFileStrings; unordered_flat_set<StringRef, StringRefHasher, StringRefComparator> m_pendingFileStrings;
unordered_flat_set<StringRef, StringRefHasher, StringRefComparator> m_checkedFileStrings; unordered_flat_set<StringRef, StringRefHasher, StringRefComparator> m_checkedFileStrings;
StringLocation m_pendingSingleString = {};
uint32_t m_pendingStrings; uint32_t m_pendingStrings;
uint32_t m_pendingThreads; uint32_t m_pendingThreads;