diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 55965629..60c4190e 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -2171,7 +2171,7 @@ void View::DrawZones() size_t lockCnt = 0; for( const auto& lock : m_worker.GetLockMap() ) { - const auto& lockmap = lock.second; + const auto& lockmap = *lock.second; if( !lockmap.valid ) continue; auto it = lockmap.threadMap.find( v->id ); if( it == lockmap.threadMap.end() ) continue; @@ -3126,7 +3126,7 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos, int cnt = 0; for( const auto& v : m_worker.GetLockMap() ) { - const auto& lockmap = v.second; + const auto& lockmap = *v.second; if( !lockmap.valid || !Vis( &lockmap ).visible ) continue; if( m_onlyContendedLocks && lockmap.threadList.size() == 1 && m_lockInfoWindow != v.first ) continue; @@ -5196,10 +5196,10 @@ void View::DrawOptions() size_t multiCnt = 0; for( const auto& l : m_worker.GetLockMap() ) { - if( l.second.valid && !l.second.timeline.empty() ) + if( l.second->valid && !l.second->timeline.empty() ) { lockCnt++; - if( l.second.threadList.size() == 1 ) + if( l.second->threadList.size() == 1 ) { singleCnt++; } @@ -5233,7 +5233,7 @@ void View::DrawOptions() { for( const auto& l : m_worker.GetLockMap() ) { - Vis( &l.second ).visible = true; + Vis( l.second ).visible = true; } } ImGui::SameLine(); @@ -5241,7 +5241,7 @@ void View::DrawOptions() { for( const auto& l : m_worker.GetLockMap() ) { - Vis( &l.second ).visible = false; + Vis( l.second ).visible = false; } } ImGui::SameLine(); @@ -5256,7 +5256,7 @@ void View::DrawOptions() { for( const auto& l : m_worker.GetLockMap() ) { - if( l.second.threadList.size() != 1 ) Vis( &l.second ).visible = true; + if( l.second->threadList.size() != 1 ) Vis( l.second ).visible = true; } } ImGui::SameLine(); @@ -5264,20 +5264,20 @@ void View::DrawOptions() { for( const auto& l : m_worker.GetLockMap() ) { - if( l.second.threadList.size() != 1 ) Vis( &l.second ).visible = false; + if( l.second->threadList.size() != 1 ) Vis( l.second ).visible = false; } } for( const auto& l : m_worker.GetLockMap() ) { - if( l.second.valid && !l.second.timeline.empty() && l.second.threadList.size() != 1 ) + if( l.second->valid && !l.second->timeline.empty() && l.second->threadList.size() != 1 ) { - auto& sl = m_worker.GetSourceLocation( l.second.srcloc ); + auto& sl = m_worker.GetSourceLocation( l.second->srcloc ); auto fileName = m_worker.GetString( sl.file ); char buf[1024]; - sprintf( buf, "%" PRIu32 ": %s", l.first, m_worker.GetString( m_worker.GetSourceLocation( l.second.srcloc ).function ) ); - ImGui::Checkbox( buf, &Vis( &l.second ).visible ); + sprintf( buf, "%" PRIu32 ": %s", l.first, m_worker.GetString( m_worker.GetSourceLocation( l.second->srcloc ).function ) ); + ImGui::Checkbox( buf, &Vis( l.second ).visible ); if( ImGui::IsItemHovered() ) { m_lockHoverHighlight = l.first; @@ -5287,7 +5287,7 @@ void View::DrawOptions() m_lockInfoWindow = l.first; } } - if( m_optionsLockBuzzAnim.Match( l.second.srcloc ) ) + if( m_optionsLockBuzzAnim.Match( l.second->srcloc ) ) { const auto time = m_optionsLockBuzzAnim.Time(); const auto indentVal = sin( time * 60.f ) * 10.f * time; @@ -5297,7 +5297,7 @@ void View::DrawOptions() { ImGui::SameLine(); } - ImGui::TextDisabled( "(%s) %s:%i", RealToString( l.second.timeline.size(), true ), fileName, sl.line ); + ImGui::TextDisabled( "(%s) %s:%i", RealToString( l.second->timeline.size(), true ), fileName, sl.line ); if( ImGui::IsItemClicked( 1 ) ) { if( FileExists( fileName ) ) @@ -5306,7 +5306,7 @@ void View::DrawOptions() } else { - m_optionsLockBuzzAnim.Enable( l.second.srcloc, 0.5f ); + m_optionsLockBuzzAnim.Enable( l.second->srcloc, 0.5f ); } } } @@ -5322,7 +5322,7 @@ void View::DrawOptions() { for( const auto& l : m_worker.GetLockMap() ) { - if( l.second.threadList.size() == 1 ) Vis( &l.second ).visible = true; + if( l.second->threadList.size() == 1 ) Vis( l.second ).visible = true; } } ImGui::SameLine(); @@ -5330,20 +5330,20 @@ void View::DrawOptions() { for( const auto& l : m_worker.GetLockMap() ) { - if( l.second.threadList.size() == 1 ) Vis( &l.second ).visible = false; + if( l.second->threadList.size() == 1 ) Vis( l.second ).visible = false; } } for( const auto& l : m_worker.GetLockMap() ) { - if( l.second.valid && !l.second.timeline.empty() && l.second.threadList.size() == 1 ) + if( l.second->valid && !l.second->timeline.empty() && l.second->threadList.size() == 1 ) { - auto& sl = m_worker.GetSourceLocation( l.second.srcloc ); + auto& sl = m_worker.GetSourceLocation( l.second->srcloc ); auto fileName = m_worker.GetString( sl.file ); char buf[1024]; - sprintf( buf, "%" PRIu32 ": %s", l.first, m_worker.GetString( m_worker.GetSourceLocation( l.second.srcloc ).function ) ); - ImGui::Checkbox( buf, &Vis( &l.second ).visible ); + sprintf( buf, "%" PRIu32 ": %s", l.first, m_worker.GetString( m_worker.GetSourceLocation( l.second->srcloc ).function ) ); + ImGui::Checkbox( buf, &Vis( l.second ).visible ); if( ImGui::IsItemHovered() ) { m_lockHoverHighlight = l.first; @@ -5353,7 +5353,7 @@ void View::DrawOptions() m_lockInfoWindow = l.first; } } - if( m_optionsLockBuzzAnim.Match( l.second.srcloc ) ) + if( m_optionsLockBuzzAnim.Match( l.second->srcloc ) ) { const auto time = m_optionsLockBuzzAnim.Time(); const auto indentVal = sin( time * 60.f ) * 10.f * time; @@ -5363,7 +5363,7 @@ void View::DrawOptions() { ImGui::SameLine(); } - ImGui::TextDisabled( "(%s) %s:%i", RealToString( l.second.timeline.size(), true ), fileName, sl.line ); + ImGui::TextDisabled( "(%s) %s:%i", RealToString( l.second->timeline.size(), true ), fileName, sl.line ); if( ImGui::IsItemClicked( 1 ) ) { if( FileExists( fileName ) ) @@ -5372,7 +5372,7 @@ void View::DrawOptions() } else { - m_optionsLockBuzzAnim.Enable( l.second.srcloc, 0.5f ); + m_optionsLockBuzzAnim.Enable( l.second->srcloc, 0.5f ); } } } @@ -8403,7 +8403,7 @@ void View::DrawLockInfoWindow() { auto it = m_worker.GetLockMap().find( m_lockInfoWindow ); assert( it != m_worker.GetLockMap().end() ); - const auto& lock = it->second; + const auto& lock = *it->second; const auto& srcloc = m_worker.GetSourceLocation( lock.srcloc ); auto fileName = m_worker.GetString( srcloc.file ); diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index e4a58905..7d1afc5b 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -566,7 +566,8 @@ Worker::Worker( FileRead& f, EventType::Type eventMask ) for( uint64_t i=0; i(); + auto& lockmap = *lockmapPtr; uint32_t id; uint64_t tsz; f.Read( id ); @@ -665,7 +666,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask ) } } UpdateLockCount( lockmap, 0 ); - m_data.lockMap.emplace( id, std::move( lockmap ) ); + m_data.lockMap.emplace( id, lockmapPtr ); } } else @@ -1214,6 +1215,10 @@ Worker::~Worker() { v->~FrameData(); } + for( auto& v : m_data.lockMap ) + { + v.second->~LockMap(); + } } uint64_t Worker::GetLockCount() const @@ -1221,7 +1226,7 @@ uint64_t Worker::GetLockCount() const uint64_t cnt = 0; for( auto& l : m_data.lockMap ) { - cnt += l.second.timeline.size(); + cnt += l.second->timeline.size(); } return cnt; } @@ -2763,20 +2768,20 @@ void Worker::ProcessLockAnnounce( const QueueLockAnnounce& ev ) auto it = m_data.lockMap.find( ev.id ); if( it == m_data.lockMap.end() ) { - LockMap lm; - lm.srcloc = ShrinkSourceLocation( ev.lckloc ); - lm.type = ev.type; - lm.timeAnnounce = TscTime( ev.time ); - lm.timeTerminate = 0; - lm.valid = true; - m_data.lockMap.emplace( ev.id, std::move( lm ) ); + auto lm = m_slab.AllocInit(); + lm->srcloc = ShrinkSourceLocation( ev.lckloc ); + lm->type = ev.type; + lm->timeAnnounce = TscTime( ev.time ); + lm->timeTerminate = 0; + lm->valid = true; + m_data.lockMap.emplace( ev.id, lm ); } else { - it->second.srcloc = ShrinkSourceLocation( ev.lckloc ); - assert( it->second.type == ev.type ); - it->second.timeAnnounce = TscTime( ev.time ); - it->second.valid = true; + it->second->srcloc = ShrinkSourceLocation( ev.lckloc ); + assert( it->second->type == ev.type ); + it->second->timeAnnounce = TscTime( ev.time ); + it->second->valid = true; } CheckSourceLocation( ev.lckloc ); } @@ -2786,17 +2791,17 @@ void Worker::ProcessLockTerminate( const QueueLockTerminate& ev ) auto it = m_data.lockMap.find( ev.id ); if( it == m_data.lockMap.end() ) { - LockMap lm; - lm.type = ev.type; - lm.timeAnnounce = 0; - lm.timeTerminate = TscTime( ev.time ); - lm.valid = false; - m_data.lockMap.emplace( ev.id, std::move( lm ) ); + auto lm = m_slab.AllocInit(); + lm->type = ev.type; + lm->timeAnnounce = 0; + lm->timeTerminate = TscTime( ev.time ); + lm->valid = false; + m_data.lockMap.emplace( ev.id, lm ); } else { - assert( it->second.type == ev.type ); - it->second.timeTerminate = TscTime( ev.time ); + assert( it->second->type == ev.type ); + it->second->timeTerminate = TscTime( ev.time ); } } @@ -2805,12 +2810,12 @@ void Worker::ProcessLockWait( const QueueLockWait& ev ) auto it = m_data.lockMap.find( ev.id ); if( it == m_data.lockMap.end() ) { - LockMap lm; - lm.timeAnnounce = 0; - lm.timeTerminate = 0; - lm.valid = false; - lm.type = ev.type; - it = m_data.lockMap.emplace( ev.id, std::move( lm ) ).first; + auto lm = m_slab.AllocInit(); + lm->timeAnnounce = 0; + lm->timeTerminate = 0; + lm->valid = false; + lm->type = ev.type; + it = m_data.lockMap.emplace( ev.id, lm ).first; } auto lev = ev.type == LockType::Lockable ? m_slab.Alloc() : m_slab.Alloc(); @@ -2818,13 +2823,14 @@ void Worker::ProcessLockWait( const QueueLockWait& ev ) lev->type = LockEvent::Type::Wait; lev->srcloc = 0; - InsertLockEvent( it->second, lev, ev.thread ); + InsertLockEvent( *it->second, lev, ev.thread ); } void Worker::ProcessLockObtain( const QueueLockObtain& ev ) { - assert( m_data.lockMap.find( ev.id ) != m_data.lockMap.end() ); - auto& lock = m_data.lockMap[ev.id]; + auto it = m_data.lockMap.find( ev.id ); + assert( it != m_data.lockMap.end() ); + auto& lock = *it->second; auto lev = lock.type == LockType::Lockable ? m_slab.Alloc() : m_slab.Alloc(); lev->time = TscTime( ev.time ); @@ -2836,8 +2842,9 @@ void Worker::ProcessLockObtain( const QueueLockObtain& ev ) void Worker::ProcessLockRelease( const QueueLockRelease& ev ) { - assert( m_data.lockMap.find( ev.id ) != m_data.lockMap.end() ); - auto& lock = m_data.lockMap[ev.id]; + auto it = m_data.lockMap.find( ev.id ); + assert( it != m_data.lockMap.end() ); + auto& lock = *it->second; auto lev = lock.type == LockType::Lockable ? m_slab.Alloc() : m_slab.Alloc(); lev->time = TscTime( ev.time ); @@ -2852,10 +2859,10 @@ void Worker::ProcessLockSharedWait( const QueueLockWait& ev ) auto it = m_data.lockMap.find( ev.id ); if( it == m_data.lockMap.end() ) { - LockMap lm; - lm.valid = false; - lm.type = ev.type; - it = m_data.lockMap.emplace( ev.id, std::move( lm ) ).first; + auto lm = m_slab.AllocInit(); + lm->valid = false; + lm->type = ev.type; + it = m_data.lockMap.emplace( ev.id, lm ).first; } assert( ev.type == LockType::SharedLockable ); @@ -2864,13 +2871,14 @@ void Worker::ProcessLockSharedWait( const QueueLockWait& ev ) lev->type = LockEvent::Type::WaitShared; lev->srcloc = 0; - InsertLockEvent( it->second, lev, ev.thread ); + InsertLockEvent( *it->second, lev, ev.thread ); } void Worker::ProcessLockSharedObtain( const QueueLockObtain& ev ) { - assert( m_data.lockMap.find( ev.id ) != m_data.lockMap.end() ); - auto& lock = m_data.lockMap[ev.id]; + auto it = m_data.lockMap.find( ev.id ); + assert( it != m_data.lockMap.end() ); + auto& lock = *it->second; assert( lock.type == LockType::SharedLockable ); auto lev = m_slab.Alloc(); @@ -2883,8 +2891,9 @@ void Worker::ProcessLockSharedObtain( const QueueLockObtain& ev ) void Worker::ProcessLockSharedRelease( const QueueLockRelease& ev ) { - assert( m_data.lockMap.find( ev.id ) != m_data.lockMap.end() ); - auto& lock = m_data.lockMap[ev.id]; + auto it = m_data.lockMap.find( ev.id ); + assert( it != m_data.lockMap.end() ); + auto& lock = *it->second; assert( lock.type == LockType::SharedLockable ); auto lev = m_slab.Alloc(); @@ -2900,7 +2909,7 @@ void Worker::ProcessLockMark( const QueueLockMark& ev ) CheckSourceLocation( ev.srcloc ); auto lit = m_data.lockMap.find( ev.id ); assert( lit != m_data.lockMap.end() ); - auto& lockmap = lit->second; + auto& lockmap = *lit->second; auto tid = lockmap.threadMap.find( ev.thread ); assert( tid != lockmap.threadMap.end() ); const auto thread = tid->second; @@ -3906,21 +3915,21 @@ void Worker::Write( FileWrite& f ) for( auto& v : m_data.lockMap ) { f.Write( &v.first, sizeof( v.first ) ); - f.Write( &v.second.srcloc, sizeof( v.second.srcloc ) ); - f.Write( &v.second.type, sizeof( v.second.type ) ); - f.Write( &v.second.valid, sizeof( v.second.valid ) ); - f.Write( &v.second.timeAnnounce, sizeof( v.second.timeAnnounce ) ); - f.Write( &v.second.timeTerminate, sizeof( v.second.timeTerminate ) ); - sz = v.second.threadList.size(); + f.Write( &v.second->srcloc, sizeof( v.second->srcloc ) ); + f.Write( &v.second->type, sizeof( v.second->type ) ); + f.Write( &v.second->valid, sizeof( v.second->valid ) ); + f.Write( &v.second->timeAnnounce, sizeof( v.second->timeAnnounce ) ); + f.Write( &v.second->timeTerminate, sizeof( v.second->timeTerminate ) ); + sz = v.second->threadList.size(); f.Write( &sz, sizeof( sz ) ); - for( auto& t : v.second.threadList ) + for( auto& t : v.second->threadList ) { f.Write( &t, sizeof( t ) ); } - int64_t refTime = v.second.timeAnnounce; - sz = v.second.timeline.size(); + int64_t refTime = v.second->timeAnnounce; + sz = v.second->timeline.size(); f.Write( &sz, sizeof( sz ) ); - for( auto& lev : v.second.timeline ) + for( auto& lev : v.second->timeline ) { WriteTimeOffset( f, refTime, lev->time ); f.Write( &lev->srcloc, sizeof( lev->srcloc ) ); diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 4847d0b7..97ea6cde 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -170,7 +169,7 @@ private: flat_hash_map callstackFrameMap; flat_hash_map revFrameMap; - std::map lockMap; + flat_hash_map> lockMap; flat_hash_map> threadMap; Vector threadExpand; @@ -260,7 +259,7 @@ public: int64_t GetFrameEnd( const FrameData& fd, size_t idx ) const; std::pair GetFrameRange( const FrameData& fd, int64_t from, int64_t to ); - const std::map& GetLockMap() const { return m_data.lockMap; } + const flat_hash_map>& GetLockMap() const { return m_data.lockMap; } const Vector& GetMessages() const { return m_data.messages; } const Vector& GetGpuData() const { return m_data.gpuData; } const Vector& GetPlots() const { return m_data.plots.Data(); }