diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index a8fdd449..af340c07 100644 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -166,6 +166,7 @@ struct ZoneEvent tracy_force_inline void SetSrcLoc( int16_t srcloc ) { memcpy( &_start_srcloc, &srcloc, 2 ); } tracy_force_inline int32_t Child() const { return int32_t( uint32_t( _end_child1 & 0xFFFF ) | ( uint32_t( _child2 ) << 16 ) ); } tracy_force_inline void SetChild( int32_t child ) { memcpy( &_end_child1, &child, 2 ); _child2 = uint32_t( child ) >> 16; } + tracy_force_inline bool HasChildren() const { return ( _child2 >> 15 ) == 0; } uint64_t _start_srcloc; uint64_t _end_child1; diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 53a78d69..3b17d22b 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -5583,7 +5583,7 @@ void DrawZoneTrace( T zone, const std::vector& trace, const Worker& worker, B void View::CalcZoneTimeData( flat_hash_map>& data, flat_hash_map>::iterator zit, const ZoneEvent& zone ) { - assert( zone.Child() >= 0 ); + assert( zone.HasChildren() ); const auto& children = m_worker.GetZoneChildren( zone.Child() ); if( children.is_magic() ) { @@ -5627,7 +5627,7 @@ void View::CalcZoneTimeDataImpl( const V& children, flat_hash_map>& data, flat_hash_map>::iterator zit, const ZoneEvent& zone ) { - assert( zone.Child() >= 0 ); + assert( zone.HasChildren() ); const auto& children = m_worker.GetZoneChildren( zone.Child() ); if( children.is_magic() ) { @@ -6303,7 +6303,7 @@ void View::DrawZoneInfoWindow() } } ); - if( ev.Child() >= 0 ) + if( ev.HasChildren() ) { const auto& children = m_worker.GetZoneChildren( ev.Child() ); bool expand = ImGui::TreeNode( "Child zones" ); @@ -14069,7 +14069,7 @@ const ZoneEvent* View::GetZoneParent( const ZoneEvent& zone ) const if( it != vec->begin() ) --it; if( zone.IsEndValid() && it->Start() > zone.End() ) break; if( it == &zone ) return parent; - if( it->Child() < 0 ) break; + if( !it->HasChildren() ) break; parent = it; timeline = &m_worker.GetZoneChildren( parent->Child() ); } @@ -14079,7 +14079,7 @@ const ZoneEvent* View::GetZoneParent( const ZoneEvent& zone ) const if( it != timeline->begin() ) --it; if( zone.IsEndValid() && (*it)->Start() > zone.End() ) break; if( *it == &zone ) return parent; - if( (*it)->Child() < 0 ) break; + if( !(*it)->HasChildren() ) break; parent = *it; timeline = &m_worker.GetZoneChildren( parent->Child() ); } @@ -14103,7 +14103,7 @@ const ZoneEvent* View::GetZoneParent( const ZoneEvent& zone, uint64_t tid ) cons if( it != vec->begin() ) --it; if( zone.IsEndValid() && it->Start() > zone.End() ) break; if( it == &zone ) return parent; - if( it->Child() < 0 ) break; + if( !it->HasChildren() ) break; parent = it; timeline = &m_worker.GetZoneChildren( parent->Child() ); } @@ -14113,7 +14113,7 @@ const ZoneEvent* View::GetZoneParent( const ZoneEvent& zone, uint64_t tid ) cons if( it != timeline->begin() ) --it; if( zone.IsEndValid() && (*it)->Start() > zone.End() ) break; if( *it == &zone ) return parent; - if( (*it)->Child() < 0 ) break; + if( !(*it)->HasChildren() ) break; parent = *it; timeline = &m_worker.GetZoneChildren( parent->Child() ); } @@ -14174,7 +14174,7 @@ const ThreadData* View::GetZoneThreadData( const ZoneEvent& zone ) const if( it != vec->begin() ) --it; if( zone.IsEndValid() && it->Start() > zone.End() ) break; if( it == &zone ) return thread; - if( it->Child() < 0 ) break; + if( !it->HasChildren() ) break; timeline = &m_worker.GetZoneChildren( it->Child() ); } else @@ -14183,7 +14183,7 @@ const ThreadData* View::GetZoneThreadData( const ZoneEvent& zone ) const if( it != timeline->begin() ) --it; if( zone.IsEndValid() && (*it)->Start() > zone.End() ) break; if( *it == &zone ) return thread; - if( (*it)->Child() < 0 ) break; + if( !(*it)->HasChildren() ) break; timeline = &m_worker.GetZoneChildren( (*it)->Child() ); } } @@ -14298,7 +14298,7 @@ const ZoneEvent* View::FindZoneAtTime( uint64_t thread, int64_t time ) const if( it != vec->begin() ) --it; if( it->Start() > time || ( it->IsEndValid() && it->End() < time ) ) return ret; ret = it; - if( it->Child() < 0 ) return ret; + if( !it->HasChildren() ) return ret; timeline = &m_worker.GetZoneChildren( it->Child() ); } else @@ -14307,7 +14307,7 @@ const ZoneEvent* View::FindZoneAtTime( uint64_t thread, int64_t time ) const if( it != timeline->begin() ) --it; if( (*it)->Start() > time || ( (*it)->IsEndValid() && (*it)->End() < time ) ) return ret; ret = *it; - if( (*it)->Child() < 0 ) return ret; + if( !(*it)->HasChildren() ) return ret; timeline = &m_worker.GetZoneChildren( (*it)->Child() ); } } @@ -14445,7 +14445,7 @@ void View::SetViewToLastFrames() int64_t View::GetZoneChildTime( const ZoneEvent& zone ) { int64_t time = 0; - if( zone.Child() >= 0 ) + if( zone.HasChildren() ) { auto& children = m_worker.GetZoneChildren( zone.Child() ); if( children.is_magic() ) @@ -14499,7 +14499,7 @@ int64_t View::GetZoneChildTime( const GpuEvent& zone ) int64_t View::GetZoneChildTimeFast( const ZoneEvent& zone ) { int64_t time = 0; - if( zone.Child() >= 0 ) + if( zone.HasChildren() ) { auto& children = m_worker.GetZoneChildren( zone.Child() ); if( children.is_magic() ) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 0d60a0b8..376cd0f0 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -1575,7 +1575,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks ) for( auto& zone : vec ) { if( zone.IsEndValid() ) ReconstructZoneStatistics( zone, thread ); - if( zone.Child() >= 0 ) ProcessTimeline( GetZoneChildrenMutable( zone.Child() ), thread ); + if( zone.HasChildren() ) ProcessTimeline( GetZoneChildrenMutable( zone.Child() ), thread ); } }; @@ -1899,7 +1899,7 @@ int64_t Worker::GetZoneEnd( const ZoneEvent& ev ) for(;;) { if( ptr->IsEndValid() ) return ptr->End(); - if( ptr->Child() < 0 ) return ptr->Start(); + if( !ptr->HasChildren() ) return ptr->Start(); auto& children = GetZoneChildren( ptr->Child() ); if( children.is_magic() ) { @@ -2682,8 +2682,7 @@ void Worker::NewZone( ZoneEvent* zone, uint64_t thread ) else { auto& back = td->stack.back(); - const auto backChild = back->Child(); - if( backChild < 0 ) + if( !back->HasChildren() ) { back->SetChild( int32_t( m_data.zoneChildren.size() ) ); if( m_data.zoneVectorCache.empty() ) @@ -2701,6 +2700,7 @@ void Worker::NewZone( ZoneEvent* zone, uint64_t thread ) } else { + const auto backChild = back->Child(); assert( !m_data.zoneChildren[backChild].empty() ); m_data.zoneChildren[backChild].push_back_non_empty( zone ); } @@ -3501,10 +3501,9 @@ void Worker::ProcessZoneEnd( const QueueZoneEnd& ev ) if( m_data.lastTime < timeEnd ) m_data.lastTime = timeEnd; - const auto child = zone->Child(); - if( child >= 0 ) + if( zone->HasChildren() ) { - auto& childVec = m_data.zoneChildren[child]; + auto& childVec = m_data.zoneChildren[zone->Child()]; const auto sz = childVec.size(); if( sz <= 8 * 1024 ) { @@ -5065,7 +5064,7 @@ void Worker::ReconstructZoneStatistics( ZoneEvent& zone, uint16_t thread ) if( slz.max < timeSpan ) slz.max = timeSpan; slz.total += timeSpan; slz.sumSq += double( timeSpan ) * timeSpan; - if( zone.Child() >= 0 ) + if( zone.HasChildren() ) { auto& children = GetZoneChildren( zone.Child() ); assert( children.is_magic() );