From b946c1d39ee198dbafce6b4d98044b462c691ae7 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 11 Nov 2019 00:04:45 +0100 Subject: [PATCH] Only enable magic fitted vectors in no-statistics builds. Source location zones pointer fixup is just too slow to be feasible. Note: no-statistics builds of the graphical profiler don't perform fixup of view-related pointers (e.g. zone info window zone pointer). This won't cause crashes, because the pointers are still valid, but the displayed data will be incorrect and potentially changing in time, as the pointer can be reused for completely other zone. Memory usage of ToyPathTracer data, in various scenarios: Capture + statistics: 7121 MB Load + statistics: 6057 MB Capture - statistics: 4876 MB Load - statistics: 4521 MB --- server/TracyWorker.cpp | 35 +++++++++++------------------------ server/TracyWorker.hpp | 4 +--- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 4cb59145..3aada30e 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -2834,16 +2834,8 @@ void Worker::NewZone( ZoneEvent* zone, uint64_t thread ) { m_data.zonesCnt++; - auto td = m_threadCtxData; - if( !td ) td = m_threadCtxData = NoticeThread( thread ); - #ifndef TRACY_NO_STATISTICS auto slz = GetSourceLocationZones( zone->SrcLoc() ); - if( !td->stack.empty() ) - { - assert( m_slzPointerMap.find( zone ) == m_slzPointerMap.end() ); - m_slzPointerMap.emplace( zone, slz->zones.size() ); - } auto& ztd = slz->zones.push_next(); ztd.SetZone( zone ); ztd.SetThread( CompressThread( thread ) ); @@ -2851,6 +2843,8 @@ void Worker::NewZone( ZoneEvent* zone, uint64_t thread ) CountZoneStatistics( zone ); #endif + auto td = m_threadCtxData; + if( !td ) td = m_threadCtxData = NoticeThread( thread ); td->count++; if( td->stack.empty() ) { @@ -3556,6 +3550,9 @@ void Worker::ProcessZoneBeginImpl( ZoneEvent* zone, const QueueZoneBegin& ev ) ZoneEvent* Worker::AllocZoneEvent() { ZoneEvent* ret; +#ifndef TRACY_NO_STATISTICS + ret = m_slab.Alloc(); +#else if( m_zoneEventPool.empty() ) { ret = m_slab.Alloc(); @@ -3564,6 +3561,7 @@ ZoneEvent* Worker::AllocZoneEvent() { ret = m_zoneEventPool.back_and_pop(); } +#endif memset( &ret->text, 0, sizeof( ZoneEvent::text ) + sizeof( ZoneEvent::callstack ) + sizeof( ZoneEvent::name ) ); return ret; } @@ -3653,6 +3651,10 @@ void Worker::ProcessZoneEnd( const QueueZoneEnd& ev ) if( sz <= 8 * 1024 ) { Vector> fitVec; +#ifndef TRACY_NO_STATISTICS + fitVec.reserve_exact( sz, m_slab ); + memcpy( fitVec.data(), childVec.data(), sz * sizeof( short_ptr ) ); +#else fitVec.set_magic(); auto& fv = *((Vector*)&fitVec); fv.reserve_exact( sz, m_slab ); @@ -3660,28 +3662,13 @@ void Worker::ProcessZoneEnd( const QueueZoneEnd& ev ) for( auto& ze : childVec ) { ZoneEvent* src = ze; -#ifndef TRACY_NO_STATISTICS - auto slz = GetSourceLocationZones( src->SrcLoc() ); - auto slzit = m_slzPointerMap.find( src ); - assert( slzit != m_slzPointerMap.end() ); - slz->zones[slzit->second].SetZone( dst ); - m_slzPointerMap.erase( slzit ); -#endif memcpy( dst++, src, sizeof( ZoneEvent ) ); m_zoneEventPool.push_back( src ); } +#endif fitVec.swap( childVec ); m_data.zoneVectorCache.push_back( std::move( fitVec ) ); } -#ifndef TRACY_NO_STATISTICS - else - { - for( auto& z : childVec ) - { - m_slzPointerMap.erase( z ); - } - } -#endif } #ifndef TRACY_NO_STATISTICS diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 112d02d9..f262ac24 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -702,10 +702,8 @@ private: std::mutex m_netWriteLock; std::condition_variable m_netWriteCv; +#ifdef TRACY_NO_STATISTICS Vector m_zoneEventPool; - -#ifndef TRACY_NO_STATISTICS - flat_hash_map> m_slzPointerMap; #endif };