mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 02:31:48 +00:00
Terminate connection handshake.
This commit is contained in:
parent
d942b7edf1
commit
7c47edc64f
@ -148,10 +148,10 @@ bool Profiler::ShouldExit()
|
||||
return s_instance->m_shutdown.load( std::memory_order_relaxed );
|
||||
}
|
||||
|
||||
enum { BulkSize = TargetFrameSize / QueueItemSize };
|
||||
|
||||
void Profiler::Worker()
|
||||
{
|
||||
enum { BulkSize = TargetFrameSize / QueueItemSize };
|
||||
|
||||
const auto procname = GetProcessName();
|
||||
const auto pnsz = std::min<size_t>( strlen( procname ), WelcomeMessageProgramNameSize - 1 );
|
||||
|
||||
@ -192,25 +192,14 @@ void Profiler::Worker()
|
||||
|
||||
for(;;)
|
||||
{
|
||||
QueueItem item[BulkSize];
|
||||
const auto sz = s_queue.try_dequeue_bulk( token, item, BulkSize );
|
||||
if( sz > 0 )
|
||||
const auto status = Dequeue( token );
|
||||
if( status == ConnectionLost )
|
||||
{
|
||||
auto buf = m_buffer + m_bufferOffset;
|
||||
auto ptr = buf;
|
||||
for( size_t i=0; i<sz; i++ )
|
||||
{
|
||||
const auto dsz = QueueDataSize[item[i].hdr.idx];
|
||||
memcpy( ptr, item+i, dsz );
|
||||
ptr += dsz;
|
||||
}
|
||||
if( !SendData( buf, ptr - buf ) ) break;
|
||||
m_bufferOffset += int( ptr - buf );
|
||||
if( m_bufferOffset > TargetFrameSize * 2 ) m_bufferOffset = 0;
|
||||
break;
|
||||
}
|
||||
else
|
||||
else if( status == QueueEmpty )
|
||||
{
|
||||
if( ShouldExit() ) return;
|
||||
if( ShouldExit() ) break;
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
|
||||
}
|
||||
|
||||
@ -219,7 +208,49 @@ void Profiler::Worker()
|
||||
if( !HandleServerQuery() ) break;
|
||||
}
|
||||
}
|
||||
if( ShouldExit() ) break;
|
||||
}
|
||||
|
||||
QueueItem terminate;
|
||||
terminate.hdr.type = QueueType::Terminate;
|
||||
if( !SendData( (const char*)&terminate, 1 ) ) return;
|
||||
for(;;)
|
||||
{
|
||||
if( m_sock->HasData() )
|
||||
{
|
||||
while( m_sock->HasData() ) if( !HandleServerQuery() ) return;
|
||||
while( Dequeue( token ) == Success ) {}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
|
||||
{
|
||||
QueueItem item[BulkSize];
|
||||
const auto sz = s_queue.try_dequeue_bulk( token, item, BulkSize );
|
||||
if( sz > 0 )
|
||||
{
|
||||
auto buf = m_buffer + m_bufferOffset;
|
||||
auto ptr = buf;
|
||||
for( size_t i=0; i<sz; i++ )
|
||||
{
|
||||
const auto dsz = QueueDataSize[item[i].hdr.idx];
|
||||
memcpy( ptr, item+i, dsz );
|
||||
ptr += dsz;
|
||||
}
|
||||
if( !SendData( buf, ptr - buf ) ) return ConnectionLost;
|
||||
m_bufferOffset += int( ptr - buf );
|
||||
if( m_bufferOffset > TargetFrameSize * 2 ) m_bufferOffset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return QueueEmpty;
|
||||
}
|
||||
return Success;
|
||||
}
|
||||
|
||||
bool Profiler::SendData( const char* data, size_t len )
|
||||
@ -322,6 +353,8 @@ bool Profiler::HandleServerQuery()
|
||||
case ServerQueryMessageLiteral:
|
||||
SendString( ptr, (const char*)ptr, QueueType::MessageData );
|
||||
break;
|
||||
case ServerQueryTerminate:
|
||||
return false;
|
||||
default:
|
||||
assert( false );
|
||||
break;
|
||||
|
@ -162,9 +162,13 @@ public:
|
||||
static bool ShouldExit();
|
||||
|
||||
private:
|
||||
enum DequeueStatus { Success, ConnectionLost, QueueEmpty };
|
||||
|
||||
static void LaunchWorker( void* ptr ) { ((Profiler*)ptr)->Worker(); }
|
||||
void Worker();
|
||||
|
||||
DequeueStatus Dequeue( moodycamel::ConsumerToken& token );
|
||||
|
||||
bool SendData( const char* data, size_t len );
|
||||
bool SendString( uint64_t ptr, const char* str, QueueType type );
|
||||
void SendSourceLocation( uint64_t ptr );
|
||||
|
@ -18,6 +18,7 @@ static_assert( TargetFrameSize * 2 >= 64 * 1024, "Not enough space for LZ4 strea
|
||||
|
||||
enum ServerQuery : uint8_t
|
||||
{
|
||||
ServerQueryTerminate,
|
||||
ServerQueryString,
|
||||
ServerQueryThreadString,
|
||||
ServerQueryCustomString,
|
||||
|
@ -8,6 +8,7 @@ namespace tracy
|
||||
|
||||
enum class QueueType : uint8_t
|
||||
{
|
||||
Terminate,
|
||||
ZoneBegin,
|
||||
ZoneEnd,
|
||||
StringData,
|
||||
@ -170,6 +171,7 @@ struct QueueItem
|
||||
enum { QueueItemSize = sizeof( QueueItem ) };
|
||||
|
||||
static const size_t QueueDataSize[] = {
|
||||
sizeof( QueueHeader ), // terminate
|
||||
sizeof( QueueHeader ) + sizeof( QueueZoneBegin ),
|
||||
sizeof( QueueHeader ) + sizeof( QueueZoneEnd ),
|
||||
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // string data
|
||||
|
@ -76,6 +76,7 @@ View::View( const char* addr )
|
||||
, m_drawZones( true )
|
||||
, m_drawLocks( true )
|
||||
, m_drawPlots( true )
|
||||
, m_terminate( false )
|
||||
{
|
||||
assert( s_instance == nullptr );
|
||||
s_instance = this;
|
||||
@ -109,6 +110,7 @@ View::View( FileRead& f )
|
||||
, m_drawZones( true )
|
||||
, m_drawLocks( true )
|
||||
, m_drawPlots( true )
|
||||
, m_terminate( false )
|
||||
{
|
||||
assert( s_instance == nullptr );
|
||||
s_instance = this;
|
||||
@ -384,6 +386,27 @@ void View::Worker()
|
||||
t0 = t1;
|
||||
bytes = 0;
|
||||
}
|
||||
|
||||
if( m_terminate )
|
||||
{
|
||||
if( !m_pendingStrings.empty() || !m_pendingThreads.empty() || !m_pendingSourceLocation.empty() ||
|
||||
!m_pendingCustomStrings.empty() || !m_pendingPlots.empty() || !m_pendingMessages.empty() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
bool done = true;
|
||||
for( auto& v : m_zoneStack )
|
||||
{
|
||||
if( !v.second.empty() )
|
||||
{
|
||||
done = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( !done ) continue;
|
||||
ServerQuery( ServerQueryTerminate, 0 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
close:
|
||||
@ -519,6 +542,9 @@ void View::Process( const QueueItem& ev )
|
||||
case QueueType::MessageLiteral:
|
||||
ProcessMessage( ev.message, true );
|
||||
break;
|
||||
case QueueType::Terminate:
|
||||
m_terminate = true;
|
||||
break;
|
||||
default:
|
||||
assert( false );
|
||||
break;
|
||||
|
@ -247,6 +247,8 @@ private:
|
||||
bool m_drawZones;
|
||||
bool m_drawLocks;
|
||||
bool m_drawPlots;
|
||||
|
||||
bool m_terminate;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user