From 06f34052a5cb51495a9842c0f72ebabc8076b738 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Tue, 19 Jun 2018 22:08:47 +0200 Subject: [PATCH] Have to track callstacks of both alloc and free. --- server/TracyEvent.hpp | 3 ++- server/TracyWorker.cpp | 24 ++++++++++++++++++------ server/TracyWorker.hpp | 1 + 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index 057ebdce..d1a83de8 100644 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -147,7 +147,8 @@ struct MemEvent uint64_t size; int64_t timeAlloc; int64_t timeFree; - uint32_t callstack; + uint32_t csAlloc; + uint32_t csFree; // All above is read/saved as-is. uint16_t threadAlloc; diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index f39174f3..87340d95 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -553,11 +553,12 @@ Worker::Worker( FileRead& f, EventType::Type eventMask ) if( fileVer <= FileVersion( 0, 3, 1 ) ) { f.Read( mem, sizeof( MemEvent::ptr ) + sizeof( MemEvent::size ) + sizeof( MemEvent::timeAlloc ) + sizeof( MemEvent::timeFree ) ); - mem->callstack = 0; + mem->csAlloc = 0; + mem->csFree = 0; } else { - f.Read( mem, sizeof( MemEvent::ptr ) + sizeof( MemEvent::size ) + sizeof( MemEvent::timeAlloc ) + sizeof( MemEvent::timeFree ) + sizeof( MemEvent::callstack ) ); + f.Read( mem, sizeof( MemEvent::ptr ) + sizeof( MemEvent::size ) + sizeof( MemEvent::timeAlloc ) + sizeof( MemEvent::timeFree ) + sizeof( MemEvent::csAlloc ) + sizeof( MemEvent::csFree ) ); } uint64_t t0, t1; @@ -611,7 +612,8 @@ Worker::Worker( FileRead& f, EventType::Type eventMask ) sizeof( MemEvent::size ) + sizeof( MemEvent::timeAlloc ) + sizeof( MemEvent::timeFree ) + - sizeof( MemEvent::callstack ) + + sizeof( MemEvent::csAlloc ) + + sizeof( MemEvent::csFree ) + sizeof( uint64_t ) + sizeof( uint64_t ) ) ); } @@ -2024,7 +2026,8 @@ void Worker::ProcessMemAlloc( const QueueMemAlloc& ev ) mem.threadAlloc = CompressThread( ev.thread ); mem.timeFree = -1; mem.threadFree = 0; - mem.callstack = 0; + mem.csAlloc = 0; + mem.csFree = 0; const auto low = m_data.memory.low; const auto high = m_data.memory.high; @@ -2057,12 +2060,14 @@ void Worker::ProcessMemAllocCallstack( const QueueMemAlloc& ev ) { m_lastMemActionCallstack = m_data.memory.data.size(); ProcessMemAlloc( ev ); + m_lastMemActionWasAlloc = true; } void Worker::ProcessMemFreeCallstack( const QueueMemFree& ev ) { ProcessMemFree( ev ); m_lastMemActionCallstack = m_data.memory.frees.back(); + m_lastMemActionWasAlloc = false; } void Worker::ProcessCallstackMemory( const QueueCallstackMemory& ev ) @@ -2071,7 +2076,14 @@ void Worker::ProcessCallstackMemory( const QueueCallstackMemory& ev ) assert( it != m_pendingCallstacks.end() ); auto& mem = m_data.memory.data[m_lastMemActionCallstack]; - mem.callstack = it->second; + if( m_lastMemActionWasAlloc ) + { + mem.csAlloc = it->second; + } + else + { + mem.csFree = it->second; + } m_pendingCallstacks.erase( it ); } @@ -2453,7 +2465,7 @@ void Worker::Write( FileWrite& f ) f.Write( &sz, sizeof( sz ) ); for( auto& mem : m_data.memory.data ) { - f.Write( &mem, sizeof( MemEvent::ptr ) + sizeof( MemEvent::size ) + sizeof( MemEvent::timeAlloc ) + sizeof( MemEvent::timeFree ) + sizeof( MemEvent::callstack ) ); + f.Write( &mem, sizeof( MemEvent::ptr ) + sizeof( MemEvent::size ) + sizeof( MemEvent::timeAlloc ) + sizeof( MemEvent::timeFree ) + sizeof( MemEvent::csAlloc ) + sizeof( MemEvent::csFree ) ); uint64_t t[2]; t[0] = DecompressThread( mem.threadAlloc ); t[1] = DecompressThread( mem.threadFree ); diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index e070c8a4..f0070a4f 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -307,6 +307,7 @@ private: uint32_t m_pendingSourceLocation; uint64_t m_lastMemActionCallstack; + bool m_lastMemActionWasAlloc; Slab<64*1024*1024> m_slab;