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

Adapt zone getters to magic vectors.

This commit is contained in:
Bartosz Taudul 2019-11-10 00:51:32 +01:00
parent f8edd3a37b
commit 0c1f3ac16d

View File

@ -13366,6 +13366,19 @@ int View::GetZoneDepth( const ZoneEvent& zone, uint64_t tid ) const
auto timeline = &td->timeline; auto timeline = &td->timeline;
int depth = 0; int depth = 0;
for(;;) for(;;)
{
if( timeline->is_magic() )
{
auto vec = (Vector<ZoneEvent>*)timeline;
auto it = std::upper_bound( vec->begin(), vec->end(), zone.Start(), [] ( const auto& l, const auto& r ) { return l < r.Start(); } );
if( it != vec->begin() ) --it;
assert( !( zone.End() >= 0 && it->Start() > zone.End() ) );
if( it == &zone ) return depth;
assert( it->Child() >= 0 );
timeline = &m_worker.GetZoneChildren( it->Child() );
depth++;
}
else
{ {
auto it = std::upper_bound( timeline->begin(), timeline->end(), zone.Start(), [] ( const auto& l, const auto& r ) { return l < r->Start(); } ); auto it = std::upper_bound( timeline->begin(), timeline->end(), zone.Start(), [] ( const auto& l, const auto& r ) { return l < r->Start(); } );
if( it != timeline->begin() ) --it; if( it != timeline->begin() ) --it;
@ -13376,6 +13389,7 @@ int View::GetZoneDepth( const ZoneEvent& zone, uint64_t tid ) const
depth++; depth++;
} }
} }
}
const ZoneEvent* View::GetZoneParent( const ZoneEvent& zone ) const const ZoneEvent* View::GetZoneParent( const ZoneEvent& zone ) const
{ {
@ -13385,6 +13399,19 @@ const ZoneEvent* View::GetZoneParent( const ZoneEvent& zone ) const
const Vector<short_ptr<ZoneEvent>>* timeline = &thread->timeline; const Vector<short_ptr<ZoneEvent>>* timeline = &thread->timeline;
if( timeline->empty() ) continue; if( timeline->empty() ) continue;
for(;;) for(;;)
{
if( timeline->is_magic() )
{
auto vec = (Vector<ZoneEvent>*)timeline;
auto it = std::upper_bound( vec->begin(), vec->end(), zone.Start(), [] ( const auto& l, const auto& r ) { return l < r.Start(); } );
if( it != vec->begin() ) --it;
if( zone.End() >= 0 && it->Start() > zone.End() ) break;
if( it == &zone ) return parent;
if( it->Child() < 0 ) break;
parent = it;
timeline = &m_worker.GetZoneChildren( parent->Child() );
}
else
{ {
auto it = std::upper_bound( timeline->begin(), timeline->end(), zone.Start(), [] ( const auto& l, const auto& r ) { return l < r->Start(); } ); auto it = std::upper_bound( timeline->begin(), timeline->end(), zone.Start(), [] ( const auto& l, const auto& r ) { return l < r->Start(); } );
if( it != timeline->begin() ) --it; if( it != timeline->begin() ) --it;
@ -13395,6 +13422,7 @@ const ZoneEvent* View::GetZoneParent( const ZoneEvent& zone ) const
timeline = &m_worker.GetZoneChildren( parent->Child() ); timeline = &m_worker.GetZoneChildren( parent->Child() );
} }
} }
}
return nullptr; return nullptr;
} }
@ -13405,6 +13433,19 @@ const ZoneEvent* View::GetZoneParent( const ZoneEvent& zone, uint64_t tid ) cons
const Vector<short_ptr<ZoneEvent>>* timeline = &thread->timeline; const Vector<short_ptr<ZoneEvent>>* timeline = &thread->timeline;
if( timeline->empty() ) return nullptr; if( timeline->empty() ) return nullptr;
for(;;) for(;;)
{
if( timeline->is_magic() )
{
auto vec = (Vector<ZoneEvent>*)timeline;
auto it = std::upper_bound( vec->begin(), vec->end(), zone.Start(), [] ( const auto& l, const auto& r ) { return l < r.Start(); } );
if( it != vec->begin() ) --it;
if( zone.End() >= 0 && it->Start() > zone.End() ) break;
if( it == &zone ) return parent;
if( it->Child() < 0 ) break;
parent = it;
timeline = &m_worker.GetZoneChildren( parent->Child() );
}
else
{ {
auto it = std::upper_bound( timeline->begin(), timeline->end(), zone.Start(), [] ( const auto& l, const auto& r ) { return l < r->Start(); } ); auto it = std::upper_bound( timeline->begin(), timeline->end(), zone.Start(), [] ( const auto& l, const auto& r ) { return l < r->Start(); } );
if( it != timeline->begin() ) --it; if( it != timeline->begin() ) --it;
@ -13414,6 +13455,7 @@ const ZoneEvent* View::GetZoneParent( const ZoneEvent& zone, uint64_t tid ) cons
parent = *it; parent = *it;
timeline = &m_worker.GetZoneChildren( parent->Child() ); timeline = &m_worker.GetZoneChildren( parent->Child() );
} }
}
return nullptr; return nullptr;
} }
@ -13448,6 +13490,18 @@ const ThreadData* View::GetZoneThreadData( const ZoneEvent& zone ) const
const Vector<short_ptr<ZoneEvent>>* timeline = &thread->timeline; const Vector<short_ptr<ZoneEvent>>* timeline = &thread->timeline;
if( timeline->empty() ) continue; if( timeline->empty() ) continue;
for(;;) for(;;)
{
if( timeline->is_magic() )
{
auto vec = (Vector<ZoneEvent>*)timeline;
auto it = std::upper_bound( vec->begin(), vec->end(), zone.Start(), [] ( const auto& l, const auto& r ) { return l < r.Start(); } );
if( it != vec->begin() ) --it;
if( zone.End() >= 0 && it->Start() > zone.End() ) break;
if( it == &zone ) return thread;
if( it->Child() < 0 ) break;
timeline = &m_worker.GetZoneChildren( it->Child() );
}
else
{ {
auto it = std::upper_bound( timeline->begin(), timeline->end(), zone.Start(), [] ( const auto& l, const auto& r ) { return l < r->Start(); } ); auto it = std::upper_bound( timeline->begin(), timeline->end(), zone.Start(), [] ( const auto& l, const auto& r ) { return l < r->Start(); } );
if( it != timeline->begin() ) --it; if( it != timeline->begin() ) --it;
@ -13457,6 +13511,7 @@ const ThreadData* View::GetZoneThreadData( const ZoneEvent& zone ) const
timeline = &m_worker.GetZoneChildren( (*it)->Child() ); timeline = &m_worker.GetZoneChildren( (*it)->Child() );
} }
} }
}
return nullptr; return nullptr;
} }
@ -13533,6 +13588,18 @@ const ZoneEvent* View::FindZoneAtTime( uint64_t thread, int64_t time ) const
if( timeline->empty() ) return nullptr; if( timeline->empty() ) return nullptr;
const ZoneEvent* ret = nullptr; const ZoneEvent* ret = nullptr;
for(;;) for(;;)
{
if( timeline->is_magic() )
{
auto vec = (Vector<ZoneEvent>*)timeline;
auto it = std::upper_bound( vec->begin(), vec->end(), time, [] ( const auto& l, const auto& r ) { return l < r.Start(); } );
if( it != vec->begin() ) --it;
if( it->Start() > time || ( it->End() >= 0 && it->End() < time ) ) return ret;
ret = it;
if( it->Child() < 0 ) return ret;
timeline = &m_worker.GetZoneChildren( it->Child() );
}
else
{ {
auto it = std::upper_bound( timeline->begin(), timeline->end(), time, [] ( const auto& l, const auto& r ) { return l < r->Start(); } ); auto it = std::upper_bound( timeline->begin(), timeline->end(), time, [] ( const auto& l, const auto& r ) { return l < r->Start(); } );
if( it != timeline->begin() ) --it; if( it != timeline->begin() ) --it;
@ -13542,6 +13609,7 @@ const ZoneEvent* View::FindZoneAtTime( uint64_t thread, int64_t time ) const
timeline = &m_worker.GetZoneChildren( (*it)->Child() ); timeline = &m_worker.GetZoneChildren( (*it)->Child() );
} }
} }
}
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS
void View::FindZones() void View::FindZones()
@ -13644,12 +13712,25 @@ int64_t View::GetZoneChildTime( const ZoneEvent& zone )
int64_t time = 0; int64_t time = 0;
if( zone.Child() >= 0 ) if( zone.Child() >= 0 )
{ {
for( auto& v : m_worker.GetZoneChildren( zone.Child() ) ) auto& children = m_worker.GetZoneChildren( zone.Child() );
if( children.is_magic() )
{
auto& vec = *(Vector<ZoneEvent>*)&children;
for( auto& v : vec )
{
const auto childSpan = std::max( int64_t( 0 ), v.End() - v.Start() );
time += childSpan;
}
}
else
{
for( auto& v : children )
{ {
const auto childSpan = std::max( int64_t( 0 ), v->End() - v->Start() ); const auto childSpan = std::max( int64_t( 0 ), v->End() - v->Start() );
time += childSpan; time += childSpan;
} }
} }
}
return time; return time;
} }
@ -13672,12 +13753,25 @@ int64_t View::GetZoneChildTimeFast( const ZoneEvent& zone )
int64_t time = 0; int64_t time = 0;
if( zone.Child() >= 0 ) if( zone.Child() >= 0 )
{ {
for( auto& v : m_worker.GetZoneChildren( zone.Child() ) ) auto& children = m_worker.GetZoneChildren( zone.Child() );
if( children.is_magic() )
{
auto& vec = *(Vector<ZoneEvent>*)&children;
for( auto& v : vec )
{
assert( v.End() >= 0 );
time += v.End() - v.Start();
}
}
else
{
for( auto& v : children )
{ {
assert( v->End() >= 0 ); assert( v->End() >= 0 );
time += v->End() - v->Start(); time += v->End() - v->Start();
} }
} }
}
return time; return time;
} }