From 437771ea85b1f208e629ef69d4a406275e3469ef Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 22 Feb 2020 16:39:39 +0100 Subject: [PATCH] Process callstack sample data. --- server/TracyEvent.hpp | 10 ++++++++++ server/TracyWorker.cpp | 36 ++++++++++++++++++++++++++++++++++++ server/TracyWorker.hpp | 2 ++ 3 files changed, 48 insertions(+) diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index e64f58ce..a7dde8c6 100644 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -202,6 +202,15 @@ struct ZoneExtra enum { ZoneExtraSize = sizeof( ZoneExtra ) }; +struct SampleData +{ + Int48 time; + Int24 callstack; +}; + +enum { SampleDataSize = sizeof( SampleData ) }; + + struct LockEvent { enum class Type : uint8_t @@ -475,6 +484,7 @@ struct ThreadData #ifndef TRACY_NO_STATISTICS Vector childTimeStack; #endif + Vector samples; }; struct GpuCtxThreadData diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 29d7dbd4..564e09c4 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -3391,6 +3391,9 @@ bool Worker::Process( const QueueItem& ev ) case QueueType::CallstackAlloc: ProcessCallstackAlloc( ev.callstackAlloc ); break; + case QueueType::CallstackSample: + ProcessCallstackSample( ev.callstackSample ); + break; case QueueType::CallstackFrameSize: ProcessCallstackFrameSize( ev.callstackFrameSize ); m_serverQuerySpaceLeft++; @@ -4572,6 +4575,39 @@ void Worker::ProcessCallstackAlloc( const QueueCallstackAlloc& ev ) } } +void Worker::ProcessCallstackSample( const QueueCallstackSample& ev ) +{ + assert( m_pendingCallstackPtr == ev.ptr ); + m_pendingCallstackPtr = 0; + m_data.samplesCnt++; + + const auto refTime = m_refTimeCtx + ev.time; + m_refTimeCtx = refTime; + const auto t = TscTime( refTime - m_data.baseTime ); + + SampleData sd; + sd.time.SetVal( t ); + sd.callstack.SetVal( m_pendingCallstackId ); + + auto td = NoticeThread( ev.thread ); + if( td->samples.empty() ) + { + td->samples.push_back( sd ); + } + else + { + if( td->samples.back().time.Val() <= t ) + { + td->samples.push_back_non_empty( sd ); + } + else + { + const auto it = std::lower_bound( td->samples.begin(), td->samples.end(), t, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } ); + td->samples.insert( it, sd ); + } + } +} + void Worker::ProcessCallstackFrameSize( const QueueCallstackFrameSize& ev ) { assert( !m_callstackFrameStaging ); diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index fb0f53f3..1b78471f 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -190,6 +190,7 @@ private: MemData memory; uint64_t zonesCnt = 0; uint64_t gpuCnt = 0; + uint64_t samplesCnt = 0; int64_t baseTime = 0; int64_t lastTime = 0; uint64_t frameOffset = 0; @@ -511,6 +512,7 @@ private: tracy_force_inline void ProcessCallstackMemory( const QueueCallstackMemory& ev ); tracy_force_inline void ProcessCallstack( const QueueCallstack& ev ); tracy_force_inline void ProcessCallstackAlloc( const QueueCallstackAlloc& ev ); + tracy_force_inline void ProcessCallstackSample( const QueueCallstackSample& ev ); tracy_force_inline void ProcessCallstackFrameSize( const QueueCallstackFrameSize& ev ); tracy_force_inline void ProcessCallstackFrame( const QueueCallstackFrame& ev ); tracy_force_inline void ProcessCrashReport( const QueueCrashReport& ev );