From c07c6d11b7d99033b812b41ec93b7971869d07ed Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 1 Apr 2019 18:52:32 +0200 Subject: [PATCH] Define server query packet. --- common/TracyProtocol.hpp | 31 ++++++++++++++++++++----------- server/TracyWorker.cpp | 29 +++++++++++++---------------- server/TracyWorker.hpp | 2 +- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/common/TracyProtocol.hpp b/common/TracyProtocol.hpp index 2a437d27..8ee317b6 100644 --- a/common/TracyProtocol.hpp +++ b/common/TracyProtocol.hpp @@ -18,17 +18,6 @@ enum { LZ4Size = LZ4_COMPRESSBOUND( TargetFrameSize ) }; static_assert( LZ4Size <= std::numeric_limits::max(), "LZ4Size greater than lz4sz_t" ); static_assert( TargetFrameSize * 2 >= 64 * 1024, "Not enough space for LZ4 stream buffer" ); -enum ServerQuery : uint8_t -{ - ServerQueryTerminate, - ServerQueryString, - ServerQueryThreadString, - ServerQuerySourceLocation, - ServerQueryPlotName, - ServerQueryCallstackFrame, - ServerQueryFrameName, -}; - enum { HandshakeShibbolethSize = 8 }; static const char HandshakeShibboleth[HandshakeShibbolethSize] = { 'T', 'r', 'a', 'c', 'y', 'P', 'r', 'f' }; @@ -46,6 +35,26 @@ enum { WelcomeMessageHostInfoSize = 1024 }; #pragma pack( 1 ) +enum ServerQuery : uint8_t +{ + ServerQueryTerminate, + ServerQueryString, + ServerQueryThreadString, + ServerQuerySourceLocation, + ServerQueryPlotName, + ServerQueryCallstackFrame, + ServerQueryFrameName, +}; + +struct ServerQueryPacket +{ + ServerQuery type; + uint64_t ptr; +}; + +enum { ServerQueryPacketSize = sizeof( ServerQueryPacket ) }; + + struct WelcomeMessage { double timerMul; diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 109ee6c7..e03a7046 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -1800,7 +1800,7 @@ void Worker::Exec() } if( !done ) continue; } - ServerQuery( ServerQueryTerminate, 0 ); + Query( ServerQueryTerminate, 0 ); break; } } @@ -1810,13 +1810,10 @@ close: m_connected.store( false, std::memory_order_relaxed ); } -void Worker::ServerQuery( uint8_t type, uint64_t data ) +void Worker::Query( ServerQuery type, uint64_t data ) { - enum { DataSize = sizeof( type ) + sizeof( data ) }; - char tmp[DataSize]; - memcpy( tmp, &type, sizeof( type ) ); - memcpy( tmp + sizeof( type ), &data, sizeof( data ) ); - m_sock.Send( tmp, DataSize ); + ServerQueryPacket query = { type, data }; + m_sock.Send( &query, ServerQueryPacketSize ); } bool Worker::DispatchProcess( const QueueItem& ev, char*& ptr ) @@ -1883,7 +1880,7 @@ void Worker::NewSourceLocation( uint64_t ptr ) m_pendingSourceLocation++; m_sourceLocationQueue.push_back( ptr ); - ServerQuery( ServerQuerySourceLocation, ptr ); + Query( ServerQuerySourceLocation, ptr ); } uint32_t Worker::ShrinkSourceLocation( uint64_t srcloc ) @@ -2067,7 +2064,7 @@ void Worker::CheckString( uint64_t ptr ) m_data.strings.emplace( ptr, "???" ); m_pendingStrings++; - ServerQuery( ServerQueryString, ptr ); + Query( ServerQueryString, ptr ); } void Worker::CheckThreadString( uint64_t id ) @@ -2077,7 +2074,7 @@ void Worker::CheckThreadString( uint64_t id ) m_data.threadNames.emplace( id, "???" ); m_pendingThreads++; - ServerQuery( ServerQueryThreadString, id ); + Query( ServerQueryThreadString, id ); } void Worker::AddSourceLocation( const QueueSourceLocation& srcloc ) @@ -2211,7 +2208,7 @@ void Worker::AddCallstackPayload( uint64_t ptr, char* _data, size_t _sz ) if( fit == m_data.callstackFrameMap.end() ) { m_pendingCallstackFrames++; - ServerQuery( ServerQueryCallstackFrame, GetCanonicalPointer( frame ) ); + Query( ServerQueryCallstackFrame, GetCanonicalPointer( frame ) ); } } } @@ -2290,7 +2287,7 @@ void Worker::AddCallstackAllocPayload( uint64_t ptr, char* data, size_t _sz ) if( fit == m_data.callstackFrameMap.end() ) { m_pendingCallstackFrames++; - ServerQuery( ServerQueryCallstackFrame, GetCanonicalPointer( frame ) ); + Query( ServerQueryCallstackFrame, GetCanonicalPointer( frame ) ); } } } @@ -2738,7 +2735,7 @@ void Worker::ProcessFrameMark( const QueueFrameMark& ev ) fd->continuous = 1; return fd; }, [this] ( uint64_t name ) { - ServerQuery( ServerQueryFrameName, name ); + Query( ServerQueryFrameName, name ); } ); assert( fd->continuous == 1 ); @@ -2756,7 +2753,7 @@ void Worker::ProcessFrameMarkStart( const QueueFrameMark& ev ) fd->continuous = 0; return fd; }, [this] ( uint64_t name ) { - ServerQuery( ServerQueryFrameName, name ); + Query( ServerQueryFrameName, name ); } ); assert( fd->continuous == 0 ); @@ -2774,7 +2771,7 @@ void Worker::ProcessFrameMarkEnd( const QueueFrameMark& ev ) fd->continuous = 0; return fd; }, [this] ( uint64_t name ) { - ServerQuery( ServerQueryFrameName, name ); + Query( ServerQueryFrameName, name ); } ); assert( fd->continuous == 0 ); @@ -3006,7 +3003,7 @@ void Worker::ProcessPlotData( const QueuePlotData& ev ) plot->type = PlotType::User; return plot; }, [this]( uint64_t name ) { - ServerQuery( ServerQueryPlotName, name ); + Query( ServerQueryPlotName, name ); } ); const auto time = TscTime( ev.time ); diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 748a3da5..28619c37 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -337,7 +337,7 @@ public: private: void Exec(); - void ServerQuery( uint8_t type, uint64_t data ); + void Query( ServerQuery type, uint64_t data ); tracy_force_inline bool DispatchProcess( const QueueItem& ev, char*& ptr ); tracy_force_inline bool Process( const QueueItem& ev );