From 872367f068e94c09d2155597cb936cc4500e61f6 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 21 Oct 2024 18:11:08 +0200 Subject: [PATCH] Process memory pool discard events. --- server/TracyWorker.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++ server/TracyWorker.hpp | 2 ++ 2 files changed, 67 insertions(+) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index b22c7443..382f2281 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -4625,6 +4625,12 @@ bool Worker::Process( const QueueItem& ev ) case QueueType::MemFreeCallstackNamed: ProcessMemFreeCallstackNamed( ev.memFree ); break; + case QueueType::MemDiscard: + ProcessMemDiscard( ev.memDiscard ); + break; + case QueueType::MemDiscardCallstack: + ProcessMemDiscardCallstack( ev.memDiscard ); + break; case QueueType::CallstackSerial: ProcessCallstackSerial(); break; @@ -6154,6 +6160,65 @@ void Worker::ProcessMemFreeCallstackNamed( const QueueMemFree& ev ) m_serialNextCallstack = 0; } +void Worker::ProcessMemDiscard( const QueueMemDiscard& ev ) +{ + assert( m_memNamePayload == 0 ); + auto it = m_data.memNameMap.find( ev.name ); + if( it == m_data.memNameMap.end() ) return; + + const auto refTime = RefTime( m_refTimeSerial, ev.time ); + auto& memdata = *it->second; + + const auto time = TscTime( refTime ); + if( m_data.lastTime < time ) m_data.lastTime = time; + NoticeThread( ev.thread ); + const auto thread = CompressThread( ev.thread ); + + for( auto& v : memdata.active ) + { + memdata.frees.push_back( v.second ); + auto& mem = memdata.data[v.second]; + mem.SetTimeThreadFree( time, thread ); + memdata.usage -= mem.Size(); + MemAllocChanged( memdata, time ); + } + + memdata.active.clear(); + assert( memdata.usage == 0 ); +} + +void Worker::ProcessMemDiscardCallstack( const QueueMemDiscard& ev ) +{ + assert( m_serialNextCallstack != 0 ); + auto cs = m_serialNextCallstack; + m_serialNextCallstack = 0; + + assert( m_memNamePayload == 0 ); + auto it = m_data.memNameMap.find( ev.name ); + if( it == m_data.memNameMap.end() ) return; + + const auto refTime = RefTime( m_refTimeSerial, ev.time ); + auto& memdata = *it->second; + + const auto time = TscTime( refTime ); + if( m_data.lastTime < time ) m_data.lastTime = time; + NoticeThread( ev.thread ); + const auto thread = CompressThread( ev.thread ); + + for( auto& v : memdata.active ) + { + memdata.frees.push_back( v.second ); + auto& mem = memdata.data[v.second]; + mem.SetTimeThreadFree( time, thread ); + mem.csFree.SetVal( cs ); + memdata.usage -= mem.Size(); + MemAllocChanged( memdata, time ); + } + + memdata.active.clear(); + assert( memdata.usage == 0 ); +} + void Worker::ProcessCallstackSerial() { assert( m_pendingCallstackId != 0 ); diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 2da4010a..f0721041 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -745,10 +745,12 @@ private: tracy_force_inline MemEvent* ProcessMemAllocNamed( const QueueMemAlloc& ev ); tracy_force_inline MemEvent* ProcessMemFree( const QueueMemFree& ev ); tracy_force_inline MemEvent* ProcessMemFreeNamed( const QueueMemFree& ev ); + tracy_force_inline void ProcessMemDiscard( const QueueMemDiscard& ev ); tracy_force_inline void ProcessMemAllocCallstack( const QueueMemAlloc& ev ); tracy_force_inline void ProcessMemAllocCallstackNamed( const QueueMemAlloc& ev ); tracy_force_inline void ProcessMemFreeCallstack( const QueueMemFree& ev ); tracy_force_inline void ProcessMemFreeCallstackNamed( const QueueMemFree& ev ); + tracy_force_inline void ProcessMemDiscardCallstack( const QueueMemDiscard& ev ); tracy_force_inline void ProcessCallstackSerial(); tracy_force_inline void ProcessCallstack(); tracy_force_inline void ProcessCallstackSample( const QueueCallstackSample& ev );