From 5ccf3699196e576b44cd3e54dc845763846d7c0b Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 10 Oct 2021 16:14:17 +0200 Subject: [PATCH] Implement callstack serialization. --- TracyLua.hpp | 4 ++-- client/TracyProfiler.cpp | 28 ++++++++++++++++++++++++++-- client/TracyProfiler.hpp | 4 ++-- common/TracyQueue.hpp | 12 ++++++++++++ 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/TracyLua.hpp b/TracyLua.hpp index 54e0097d..c9a64313 100644 --- a/TracyLua.hpp +++ b/TracyLua.hpp @@ -182,10 +182,10 @@ static tracy_force_inline void SendLuaCallstack( lua_State* L, uint32_t depth ) } assert( dst - ptr == spaceNeeded + 2 ); - TracyLfqPrepare( QueueType::CallstackAlloc ); + TracyQueuePrepare( QueueType::CallstackAlloc ); MemWrite( &item->callstackAllocFat.ptr, (uint64_t)ptr ); MemWrite( &item->callstackAllocFat.nativePtr, (uint64_t)Callstack( depth ) ); - TracyLfqCommit; + TracyQueueCommit( callstackAllocFatThread ); } static inline int LuaZoneBeginS( lua_State* L ) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 07588d4b..5e164cbf 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -2448,6 +2448,29 @@ Profiler::DequeueStatus Profiler::DequeueSerial() tracy_free_fast( (void*)ptr ); break; } + case QueueType::Callstack: + { + ThreadCtxCheckSerial( callstackFatThread ); + ptr = MemRead( &item->callstackFat.ptr ); + SendCallstackPayload( ptr ); + tracy_free_fast( (void*)ptr ); + break; + } + case QueueType::CallstackAlloc: + { + ThreadCtxCheckSerial( callstackAllocFatThread ); + ptr = MemRead( &item->callstackAllocFat.nativePtr ); + if( ptr != 0 ) + { + CutCallstack( (void*)ptr, "lua_pcall" ); + SendCallstackPayload( ptr ); + tracy_free_fast( (void*)ptr ); + } + ptr = MemRead( &item->callstackAllocFat.ptr ); + SendCallstackAlloc( ptr ); + tracy_free_fast( (void*)ptr ); + break; + } #endif default: assert( false ); @@ -3141,11 +3164,12 @@ void Profiler::ReportTopology() void Profiler::SendCallstack( int depth, const char* skipBefore ) { #ifdef TRACY_HAS_CALLSTACK - TracyLfqPrepare( QueueType::Callstack ); auto ptr = Callstack( depth ); CutCallstack( ptr, skipBefore ); + + TracyQueuePrepare( QueueType::Callstack ); MemWrite( &item->callstackFat.ptr, (uint64_t)ptr ); - TracyLfqCommit; + TracyQueueCommit( callstackFatThread ); #endif } diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 26f146b3..c2f201b1 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -548,9 +548,9 @@ public: { #ifdef TRACY_HAS_CALLSTACK auto ptr = Callstack( depth ); - TracyLfqPrepare( QueueType::Callstack ); + TracyQueuePrepare( QueueType::Callstack ); MemWrite( &item->callstackFat.ptr, (uint64_t)ptr ); - TracyLfqCommit; + TracyQueueCommit( callstackFatThread ); #endif } diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index b6f24013..629292e8 100644 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -453,12 +453,22 @@ struct QueueCallstackFat uint64_t ptr; }; +struct QueueCallstackFatThread : public QueueCallstackFat +{ + uint32_t thread; +}; + struct QueueCallstackAllocFat { uint64_t ptr; uint64_t nativePtr; }; +struct QueueCallstackAllocFatThread : public QueueCallstackAllocFat +{ + uint32_t thread; +}; + struct QueueCallstackSample { int64_t time; @@ -633,7 +643,9 @@ struct QueueItem QueueMemFree memFree; QueueMemNamePayload memName; QueueCallstackFat callstackFat; + QueueCallstackFatThread callstackFatThread; QueueCallstackAllocFat callstackAllocFat; + QueueCallstackAllocFatThread callstackAllocFatThread; QueueCallstackSample callstackSample; QueueCallstackSampleFat callstackSampleFat; QueueCallstackFrameSize callstackFrameSize;