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

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 zone = stack.back_and_pop();
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 );
for( auto& zone : vec )
{
ReconstructZoneStatistics( zone, thread );
if( zone.Child() >= 0 )
{
ProcessTimeline( GetZoneChildrenMutable( zone.Child() ), thread );
}
if( zone.IsEndValid() ) ReconstructZoneStatistics( zone, thread );
if( zone.Child() >= 0 ) ProcessTimeline( GetZoneChildrenMutable( zone.Child() ), thread );
}
};
@ -2665,15 +2671,6 @@ void Worker::NewZone( ZoneEvent* zone, uint64_t thread )
{
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;
if( !td ) td = m_threadCtxData = NoticeThread( thread );
td->count++;
@ -3538,6 +3535,9 @@ void Worker::ProcessZoneEnd( const QueueZoneEnd& ev )
if( timeSpan > 0 )
{
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->max < timeSpan ) slz->max = timeSpan;
slz->total += timeSpan;
@ -3555,6 +3555,8 @@ void Worker::ProcessZoneEnd( const QueueZoneEnd& ev )
{
td->childTimeStack.pop_back();
}
#else
CountZoneStatistics( zone );
#endif
}
@ -5048,6 +5050,10 @@ void Worker::ReadTimelinePre0510( FileRead& f, GpuEvent* zone, int64_t& refTime,
#ifndef TRACY_NO_STATISTICS
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() );
assert( it != m_data.sourceLocationZones.end() );
@ -5055,12 +5061,6 @@ void Worker::ReconstructZoneStatistics( ZoneEvent& zone, uint16_t thread )
auto& ztd = slz.zones.push_next();
ztd.SetZone( &zone );
ztd.SetThread( thread );
if( zone.IsEndValid() )
{
auto timeSpan = zone.End() - zone.Start();
if( timeSpan > 0 )
{
if( slz.min > timeSpan ) slz.min = timeSpan;
if( slz.max < timeSpan ) slz.max = timeSpan;
slz.total += timeSpan;
@ -5081,7 +5081,6 @@ void Worker::ReconstructZoneStatistics( ZoneEvent& zone, uint16_t thread )
slz.selfTotal += timeSpan;
}
}
}
#else
void Worker::CountZoneStatistics( ZoneEvent* zone )
{