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( 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;

View File

@ -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 );

View File

@ -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 );