From 81d5a8db5ec87ae736d460c42593f7f33f21b220 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 25 Jul 2020 23:13:01 +0200 Subject: [PATCH] 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. --- client/TracyProfiler.cpp | 15 +++++++++++++++ client/TracyProfiler.hpp | 2 ++ common/TracyProtocol.hpp | 2 +- common/TracyQueue.hpp | 2 ++ server/TracyWorker.cpp | 18 +++++++++++++++++- server/TracyWorker.hpp | 2 ++ 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index cc278253..74d94cce 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -2244,6 +2244,21 @@ void Profiler::SendString( uint64_t str, const char* ptr, size_t len, QueueType 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::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 ) { assert( type == QueueType::FrameImageData || diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 680c33be..511df3ab 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -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, 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: diff --git a/common/TracyProtocol.hpp b/common/TracyProtocol.hpp index cc47fe41..82794fdb 100644 --- a/common/TracyProtocol.hpp +++ b/common/TracyProtocol.hpp @@ -9,7 +9,7 @@ namespace tracy 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 }; using lz4sz_t = uint32_t; diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index aa23f0de..521ff9d6 100644 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -83,6 +83,7 @@ enum class QueueType : uint8_t ParamSetup, ParamPingback, CpuTopology, + SingleStringData, StringData, ThreadName, CustomStringData, @@ -613,6 +614,7 @@ static constexpr size_t QueueDataSize[] = { sizeof( QueueHeader ) + sizeof( QueueParamSetup ), sizeof( QueueHeader ), // param pingback sizeof( QueueHeader ) + sizeof( QueueCpuTopology ), + sizeof( QueueHeader ), // single string data // keep all QueueStringTransfer below sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // string data sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // thread name diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 5d9e5945..8cb82ee7 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -2672,7 +2672,7 @@ void Worker::Exec() !m_pendingCustomStrings.empty() || m_data.plots.IsPending() || m_pendingCallstackPtr != 0 || m_pendingExternalNames != 0 || m_pendingCallstackSubframes != 0 || m_pendingFrameImageData.image != nullptr || !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; } @@ -2941,6 +2941,16 @@ bool Worker::DispatchProcess( const QueueItem& ev, const char*& ptr ) } 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 { 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 ) ); } +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 ) { assert( m_pendingExternalNames > 0 ); diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 7390593d..9c93a984 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -738,6 +738,7 @@ private: void AddString( uint64_t ptr, 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 AddSingleString( 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 AddFrameImageData( uint64_t ptr, const char* data, size_t sz ); @@ -856,6 +857,7 @@ private: unordered_flat_set m_pendingSymbolCode; unordered_flat_set m_pendingFileStrings; unordered_flat_set m_checkedFileStrings; + StringLocation m_pendingSingleString = {}; uint32_t m_pendingStrings; uint32_t m_pendingThreads;