Define server query packet.

This commit is contained in:
Bartosz Taudul 2019-04-01 18:52:32 +02:00
parent 57cd6d3ed5
commit c07c6d11b7
3 changed files with 34 additions and 28 deletions

View File

@ -18,17 +18,6 @@ enum { LZ4Size = LZ4_COMPRESSBOUND( TargetFrameSize ) };
static_assert( LZ4Size <= std::numeric_limits<lz4sz_t>::max(), "LZ4Size greater than lz4sz_t" ); static_assert( LZ4Size <= std::numeric_limits<lz4sz_t>::max(), "LZ4Size greater than lz4sz_t" );
static_assert( TargetFrameSize * 2 >= 64 * 1024, "Not enough space for LZ4 stream buffer" ); 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 }; enum { HandshakeShibbolethSize = 8 };
static const char HandshakeShibboleth[HandshakeShibbolethSize] = { 'T', 'r', 'a', 'c', 'y', 'P', 'r', 'f' }; static const char HandshakeShibboleth[HandshakeShibbolethSize] = { 'T', 'r', 'a', 'c', 'y', 'P', 'r', 'f' };
@ -46,6 +35,26 @@ enum { WelcomeMessageHostInfoSize = 1024 };
#pragma pack( 1 ) #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 struct WelcomeMessage
{ {
double timerMul; double timerMul;

View File

@ -1800,7 +1800,7 @@ void Worker::Exec()
} }
if( !done ) continue; if( !done ) continue;
} }
ServerQuery( ServerQueryTerminate, 0 ); Query( ServerQueryTerminate, 0 );
break; break;
} }
} }
@ -1810,13 +1810,10 @@ close:
m_connected.store( false, std::memory_order_relaxed ); 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 ) }; ServerQueryPacket query = { type, data };
char tmp[DataSize]; m_sock.Send( &query, ServerQueryPacketSize );
memcpy( tmp, &type, sizeof( type ) );
memcpy( tmp + sizeof( type ), &data, sizeof( data ) );
m_sock.Send( tmp, DataSize );
} }
bool Worker::DispatchProcess( const QueueItem& ev, char*& ptr ) bool Worker::DispatchProcess( const QueueItem& ev, char*& ptr )
@ -1883,7 +1880,7 @@ void Worker::NewSourceLocation( uint64_t ptr )
m_pendingSourceLocation++; m_pendingSourceLocation++;
m_sourceLocationQueue.push_back( ptr ); m_sourceLocationQueue.push_back( ptr );
ServerQuery( ServerQuerySourceLocation, ptr ); Query( ServerQuerySourceLocation, ptr );
} }
uint32_t Worker::ShrinkSourceLocation( uint64_t srcloc ) uint32_t Worker::ShrinkSourceLocation( uint64_t srcloc )
@ -2067,7 +2064,7 @@ void Worker::CheckString( uint64_t ptr )
m_data.strings.emplace( ptr, "???" ); m_data.strings.emplace( ptr, "???" );
m_pendingStrings++; m_pendingStrings++;
ServerQuery( ServerQueryString, ptr ); Query( ServerQueryString, ptr );
} }
void Worker::CheckThreadString( uint64_t id ) void Worker::CheckThreadString( uint64_t id )
@ -2077,7 +2074,7 @@ void Worker::CheckThreadString( uint64_t id )
m_data.threadNames.emplace( id, "???" ); m_data.threadNames.emplace( id, "???" );
m_pendingThreads++; m_pendingThreads++;
ServerQuery( ServerQueryThreadString, id ); Query( ServerQueryThreadString, id );
} }
void Worker::AddSourceLocation( const QueueSourceLocation& srcloc ) 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() ) if( fit == m_data.callstackFrameMap.end() )
{ {
m_pendingCallstackFrames++; 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() ) if( fit == m_data.callstackFrameMap.end() )
{ {
m_pendingCallstackFrames++; m_pendingCallstackFrames++;
ServerQuery( ServerQueryCallstackFrame, GetCanonicalPointer( frame ) ); Query( ServerQueryCallstackFrame, GetCanonicalPointer( frame ) );
} }
} }
} }
@ -2738,7 +2735,7 @@ void Worker::ProcessFrameMark( const QueueFrameMark& ev )
fd->continuous = 1; fd->continuous = 1;
return fd; return fd;
}, [this] ( uint64_t name ) { }, [this] ( uint64_t name ) {
ServerQuery( ServerQueryFrameName, name ); Query( ServerQueryFrameName, name );
} ); } );
assert( fd->continuous == 1 ); assert( fd->continuous == 1 );
@ -2756,7 +2753,7 @@ void Worker::ProcessFrameMarkStart( const QueueFrameMark& ev )
fd->continuous = 0; fd->continuous = 0;
return fd; return fd;
}, [this] ( uint64_t name ) { }, [this] ( uint64_t name ) {
ServerQuery( ServerQueryFrameName, name ); Query( ServerQueryFrameName, name );
} ); } );
assert( fd->continuous == 0 ); assert( fd->continuous == 0 );
@ -2774,7 +2771,7 @@ void Worker::ProcessFrameMarkEnd( const QueueFrameMark& ev )
fd->continuous = 0; fd->continuous = 0;
return fd; return fd;
}, [this] ( uint64_t name ) { }, [this] ( uint64_t name ) {
ServerQuery( ServerQueryFrameName, name ); Query( ServerQueryFrameName, name );
} ); } );
assert( fd->continuous == 0 ); assert( fd->continuous == 0 );
@ -3006,7 +3003,7 @@ void Worker::ProcessPlotData( const QueuePlotData& ev )
plot->type = PlotType::User; plot->type = PlotType::User;
return plot; return plot;
}, [this]( uint64_t name ) { }, [this]( uint64_t name ) {
ServerQuery( ServerQueryPlotName, name ); Query( ServerQueryPlotName, name );
} ); } );
const auto time = TscTime( ev.time ); const auto time = TscTime( ev.time );

View File

@ -337,7 +337,7 @@ public:
private: private:
void Exec(); 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 DispatchProcess( const QueueItem& ev, char*& ptr );
tracy_force_inline bool Process( const QueueItem& ev ); tracy_force_inline bool Process( const QueueItem& ev );