From 8ef212c26e8eb2543de09840dfa2074d34d31c2b Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 13 Nov 2021 02:44:54 +0100 Subject: [PATCH] Determine if postponed callstacks are for context switches. Samples are processed only when new context switch data has been received. --- server/TracyWorker.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 93440df9..ae7bfd0d 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -4282,6 +4282,45 @@ void Worker::DoPostponedWork() if( !slz.second.zones.is_sorted() ) slz.second.zones.sort(); } } + + if( m_data.newContextSwitchesReceived ) + { + for( auto& td : m_data.threads ) + { + if( !td->postponedSamples.empty() ) + { + auto ctx = GetContextSwitchData( td->id ); + if( ctx ) + { +#ifdef NO_PARALLEL_SORT + pdqsort_branchless( td->postponedSamples.begin(), td->postponedSamples.end(), [] ( const auto& l, const auto& r ) { return l.time.Val() < r.time.Val(); } ); +#else + std::sort( std::execution::par_unseq, td->postponedSamples.begin(), td->postponedSamples.end(), [] ( const auto& l, const auto& r ) { return l.time.Val() < r.time.Val(); } ); +#endif + auto sit = td->postponedSamples.begin(); + auto cit = std::lower_bound( ctx->v.begin(), ctx->v.end(), sit->time.Val(), [] ( const auto& l, const auto& r ) { return (uint64_t)l.End() < (uint64_t)r; } ); + if( cit != ctx->v.end() ) + { + do + { + if( sit->time.Val() == cit->Start() ) + { + td->ctxSwitchSamples.push_back( *sit ); + } + else + { + ProcessCallstackSampleImplStats( *sit, *td ); + } + if( ++sit == td->postponedSamples.end() ) break; + cit = std::lower_bound( cit, ctx->v.end(), sit->time.Val(), [] ( const auto& l, const auto& r ) { return (uint64_t)l.End() < (uint64_t)r; } ); + } + while( cit != ctx->v.end() ); + } + } + } + } + m_data.newContextSwitchesReceived = false; + } #endif if( m_data.newSymbolsIndex >= 0 )