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:
parent
9650162cda
commit
ca939ccd19
@ -400,6 +400,7 @@ Profiler::Profiler()
|
|||||||
, m_mainThread( GetThreadHandle() )
|
, m_mainThread( GetThreadHandle() )
|
||||||
, m_epoch( std::chrono::duration_cast<std::chrono::seconds>( std::chrono::system_clock::now().time_since_epoch() ).count() )
|
, m_epoch( std::chrono::duration_cast<std::chrono::seconds>( std::chrono::system_clock::now().time_since_epoch() ).count() )
|
||||||
, m_shutdown( false )
|
, m_shutdown( false )
|
||||||
|
, m_shutdownFinished( false )
|
||||||
, m_sock( nullptr )
|
, m_sock( nullptr )
|
||||||
, m_noExit( false )
|
, m_noExit( false )
|
||||||
, m_stream( LZ4_createStream() )
|
, m_stream( LZ4_createStream() )
|
||||||
@ -514,7 +515,11 @@ void Profiler::Worker()
|
|||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
#ifndef TRACY_NO_EXIT
|
#ifndef TRACY_NO_EXIT
|
||||||
if( !m_noExit && ShouldExit() ) return;
|
if( !m_noExit && ShouldExit() )
|
||||||
|
{
|
||||||
|
m_shutdownFinished.store( true, std::memory_order_relaxed );
|
||||||
|
return;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
m_sock = listen.Accept();
|
m_sock = listen.Accept();
|
||||||
if( m_sock ) break;
|
if( m_sock ) break;
|
||||||
@ -613,7 +618,11 @@ void Profiler::Worker()
|
|||||||
|
|
||||||
QueueItem terminate;
|
QueueItem terminate;
|
||||||
MemWrite( &terminate.hdr.type, QueueType::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(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
if( m_sock->HasData() )
|
if( m_sock->HasData() )
|
||||||
@ -623,6 +632,7 @@ void Profiler::Worker()
|
|||||||
if( !HandleServerQuery() )
|
if( !HandleServerQuery() )
|
||||||
{
|
{
|
||||||
if( m_bufferOffset != m_bufferStart ) CommitData();
|
if( m_bufferOffset != m_bufferStart ) CommitData();
|
||||||
|
m_shutdownFinished.store( true, std::memory_order_relaxed );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -630,7 +640,11 @@ void Profiler::Worker()
|
|||||||
while( DequeueSerial() == Success ) {}
|
while( DequeueSerial() == Success ) {}
|
||||||
if( m_bufferOffset != m_bufferStart )
|
if( m_bufferOffset != m_bufferStart )
|
||||||
{
|
{
|
||||||
if( !CommitData() ) return;
|
if( !CommitData() )
|
||||||
|
{
|
||||||
|
m_shutdownFinished.store( true, std::memory_order_relaxed );
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@ -342,6 +342,9 @@ public:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void RequestShutdown() { m_shutdown.store( true, std::memory_order_relaxed ); }
|
||||||
|
bool HasShutdownFinished() const { return m_shutdownFinished.load( std::memory_order_relaxed ); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum DequeueStatus { Success, ConnectionLost, QueueEmpty };
|
enum DequeueStatus { Success, ConnectionLost, QueueEmpty };
|
||||||
|
|
||||||
@ -421,6 +424,7 @@ private:
|
|||||||
uint64_t m_mainThread;
|
uint64_t m_mainThread;
|
||||||
uint64_t m_epoch;
|
uint64_t m_epoch;
|
||||||
std::atomic<bool> m_shutdown;
|
std::atomic<bool> m_shutdown;
|
||||||
|
std::atomic<bool> m_shutdownFinished;
|
||||||
Socket* m_sock;
|
Socket* m_sock;
|
||||||
bool m_noExit;
|
bool m_noExit;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user