diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index a3e9af98..9688e56b 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -982,7 +982,7 @@ void Worker::DispatchProcess( const QueueItem& ev, char*& ptr ) AddSourceLocationPayload( ev.stringTransfer.ptr, ptr, sz ); break; case QueueType::CallstackPayload: - //AddCallstackPayload( ev.stringTransfer.ptr, ptr, sz ); + AddCallstackPayload( ev.stringTransfer.ptr, ptr, sz ); break; default: assert( false ); @@ -1265,6 +1265,36 @@ void Worker::AddCustomString( uint64_t ptr, char* str, size_t sz ) m_pendingCustomStrings.emplace( ptr, StoreString( str, sz ) ); } +void Worker::AddCallstackPayload( uint64_t ptr, char* _data, size_t sz ) +{ + assert( m_pendingCallstacks.find( ptr ) == m_pendingCallstacks.end() ); + + const auto memsize = sizeof( VarArray ) + sz; + auto mem = (char*)m_slab.AllocRaw( memsize ); + + auto data = (uint64_t*)mem; + memcpy( data, _data, sz ); + + auto arr = (VarArray*)( mem + sz ); + new(arr) VarArray( sz / sizeof( uint64_t ), data ); + + uint32_t idx; + auto it = m_data.callstackMap.find( arr ); + if( it == m_data.callstackMap.end() ) + { + idx = m_data.callstackPayload.size(); + m_data.callstackMap.emplace( arr, idx ); + m_data.callstackPayload.push_back( arr ); + } + else + { + idx = it->second; + m_slab.Unalloc( memsize ); + } + + m_pendingCallstacks.emplace( ptr, idx ); +} + void Worker::InsertPlot( PlotData* plot, int64_t time, double val ) { if( plot->data.empty() ) diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index b6c8cd00..e070c8a4 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -17,6 +17,7 @@ #include "tracy_flat_hash_map.hpp" #include "TracyEvent.hpp" #include "TracySlab.hpp" +#include "TracyVarArray.hpp" namespace tracy { @@ -98,6 +99,9 @@ class Worker bool sourceLocationZonesReady; #endif + flat_hash_map*, uint32_t, VarArrayHasherPOT, VarArrayComparator> callstackMap; + Vector*> callstackPayload; + std::map lockMap; flat_hash_map> threadMap; @@ -243,6 +247,8 @@ private: void AddThreadString( uint64_t id, char* str, size_t sz ); void AddCustomString( uint64_t ptr, char* str, size_t sz ); + void AddCallstackPayload( uint64_t ptr, char* data, size_t sz ); + void InsertPlot( PlotData* plot, int64_t time, double val ); void HandlePlotName( uint64_t name, char* str, size_t sz ); @@ -288,6 +294,7 @@ private: flat_hash_map> m_gpuCtxMap; flat_hash_map> m_pendingCustomStrings; flat_hash_map> m_pendingPlots; + flat_hash_map m_pendingCallstacks; flat_hash_map> m_plotMap; flat_hash_map m_plotRev; flat_hash_map> m_pendingSourceLocationPayload;