From b3e0d2660da604ffcdf921f58701b37f0589ed5a Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 19 Nov 2017 01:16:21 +0100 Subject: [PATCH] Properly use zone stack when inserting new zones. CPU zones stack was also moved to thread data struct. --- server/TracyEvent.hpp | 1 + server/TracyView.cpp | 49 +++++++++++++++---------------------------- server/TracyView.hpp | 4 ---- 3 files changed, 18 insertions(+), 36 deletions(-) diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index 0efe7632..583e4faf 100644 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -132,6 +132,7 @@ struct ThreadData bool showFull; bool visible; Vector timeline; + Vector stack; Vector messages; }; diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 61cc11bc..b415bebd 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -490,9 +490,9 @@ void View::Worker() continue; } bool done = true; - for( auto& v : m_zoneStack ) + for( auto& v : m_threads ) { - if( !v.second.empty() ) + if( !v->stack.empty() ) { done = false; break; @@ -633,7 +633,6 @@ void View::ProcessZoneBegin( const QueueZoneBegin& ev ) zone->cpu_start = ev.cpu == 0xFFFFFFFF ? -1 : (int8_t)ev.cpu; NewZone( zone, ev.thread ); - m_zoneStack[ev.thread].push_back( zone ); } void View::ProcessZoneBeginAllocSrcLoc( const QueueZoneBegin& ev ) @@ -651,14 +650,17 @@ void View::ProcessZoneBeginAllocSrcLoc( const QueueZoneBegin& ev ) zone->srcloc = it->second; NewZone( zone, ev.thread ); - m_zoneStack[ev.thread].push_back( zone ); m_pendingSourceLocationPayload.erase( it ); } void View::ProcessZoneEnd( const QueueZoneEnd& ev ) { - auto& stack = m_zoneStack[ev.thread]; + auto tit = m_threadMap.find( ev.thread ); + assert( tit != m_threadMap.end() ); + + auto td = m_threads[tit->second]; + auto& stack = td->stack; assert( !stack.empty() ); auto zone = stack.back(); stack.pop_back(); @@ -667,7 +669,6 @@ void View::ProcessZoneEnd( const QueueZoneEnd& ev ) assert( ev.cpu == 0xFFFFFFFF || ev.cpu <= std::numeric_limits::max() ); zone->cpu_end = ev.cpu == 0xFFFFFFFF ? -1 : (int8_t)ev.cpu; assert( zone->end >= zone->start ); - UpdateZone( zone ); } void View::ProcessFrameMark( const QueueFrameMark& ev ) @@ -681,7 +682,11 @@ void View::ProcessFrameMark( const QueueFrameMark& ev ) void View::ProcessZoneText( const QueueZoneText& ev ) { - auto& stack = m_zoneStack[ev.thread]; + auto tit = m_threadMap.find( ev.thread ); + assert( tit != m_threadMap.end() ); + + auto td = m_threads[tit->second]; + auto& stack = td->stack; assert( !stack.empty() ); auto zone = stack.back(); auto it = m_pendingCustomStrings.find( ev.text ); @@ -1109,35 +1114,15 @@ void View::NewZone( ZoneEvent* zone, uint64_t thread ) m_zonesCnt++; auto td = NoticeThread( thread ); td->count++; - Vector* timeline = &td->timeline; - InsertZone( zone, *timeline ); -} - -void View::UpdateZone( ZoneEvent* zone ) -{ - assert( zone->end != -1 ); - assert( std::upper_bound( zone->child.begin(), zone->child.end(), zone->end, [] ( const auto& l, const auto& r ) { return l < r->start; } ) == zone->child.end() ); -} - -void View::InsertZone( ZoneEvent* zone, Vector& vec ) -{ - if( !vec.empty() ) + if( td->stack.empty() ) { - const auto lastend = vec.back()->end; - if( lastend != -1 && lastend <= zone->start ) - { - vec.push_back( zone ); - } - else - { - assert( std::upper_bound( vec.begin(), vec.end(), zone->start, [] ( const auto& l, const auto& r ) { return l < r->start; } ) == vec.end() ); - assert( vec.back()->end == -1 || vec.back()->end >= zone->end ); - InsertZone( zone, vec.back()->child ); - } + td->stack.push_back( zone ); + td->timeline.push_back( zone ); } else { - vec.push_back( zone ); + td->stack.back()->child.push_back( zone ); + td->stack.push_back( zone ); } } diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 1b32dcf6..110cb669 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -89,9 +89,6 @@ private: ThreadData* NoticeThread( uint64_t thread ); void NewZone( ZoneEvent* zone, uint64_t thread ); - void UpdateZone( ZoneEvent* zone ); - - void InsertZone( ZoneEvent* zone, Vector& vec ); void InsertLockEvent( LockMap& lockmap, LockEvent* lev, uint64_t thread ); void UpdateLockCount( LockMap& lockmap, size_t pos ); @@ -187,7 +184,6 @@ private: std::vector m_mbps; // not used for vis - no need to lock - flat_hash_map, power_of_two_std_hash> m_zoneStack; flat_hash_set> m_pendingStrings; flat_hash_set> m_pendingThreads; flat_hash_set> m_pendingSourceLocation;