Add dedicated function to check if zone has children.

This commit is contained in:
Bartosz Taudul 2020-01-24 02:17:38 +01:00
parent ad3f37aec6
commit c43bd2bfe2
3 changed files with 21 additions and 21 deletions

View File

@ -166,6 +166,7 @@ struct ZoneEvent
tracy_force_inline void SetSrcLoc( int16_t srcloc ) { memcpy( &_start_srcloc, &srcloc, 2 ); } 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 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 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 _start_srcloc;
uint64_t _end_child1; uint64_t _end_child1;

View File

@ -5583,7 +5583,7 @@ void DrawZoneTrace( T zone, const std::vector<T>& trace, const Worker& worker, B
void View::CalcZoneTimeData( flat_hash_map<int16_t, ZoneTimeData, nohash<uint16_t>>& data, flat_hash_map<int16_t, ZoneTimeData, nohash<uint16_t>>::iterator zit, const ZoneEvent& zone ) void View::CalcZoneTimeData( flat_hash_map<int16_t, ZoneTimeData, nohash<uint16_t>>& data, flat_hash_map<int16_t, ZoneTimeData, nohash<uint16_t>>::iterator zit, const ZoneEvent& zone )
{ {
assert( zone.Child() >= 0 ); assert( zone.HasChildren() );
const auto& children = m_worker.GetZoneChildren( zone.Child() ); const auto& children = m_worker.GetZoneChildren( zone.Child() );
if( children.is_magic() ) if( children.is_magic() )
{ {
@ -5627,7 +5627,7 @@ void View::CalcZoneTimeDataImpl( const V& children, flat_hash_map<int16_t, ZoneT
void View::CalcZoneTimeData( const ContextSwitch* ctx, flat_hash_map<int16_t, ZoneTimeData, nohash<uint16_t>>& data, flat_hash_map<int16_t, ZoneTimeData, nohash<uint16_t>>::iterator zit, const ZoneEvent& zone ) void View::CalcZoneTimeData( const ContextSwitch* ctx, flat_hash_map<int16_t, ZoneTimeData, nohash<uint16_t>>& data, flat_hash_map<int16_t, ZoneTimeData, nohash<uint16_t>>::iterator zit, const ZoneEvent& zone )
{ {
assert( zone.Child() >= 0 ); assert( zone.HasChildren() );
const auto& children = m_worker.GetZoneChildren( zone.Child() ); const auto& children = m_worker.GetZoneChildren( zone.Child() );
if( children.is_magic() ) 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() ); const auto& children = m_worker.GetZoneChildren( ev.Child() );
bool expand = ImGui::TreeNode( "Child zones" ); bool expand = ImGui::TreeNode( "Child zones" );
@ -14069,7 +14069,7 @@ const ZoneEvent* View::GetZoneParent( const ZoneEvent& zone ) const
if( it != vec->begin() ) --it; if( it != vec->begin() ) --it;
if( zone.IsEndValid() && it->Start() > zone.End() ) break; if( zone.IsEndValid() && it->Start() > zone.End() ) break;
if( it == &zone ) return parent; if( it == &zone ) return parent;
if( it->Child() < 0 ) break; if( !it->HasChildren() ) break;
parent = it; parent = it;
timeline = &m_worker.GetZoneChildren( parent->Child() ); timeline = &m_worker.GetZoneChildren( parent->Child() );
} }
@ -14079,7 +14079,7 @@ const ZoneEvent* View::GetZoneParent( const ZoneEvent& zone ) const
if( it != timeline->begin() ) --it; if( it != timeline->begin() ) --it;
if( zone.IsEndValid() && (*it)->Start() > zone.End() ) break; if( zone.IsEndValid() && (*it)->Start() > zone.End() ) break;
if( *it == &zone ) return parent; if( *it == &zone ) return parent;
if( (*it)->Child() < 0 ) break; if( !(*it)->HasChildren() ) break;
parent = *it; parent = *it;
timeline = &m_worker.GetZoneChildren( parent->Child() ); 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( it != vec->begin() ) --it;
if( zone.IsEndValid() && it->Start() > zone.End() ) break; if( zone.IsEndValid() && it->Start() > zone.End() ) break;
if( it == &zone ) return parent; if( it == &zone ) return parent;
if( it->Child() < 0 ) break; if( !it->HasChildren() ) break;
parent = it; parent = it;
timeline = &m_worker.GetZoneChildren( parent->Child() ); 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( it != timeline->begin() ) --it;
if( zone.IsEndValid() && (*it)->Start() > zone.End() ) break; if( zone.IsEndValid() && (*it)->Start() > zone.End() ) break;
if( *it == &zone ) return parent; if( *it == &zone ) return parent;
if( (*it)->Child() < 0 ) break; if( !(*it)->HasChildren() ) break;
parent = *it; parent = *it;
timeline = &m_worker.GetZoneChildren( parent->Child() ); timeline = &m_worker.GetZoneChildren( parent->Child() );
} }
@ -14174,7 +14174,7 @@ const ThreadData* View::GetZoneThreadData( const ZoneEvent& zone ) const
if( it != vec->begin() ) --it; if( it != vec->begin() ) --it;
if( zone.IsEndValid() && it->Start() > zone.End() ) break; if( zone.IsEndValid() && it->Start() > zone.End() ) break;
if( it == &zone ) return thread; if( it == &zone ) return thread;
if( it->Child() < 0 ) break; if( !it->HasChildren() ) break;
timeline = &m_worker.GetZoneChildren( it->Child() ); timeline = &m_worker.GetZoneChildren( it->Child() );
} }
else else
@ -14183,7 +14183,7 @@ const ThreadData* View::GetZoneThreadData( const ZoneEvent& zone ) const
if( it != timeline->begin() ) --it; if( it != timeline->begin() ) --it;
if( zone.IsEndValid() && (*it)->Start() > zone.End() ) break; if( zone.IsEndValid() && (*it)->Start() > zone.End() ) break;
if( *it == &zone ) return thread; if( *it == &zone ) return thread;
if( (*it)->Child() < 0 ) break; if( !(*it)->HasChildren() ) break;
timeline = &m_worker.GetZoneChildren( (*it)->Child() ); 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 != vec->begin() ) --it;
if( it->Start() > time || ( it->IsEndValid() && it->End() < time ) ) return ret; if( it->Start() > time || ( it->IsEndValid() && it->End() < time ) ) return ret;
ret = it; ret = it;
if( it->Child() < 0 ) return ret; if( !it->HasChildren() ) return ret;
timeline = &m_worker.GetZoneChildren( it->Child() ); timeline = &m_worker.GetZoneChildren( it->Child() );
} }
else else
@ -14307,7 +14307,7 @@ const ZoneEvent* View::FindZoneAtTime( uint64_t thread, int64_t time ) const
if( it != timeline->begin() ) --it; if( it != timeline->begin() ) --it;
if( (*it)->Start() > time || ( (*it)->IsEndValid() && (*it)->End() < time ) ) return ret; if( (*it)->Start() > time || ( (*it)->IsEndValid() && (*it)->End() < time ) ) return ret;
ret = *it; ret = *it;
if( (*it)->Child() < 0 ) return ret; if( !(*it)->HasChildren() ) return ret;
timeline = &m_worker.GetZoneChildren( (*it)->Child() ); timeline = &m_worker.GetZoneChildren( (*it)->Child() );
} }
} }
@ -14445,7 +14445,7 @@ void View::SetViewToLastFrames()
int64_t View::GetZoneChildTime( const ZoneEvent& zone ) int64_t View::GetZoneChildTime( const ZoneEvent& zone )
{ {
int64_t time = 0; int64_t time = 0;
if( zone.Child() >= 0 ) if( zone.HasChildren() )
{ {
auto& children = m_worker.GetZoneChildren( zone.Child() ); auto& children = m_worker.GetZoneChildren( zone.Child() );
if( children.is_magic() ) if( children.is_magic() )
@ -14499,7 +14499,7 @@ int64_t View::GetZoneChildTime( const GpuEvent& zone )
int64_t View::GetZoneChildTimeFast( const ZoneEvent& zone ) int64_t View::GetZoneChildTimeFast( const ZoneEvent& zone )
{ {
int64_t time = 0; int64_t time = 0;
if( zone.Child() >= 0 ) if( zone.HasChildren() )
{ {
auto& children = m_worker.GetZoneChildren( zone.Child() ); auto& children = m_worker.GetZoneChildren( zone.Child() );
if( children.is_magic() ) if( children.is_magic() )

View File

@ -1575,7 +1575,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
for( auto& zone : vec ) for( auto& zone : vec )
{ {
if( zone.IsEndValid() ) ReconstructZoneStatistics( zone, thread ); 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(;;) for(;;)
{ {
if( ptr->IsEndValid() ) return ptr->End(); if( ptr->IsEndValid() ) return ptr->End();
if( ptr->Child() < 0 ) return ptr->Start(); if( !ptr->HasChildren() ) return ptr->Start();
auto& children = GetZoneChildren( ptr->Child() ); auto& children = GetZoneChildren( ptr->Child() );
if( children.is_magic() ) if( children.is_magic() )
{ {
@ -2682,8 +2682,7 @@ void Worker::NewZone( ZoneEvent* zone, uint64_t thread )
else else
{ {
auto& back = td->stack.back(); auto& back = td->stack.back();
const auto backChild = back->Child(); if( !back->HasChildren() )
if( backChild < 0 )
{ {
back->SetChild( int32_t( m_data.zoneChildren.size() ) ); back->SetChild( int32_t( m_data.zoneChildren.size() ) );
if( m_data.zoneVectorCache.empty() ) if( m_data.zoneVectorCache.empty() )
@ -2701,6 +2700,7 @@ void Worker::NewZone( ZoneEvent* zone, uint64_t thread )
} }
else else
{ {
const auto backChild = back->Child();
assert( !m_data.zoneChildren[backChild].empty() ); assert( !m_data.zoneChildren[backChild].empty() );
m_data.zoneChildren[backChild].push_back_non_empty( zone ); 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; if( m_data.lastTime < timeEnd ) m_data.lastTime = timeEnd;
const auto child = zone->Child(); if( zone->HasChildren() )
if( child >= 0 )
{ {
auto& childVec = m_data.zoneChildren[child]; auto& childVec = m_data.zoneChildren[zone->Child()];
const auto sz = childVec.size(); const auto sz = childVec.size();
if( sz <= 8 * 1024 ) if( sz <= 8 * 1024 )
{ {
@ -5065,7 +5064,7 @@ void Worker::ReconstructZoneStatistics( ZoneEvent& zone, uint16_t thread )
if( slz.max < timeSpan ) slz.max = timeSpan; if( slz.max < timeSpan ) slz.max = timeSpan;
slz.total += timeSpan; slz.total += timeSpan;
slz.sumSq += double( timeSpan ) * timeSpan; slz.sumSq += double( timeSpan ) * timeSpan;
if( zone.Child() >= 0 ) if( zone.HasChildren() )
{ {
auto& children = GetZoneChildren( zone.Child() ); auto& children = GetZoneChildren( zone.Child() );
assert( children.is_magic() ); assert( children.is_magic() );