From c8b5b9447d3131ba79ce0a1231f92f27255953ba Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 12 Jul 2018 01:35:32 +0200 Subject: [PATCH] Ignore dangling memory frees in on-demand mode. --- server/TracyWorker.cpp | 39 +++++++++++++++++++++++++++------------ server/TracyWorker.hpp | 2 +- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index ac29a6e6..2484cecc 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -2172,12 +2172,17 @@ void Worker::ProcessMemAlloc( const QueueMemAlloc& ev ) MemAllocChanged( time ); } -void Worker::ProcessMemFree( const QueueMemFree& ev ) +bool Worker::ProcessMemFree( const QueueMemFree& ev ) { const auto time = TscTime( ev.time ); auto it = m_data.memory.active.find( ev.ptr ); - assert( it != m_data.memory.active.end() ); + if( it == m_data.memory.active.end() ) + { + assert( m_onDemand ); + return false; + } + m_data.memory.frees.push_back( it->second ); auto& mem = m_data.memory.data[it->second]; mem.timeFree = time; @@ -2186,6 +2191,7 @@ void Worker::ProcessMemFree( const QueueMemFree& ev ) m_data.memory.active.erase( it ); MemAllocChanged( time ); + return true; } void Worker::ProcessMemAllocCallstack( const QueueMemAlloc& ev ) @@ -2197,9 +2203,15 @@ void Worker::ProcessMemAllocCallstack( const QueueMemAlloc& ev ) void Worker::ProcessMemFreeCallstack( const QueueMemFree& ev ) { - ProcessMemFree( ev ); - m_lastMemActionCallstack = m_data.memory.frees.back(); - m_lastMemActionWasAlloc = false; + if( ProcessMemFree( ev ) ) + { + m_lastMemActionCallstack = m_data.memory.frees.back(); + m_lastMemActionWasAlloc = false; + } + else + { + m_lastMemActionCallstack = std::numeric_limits::max(); + } } void Worker::ProcessCallstackMemory( const QueueCallstackMemory& ev ) @@ -2207,14 +2219,17 @@ void Worker::ProcessCallstackMemory( const QueueCallstackMemory& ev ) auto it = m_pendingCallstacks.find( ev.ptr ); assert( it != m_pendingCallstacks.end() ); - auto& mem = m_data.memory.data[m_lastMemActionCallstack]; - if( m_lastMemActionWasAlloc ) + if( m_lastMemActionCallstack != std::numeric_limits::max() ) { - mem.csAlloc = it->second; - } - else - { - mem.csFree = it->second; + auto& mem = m_data.memory.data[m_lastMemActionCallstack]; + if( m_lastMemActionWasAlloc ) + { + mem.csAlloc = it->second; + } + else + { + mem.csFree = it->second; + } } m_pendingCallstacks.erase( it ); diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index b85f7076..6f3bda87 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -243,7 +243,7 @@ private: tracy_force_inline void ProcessGpuZoneEnd( const QueueGpuZoneEnd& ev ); tracy_force_inline void ProcessGpuTime( const QueueGpuTime& ev ); tracy_force_inline void ProcessMemAlloc( const QueueMemAlloc& ev ); - tracy_force_inline void ProcessMemFree( const QueueMemFree& ev ); + tracy_force_inline bool ProcessMemFree( const QueueMemFree& ev ); tracy_force_inline void ProcessMemAllocCallstack( const QueueMemAlloc& ev ); tracy_force_inline void ProcessMemFreeCallstack( const QueueMemFree& ev ); tracy_force_inline void ProcessCallstackMemory( const QueueCallstackMemory& ev );