From ba87929074eaeaa67b250cf05fdb8edc2d5883af Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 29 Jan 2022 00:48:01 +0100 Subject: [PATCH] Perform GPU statistics reconstruction. Note: Zone counts are currently being calculated, but they are not being saved. Proper usage of this data (as is performed in the CPU counterpart) would remove the possibility of insertion of new entries into the map in ReconstructZoneStatistics(). --- server/TracyWorker.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++ server/TracyWorker.hpp | 1 + 2 files changed, 56 insertions(+) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 07fc5f6d..2474f0fc 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -1978,6 +1978,38 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks ) m_data.sourceLocationZonesReady = true; } ) ); + std::function>&, uint16_t)> ProcessTimelineGpu; + ProcessTimelineGpu = [this, &ProcessTimelineGpu] ( Vector>& _vec, uint16_t thread ) + { + if( m_shutdown.load( std::memory_order_relaxed ) ) return; + assert( _vec.is_magic() ); + auto& vec = *(Vector*)( &_vec ); + for( auto& zone : vec ) + { + if( zone.GpuEnd() >= 0 ) ReconstructZoneStatistics( zone, thread ); + if( zone.Child() >= 0 ) + { + ProcessTimelineGpu( GetGpuChildrenMutable( zone.Child() ), thread ); + } + } + }; + + jobs.emplace_back( std::thread( [this, ProcessTimelineGpu] { + for( auto& t : m_data.gpuData ) + { + for( auto& td : t->threadData ) + { + if( m_shutdown.load( std::memory_order_relaxed ) ) return; + if( !td.second.timeline.empty() ) + { + ProcessTimelineGpu( td.second.timeline, td.first ); + } + } + } + std::lock_guard lock( m_data.lock ); + m_data.gpuSourceLocationZonesReady = true; + } ) ); + if( eventMask & EventType::Samples ) { jobs.emplace_back( std::thread( [this] { @@ -7692,6 +7724,29 @@ void Worker::ReconstructZoneStatistics( uint8_t* countMap, ZoneEvent& zone, uint slz.selfTotal += timeSpan; } } + +void Worker::ReconstructZoneStatistics( GpuEvent& zone, uint16_t thread ) +{ + assert( zone.GpuEnd() >= 0 ); + auto timeSpan = zone.GpuEnd() - zone.GpuStart(); + if( timeSpan > 0 ) + { + auto it = m_data.gpuSourceLocationZones.find( zone.SrcLoc() ); + if( it == m_data.gpuSourceLocationZones.end() ) + { + it = m_data.gpuSourceLocationZones.emplace( zone.SrcLoc(), GpuSourceLocationZones {} ).first; + } + GpuZoneThreadData ztd; + ztd.SetZone( &zone ); + ztd.SetThread( thread ); + auto& slz = it->second; + slz.zones.push_back( ztd ); + if( slz.min > timeSpan ) slz.min = timeSpan; + if( slz.max < timeSpan ) slz.max = timeSpan; + slz.total += timeSpan; + slz.sumSq += double( timeSpan ) * timeSpan; + } +} #else void Worker::CountZoneStatistics( ZoneEvent* zone ) { diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 68de6e4c..453ff525 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -905,6 +905,7 @@ private: #ifndef TRACY_NO_STATISTICS tracy_force_inline void ReconstructZoneStatistics( uint8_t* countMap, ZoneEvent& zone, uint16_t thread ); + tracy_force_inline void ReconstructZoneStatistics( GpuEvent& zone, uint16_t thread ); #else tracy_force_inline void CountZoneStatistics( ZoneEvent* zone ); tracy_force_inline void CountZoneStatistics( GpuEvent* zone );