From 708fdfea49bb79017e78748607e64f1413b9c0bf Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Tue, 15 Jan 2019 18:56:26 +0100 Subject: [PATCH] Track memory alloc+free matching failures. --- server/TracyWorker.cpp | 16 +++++++++++++--- server/TracyWorker.hpp | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 2ad35d75..4d09f8c4 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -2329,6 +2329,13 @@ void Worker::ZoneStackFailure( uint64_t thread, const ZoneEvent* ev ) m_failureData.srcloc = ev->srcloc; } +void Worker::MemFreeFailure( uint64_t thread ) +{ + m_failure = Failure::MemFree; + m_failureData.thread = thread; + m_failureData.srcloc = 0; +} + void Worker::ProcessZoneValidation( const QueueZoneValidation& ev ) { auto td = NoticeThread( ev.thread ); @@ -2386,7 +2393,6 @@ void Worker::ProcessFrameMarkEnd( const QueueFrameMark& ev ) const auto time = TscTime( ev.time ); if( fd->frames.empty() ) { - // TODO: add failure state assert( m_onDemand ); return; } @@ -2833,7 +2839,10 @@ bool Worker::ProcessMemFree( const QueueMemFree& ev ) auto it = m_data.memory.active.find( ev.ptr ); if( it == m_data.memory.active.end() ) { - assert( m_onDemand ); + if( !m_onDemand ) + { + MemFreeFailure( ev.thread ); + } return false; } @@ -3645,7 +3654,8 @@ void Worker::WriteTimeline( FileWrite& f, const Vector& vec, int64_t& static const char* s_failureReasons[] = { "", - "Invalid order of zone begin and end events." + "Invalid order of zone begin and end events.", + "Memory free event without a matching allocation." }; static_assert( sizeof( s_failureReasons ) / sizeof( *s_failureReasons ) == (int)Worker::Failure::NUM_FAILURES, "Missing failure reason description." ); diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 5eb4ae01..b503d409 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -181,6 +181,7 @@ public: { None, ZoneStack, + MemFree, NUM_FAILURES }; @@ -334,6 +335,7 @@ private: tracy_force_inline void ProcessGpuZoneBeginImpl( GpuEvent* zone, const QueueGpuZoneBegin& ev ); void ZoneStackFailure( uint64_t thread, const ZoneEvent* ev ); + void MemFreeFailure( uint64_t thread ); tracy_force_inline void CheckSourceLocation( uint64_t ptr ); void NewSourceLocation( uint64_t ptr );