Add zone child time getter with clamping to time range.

This commit is contained in:
Bartosz Taudul 2020-05-25 01:14:44 +02:00
parent e0d7ffe754
commit 74a79a6921
2 changed files with 40 additions and 0 deletions

View File

@ -16270,6 +16270,45 @@ int64_t View::GetZoneChildTimeFast( const ZoneEvent& zone )
return time;
}
int64_t View::GetZoneChildTimeFastClamped( const ZoneEvent& zone, uint64_t t0, uint64_t t1 )
{
int64_t time = 0;
if( zone.HasChildren() )
{
auto& children = m_worker.GetZoneChildren( zone.Child() );
if( children.is_magic() )
{
auto& vec = *(Vector<ZoneEvent>*)&children;
auto it = std::lower_bound( vec.begin(), vec.end(), t0, [] ( const auto& l, const auto& r ) { return (uint64_t)l.End() < (uint64_t)r; } );
if( it == vec.end() ) return 0;
const auto zitend = std::lower_bound( it, vec.end(), t1, [] ( const auto& l, const auto& r ) { return l.Start() < r; } );
if( it == zitend ) return 0;
while( it < zitend )
{
const auto c0 = std::max<uint64_t>( it->Start(), t0 );
const auto c1 = std::min<uint64_t>( it->End(), t1 );
time += c1 - c0;
++it;
}
}
else
{
auto it = std::lower_bound( children.begin(), children.end(), t0, [] ( const auto& l, const auto& r ) { return (uint64_t)l->End() < (uint64_t)r; } );
if( it == children.end() ) return 0;
const auto zitend = std::lower_bound( it, children.end(), t1, [] ( const auto& l, const auto& r ) { return l->Start() < r; } );
if( it == zitend ) return 0;
while( it < zitend )
{
const auto c0 = std::max<uint64_t>( (*it)->Start(), t0 );
const auto c1 = std::min<uint64_t>( (*it)->End(), t1 );
time += c1 - c0;
++it;
}
}
}
return time;
}
int64_t View::GetZoneSelfTime( const ZoneEvent& zone )
{
if( m_cache.zoneSelfTime.first == &zone ) return m_cache.zoneSelfTime.second;

View File

@ -242,6 +242,7 @@ private:
int64_t GetZoneChildTime( const ZoneEvent& zone );
int64_t GetZoneChildTime( const GpuEvent& zone );
int64_t GetZoneChildTimeFast( const ZoneEvent& zone );
int64_t GetZoneChildTimeFastClamped( const ZoneEvent& zone, uint64_t t0, uint64_t t1 );
int64_t GetZoneSelfTime( const ZoneEvent& zone );
int64_t GetZoneSelfTime( const GpuEvent& zone );
bool GetZoneRunningTime( const ContextSwitch* ctx, const ZoneEvent& ev, int64_t& time, uint64_t& cnt );