mirror of
https://github.com/wolfpld/tracy
synced 2025-05-01 05:03:53 +00:00
Add connection id for on-demand mode.
Long-lived zones could send their end events without begin events in a following scenario: 1. On-demand connection is made. 2. Zone begin is emitted, m_active is set to true. 3. Connection is terminated. 4. A new connection is made. 5. Zone end is emitted, because m_active is true. To this point it was assumed that all zone end events will happen before a new connection is made, but it's not necessarily true.
This commit is contained in:
parent
0db9c73d76
commit
80dff1ede1
@ -964,6 +964,7 @@ Profiler::Profiler()
|
|||||||
#ifdef TRACY_ON_DEMAND
|
#ifdef TRACY_ON_DEMAND
|
||||||
, m_isConnected( false )
|
, m_isConnected( false )
|
||||||
, m_frameCount( 0 )
|
, m_frameCount( 0 )
|
||||||
|
, m_connectionId( 0 )
|
||||||
, m_deferredQueue( 64*1024 )
|
, m_deferredQueue( 64*1024 )
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
@ -1162,6 +1163,7 @@ void Profiler::Worker()
|
|||||||
|
|
||||||
#ifdef TRACY_ON_DEMAND
|
#ifdef TRACY_ON_DEMAND
|
||||||
ClearQueues( token );
|
ClearQueues( token );
|
||||||
|
m_connectionId.fetch_add( 1, std::memory_order_release );
|
||||||
m_isConnected.store( true, std::memory_order_release );
|
m_isConnected.store( true, std::memory_order_release );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -405,11 +405,16 @@ public:
|
|||||||
static bool ShouldExit();
|
static bool ShouldExit();
|
||||||
|
|
||||||
#ifdef TRACY_ON_DEMAND
|
#ifdef TRACY_ON_DEMAND
|
||||||
tracy_force_inline bool IsConnected()
|
tracy_force_inline bool IsConnected() const
|
||||||
{
|
{
|
||||||
return m_isConnected.load( std::memory_order_acquire );
|
return m_isConnected.load( std::memory_order_acquire );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tracy_force_inline uint64_t ConnectionId() const
|
||||||
|
{
|
||||||
|
return m_connectionId.load( std::memory_order_acquire );
|
||||||
|
}
|
||||||
|
|
||||||
tracy_force_inline void DeferItem( const QueueItem& item )
|
tracy_force_inline void DeferItem( const QueueItem& item )
|
||||||
{
|
{
|
||||||
m_deferredLock.lock();
|
m_deferredLock.lock();
|
||||||
@ -529,6 +534,7 @@ private:
|
|||||||
#ifdef TRACY_ON_DEMAND
|
#ifdef TRACY_ON_DEMAND
|
||||||
std::atomic<bool> m_isConnected;
|
std::atomic<bool> m_isConnected;
|
||||||
std::atomic<uint64_t> m_frameCount;
|
std::atomic<uint64_t> m_frameCount;
|
||||||
|
std::atomic<uint64_t> m_connectionId;
|
||||||
|
|
||||||
TracyMutex m_deferredLock;
|
TracyMutex m_deferredLock;
|
||||||
FastVector<QueueItem> m_deferredQueue;
|
FastVector<QueueItem> m_deferredQueue;
|
||||||
|
@ -18,6 +18,7 @@ public:
|
|||||||
tracy_force_inline ScopedZone( const SourceLocationData* srcloc, bool is_active = true )
|
tracy_force_inline ScopedZone( const SourceLocationData* srcloc, bool is_active = true )
|
||||||
#ifdef TRACY_ON_DEMAND
|
#ifdef TRACY_ON_DEMAND
|
||||||
: m_active( is_active && GetProfiler().IsConnected() )
|
: m_active( is_active && GetProfiler().IsConnected() )
|
||||||
|
, m_connectionId( GetProfiler().ConnectionId() )
|
||||||
#else
|
#else
|
||||||
: m_active( is_active )
|
: m_active( is_active )
|
||||||
#endif
|
#endif
|
||||||
@ -45,6 +46,7 @@ public:
|
|||||||
tracy_force_inline ScopedZone( const SourceLocationData* srcloc, int depth, bool is_active = true )
|
tracy_force_inline ScopedZone( const SourceLocationData* srcloc, int depth, bool is_active = true )
|
||||||
#ifdef TRACY_ON_DEMAND
|
#ifdef TRACY_ON_DEMAND
|
||||||
: m_active( is_active && GetProfiler().IsConnected() )
|
: m_active( is_active && GetProfiler().IsConnected() )
|
||||||
|
, m_connectionId( GetProfiler().ConnectionId() )
|
||||||
#else
|
#else
|
||||||
: m_active( is_active )
|
: m_active( is_active )
|
||||||
#endif
|
#endif
|
||||||
@ -74,6 +76,9 @@ public:
|
|||||||
tracy_force_inline ~ScopedZone()
|
tracy_force_inline ~ScopedZone()
|
||||||
{
|
{
|
||||||
if( !m_active ) return;
|
if( !m_active ) return;
|
||||||
|
#ifdef TRACY_ON_DEMAND
|
||||||
|
if( GetProfiler().ConnectionId() != m_connectionId ) return;
|
||||||
|
#endif
|
||||||
Magic magic;
|
Magic magic;
|
||||||
auto token = GetToken();
|
auto token = GetToken();
|
||||||
auto& tail = token->get_tail_index();
|
auto& tail = token->get_tail_index();
|
||||||
@ -93,6 +98,9 @@ public:
|
|||||||
tracy_force_inline void Text( const char* txt, size_t size )
|
tracy_force_inline void Text( const char* txt, size_t size )
|
||||||
{
|
{
|
||||||
if( !m_active ) return;
|
if( !m_active ) return;
|
||||||
|
#ifdef TRACY_ON_DEMAND
|
||||||
|
if( GetProfiler().ConnectionId() != m_connectionId ) return;
|
||||||
|
#endif
|
||||||
Magic magic;
|
Magic magic;
|
||||||
auto token = GetToken();
|
auto token = GetToken();
|
||||||
auto ptr = (char*)tracy_malloc( size+1 );
|
auto ptr = (char*)tracy_malloc( size+1 );
|
||||||
@ -109,6 +117,9 @@ public:
|
|||||||
tracy_force_inline void Name( const char* txt, size_t size )
|
tracy_force_inline void Name( const char* txt, size_t size )
|
||||||
{
|
{
|
||||||
if( !m_active ) return;
|
if( !m_active ) return;
|
||||||
|
#ifdef TRACY_ON_DEMAND
|
||||||
|
if( GetProfiler().ConnectionId() != m_connectionId ) return;
|
||||||
|
#endif
|
||||||
Magic magic;
|
Magic magic;
|
||||||
auto token = GetToken();
|
auto token = GetToken();
|
||||||
auto ptr = (char*)tracy_malloc( size+1 );
|
auto ptr = (char*)tracy_malloc( size+1 );
|
||||||
@ -125,6 +136,10 @@ public:
|
|||||||
private:
|
private:
|
||||||
uint64_t m_thread;
|
uint64_t m_thread;
|
||||||
const bool m_active;
|
const bool m_active;
|
||||||
|
|
||||||
|
#ifdef TRACY_ON_DEMAND
|
||||||
|
uint64_t m_connectionId;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user