1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Allow external profiler shutdown requests.

This commit is contained in:
Bartosz Taudul 2018-08-20 01:02:27 +02:00
parent 9650162cda
commit ca939ccd19
2 changed files with 21 additions and 3 deletions

View File

@ -400,6 +400,7 @@ Profiler::Profiler()
, m_mainThread( GetThreadHandle() )
, m_epoch( std::chrono::duration_cast<std::chrono::seconds>( std::chrono::system_clock::now().time_since_epoch() ).count() )
, m_shutdown( false )
, m_shutdownFinished( false )
, m_sock( nullptr )
, m_noExit( false )
, m_stream( LZ4_createStream() )
@ -514,7 +515,11 @@ void Profiler::Worker()
for(;;)
{
#ifndef TRACY_NO_EXIT
if( !m_noExit && ShouldExit() ) return;
if( !m_noExit && ShouldExit() )
{
m_shutdownFinished.store( true, std::memory_order_relaxed );
return;
}
#endif
m_sock = listen.Accept();
if( m_sock ) break;
@ -613,7 +618,11 @@ void Profiler::Worker()
QueueItem terminate;
MemWrite( &terminate.hdr.type, QueueType::Terminate );
if( !SendData( (const char*)&terminate, 1 ) ) return;
if( !SendData( (const char*)&terminate, 1 ) )
{
m_shutdownFinished.store( true, std::memory_order_relaxed );
return;
}
for(;;)
{
if( m_sock->HasData() )
@ -623,6 +632,7 @@ void Profiler::Worker()
if( !HandleServerQuery() )
{
if( m_bufferOffset != m_bufferStart ) CommitData();
m_shutdownFinished.store( true, std::memory_order_relaxed );
return;
}
}
@ -630,7 +640,11 @@ void Profiler::Worker()
while( DequeueSerial() == Success ) {}
if( m_bufferOffset != m_bufferStart )
{
if( !CommitData() ) return;
if( !CommitData() )
{
m_shutdownFinished.store( true, std::memory_order_relaxed );
return;
}
}
}
else

View File

@ -342,6 +342,9 @@ public:
}
#endif
void RequestShutdown() { m_shutdown.store( true, std::memory_order_relaxed ); }
bool HasShutdownFinished() const { return m_shutdownFinished.load( std::memory_order_relaxed ); }
private:
enum DequeueStatus { Success, ConnectionLost, QueueEmpty };
@ -421,6 +424,7 @@ private:
uint64_t m_mainThread;
uint64_t m_epoch;
std::atomic<bool> m_shutdown;
std::atomic<bool> m_shutdownFinished;
Socket* m_sock;
bool m_noExit;