Count zones at zone end, not zone begin.

This makes sure only finished, non-zero-timespan zones are counted in
the statistics.
This commit is contained in:
Bartosz Taudul 2020-01-23 19:03:03 +01:00
parent 23601904cd
commit e31b529b4a

View File

@ -326,6 +326,15 @@ Worker::Worker( const std::string& program, const std::vector<ImportEventTimelin
auto& stack = td->stack; auto& stack = td->stack;
auto zone = stack.back_and_pop(); auto zone = stack.back_and_pop();
zone->SetEnd( v.timestamp ); zone->SetEnd( v.timestamp );
#ifndef TRACY_NO_STATISTICS
auto slz = GetSourceLocationZones( zone->SrcLoc() );
auto& ztd = slz->zones.push_next();
ztd.SetZone( zone );
ztd.SetThread( CompressThread( v.tid ) );
#else
CountZoneStatistics( zone );
#endif
} }
} }
@ -1565,11 +1574,8 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
auto& vec = *(Vector<ZoneEvent>*)( &_vec ); auto& vec = *(Vector<ZoneEvent>*)( &_vec );
for( auto& zone : vec ) for( auto& zone : vec )
{ {
ReconstructZoneStatistics( zone, thread ); if( zone.IsEndValid() ) ReconstructZoneStatistics( zone, thread );
if( zone.Child() >= 0 ) if( zone.Child() >= 0 ) ProcessTimeline( GetZoneChildrenMutable( zone.Child() ), thread );
{
ProcessTimeline( GetZoneChildrenMutable( zone.Child() ), thread );
}
} }
}; };
@ -2665,15 +2671,6 @@ void Worker::NewZone( ZoneEvent* zone, uint64_t thread )
{ {
m_data.zonesCnt++; m_data.zonesCnt++;
#ifndef TRACY_NO_STATISTICS
auto slz = GetSourceLocationZones( zone->SrcLoc() );
auto& ztd = slz->zones.push_next();
ztd.SetZone( zone );
ztd.SetThread( CompressThread( thread ) );
#else
CountZoneStatistics( zone );
#endif
auto td = m_threadCtxData; auto td = m_threadCtxData;
if( !td ) td = m_threadCtxData = NoticeThread( thread ); if( !td ) td = m_threadCtxData = NoticeThread( thread );
td->count++; td->count++;
@ -3538,6 +3535,9 @@ void Worker::ProcessZoneEnd( const QueueZoneEnd& ev )
if( timeSpan > 0 ) if( timeSpan > 0 )
{ {
auto slz = GetSourceLocationZones( zone->SrcLoc() ); auto slz = GetSourceLocationZones( zone->SrcLoc() );
auto& ztd = slz->zones.push_next();
ztd.SetZone( zone );
ztd.SetThread( CompressThread( m_threadCtx ) );
if( slz->min > timeSpan ) slz->min = timeSpan; if( slz->min > timeSpan ) slz->min = timeSpan;
if( slz->max < timeSpan ) slz->max = timeSpan; if( slz->max < timeSpan ) slz->max = timeSpan;
slz->total += timeSpan; slz->total += timeSpan;
@ -3555,6 +3555,8 @@ void Worker::ProcessZoneEnd( const QueueZoneEnd& ev )
{ {
td->childTimeStack.pop_back(); td->childTimeStack.pop_back();
} }
#else
CountZoneStatistics( zone );
#endif #endif
} }
@ -5049,18 +5051,16 @@ void Worker::ReadTimelinePre0510( FileRead& f, GpuEvent* zone, int64_t& refTime,
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS
void Worker::ReconstructZoneStatistics( ZoneEvent& zone, uint16_t thread ) void Worker::ReconstructZoneStatistics( ZoneEvent& zone, uint16_t thread )
{ {
assert( zone.IsEndValid() );
auto timeSpan = zone.End() - zone.Start();
if( timeSpan > 0 )
{
auto it = m_data.sourceLocationZones.find( zone.SrcLoc() ); auto it = m_data.sourceLocationZones.find( zone.SrcLoc() );
assert( it != m_data.sourceLocationZones.end() ); assert( it != m_data.sourceLocationZones.end() );
auto& slz = it->second; auto& slz = it->second;
auto& ztd = slz.zones.push_next(); auto& ztd = slz.zones.push_next();
ztd.SetZone( &zone ); ztd.SetZone( &zone );
ztd.SetThread( thread ); ztd.SetThread( thread );
if( zone.IsEndValid() )
{
auto timeSpan = zone.End() - zone.Start();
if( timeSpan > 0 )
{
if( slz.min > timeSpan ) slz.min = timeSpan; if( slz.min > timeSpan ) slz.min = timeSpan;
if( slz.max < timeSpan ) slz.max = timeSpan; if( slz.max < timeSpan ) slz.max = timeSpan;
slz.total += timeSpan; slz.total += timeSpan;
@ -5080,7 +5080,6 @@ void Worker::ReconstructZoneStatistics( ZoneEvent& zone, uint16_t thread )
if( slz.selfMax < timeSpan ) slz.selfMax = timeSpan; if( slz.selfMax < timeSpan ) slz.selfMax = timeSpan;
slz.selfTotal += timeSpan; slz.selfTotal += timeSpan;
} }
}
} }
#else #else
void Worker::CountZoneStatistics( ZoneEvent* zone ) void Worker::CountZoneStatistics( ZoneEvent* zone )