From b7fe29f750e8d7bbfc3842a187b2af7149ac3d3b Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 13 Mar 2019 01:46:05 +0100 Subject: [PATCH] Offload timeline statistics update to a background thread. --- server/TracyWorker.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 1b9da5d9..0577dda8 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -1132,6 +1132,26 @@ finishLoading: #ifndef TRACY_NO_STATISTICS m_threadBackground = std::thread( [this, reconstructMemAllocPlot] { + std::function&, uint16_t)> ProcessTimeline; + ProcessTimeline = [this, &ProcessTimeline] ( const Vector& vec, uint16_t thread ) + { + for( auto& zone : vec ) + { + ReadTimelineUpdateStatistics( zone, thread ); + if( zone->child >= 0 ) + { + ProcessTimeline( GetZoneChildren( zone->child ), thread ); + } + } + }; + + for( auto& t : m_data.threads ) + { + // Don't touch thread compression cache in a thread. + auto it = m_data.threadMap.find( t->id ); + assert( it != m_data.threadMap.end() ); + ProcessTimeline( t->timeline, it->second ); + } for( auto& v : m_data.sourceLocationZones ) { auto& zones = v.second.zones; @@ -3605,7 +3625,9 @@ void Worker::ReadTimeline( FileRead& f, Vector& vec, uint16_t thread zone->start = refTime; ReadTimeline( f, zone, thread, refTime ); zone->end = ReadTimeOffset( f, refTime ); +#ifdef TRACY_NO_STATISTICS ReadTimelineUpdateStatistics( zone, thread ); +#endif } while( ++zone != zptr ); } @@ -3639,7 +3661,9 @@ void Worker::ReadTimelinePre042( FileRead& f, Vector& vec, uint16_t f.Read( zone, sizeof( ZoneEvent ) - sizeof( ZoneEvent::child ) ); } ReadTimelinePre042( f, zone, thread, fileVer ); +#ifdef TRACY_NO_STATISTICS ReadTimelineUpdateStatistics( zone, thread ); +#endif } }