diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index 783a31b5..1018150a 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -622,6 +622,9 @@ int main( int argc, char** argv ) case tracy::LoadProgress::FrameImages: ImGui::TextUnformatted( "Frame images..." ); break; + case tracy::LoadProgress::ContextSwitches: + ImGui::TextUnformatted( "Context switches..." ); + break; default: assert( false ); break; diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 8acf780e..6e778e54 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -304,10 +304,14 @@ Worker::Worker( FileRead& f, EventType::Type eventMask ) { s_loadProgress.total.store( 8, std::memory_order_relaxed ); } - else + else if( fileVer <= FileVersion( 0, 5, 0 ) ) { s_loadProgress.total.store( 9, std::memory_order_relaxed ); } + else + { + s_loadProgress.total.store( 10, std::memory_order_relaxed ); + } s_loadProgress.subTotal.store( 0, std::memory_order_relaxed ); s_loadProgress.progress.store( LoadProgress::Initialization, std::memory_order_relaxed ); @@ -1141,6 +1145,50 @@ Worker::Worker( FileRead& f, EventType::Type eventMask ) } } + if( fileVer >= FileVersion( 0, 5, 1 ) ) + { + s_loadProgress.subTotal.store( 0, std::memory_order_relaxed ); + s_loadProgress.progress.store( LoadProgress::ContextSwitches, std::memory_order_relaxed ); + + if( eventMask & EventType::ContextSwitches ) + { + f.Read( sz ); + s_loadProgress.subTotal.store( sz, std::memory_order_relaxed ); + m_data.ctxSwitch.reserve( sz ); + for( uint64_t i=0; i(); + data->v.reserve_exact( csz, m_slab ); + int64_t refTime = 0; + auto ptr = data->v.data(); + for( uint64_t j=0; jstart = ReadTimeOffset( f, refTime ); + ptr->end = ReadTimeOffset( f, refTime ); + f.Read( &ptr->cpu, sizeof( ptr->cpu ) + sizeof( ptr->reason ) + sizeof( ptr->state ) ); + ptr++; + } + m_data.ctxSwitch.emplace( thread, data ); + } + } + else + { + f.Read( sz ); + s_loadProgress.subTotal.store( sz, std::memory_order_relaxed ); + for( uint64_t i=0; i( std::chrono::high_resolution_clock::now() - loadStart ).count(); @@ -4426,6 +4474,32 @@ void Worker::Write( FileWrite& f ) const auto image = UnpackFrameImage( *fi ); f.Write( image, fi->w * fi->h / 2 ); } + + // Only save context switches relevant to active threads. + std::vector>::const_iterator> ctxValid; + ctxValid.reserve( m_data.ctxSwitch.size() ); + for( auto it = m_data.ctxSwitch.begin(); it != m_data.ctxSwitch.end(); ++it ) + { + if( m_data.threadMap.find( it->first ) != m_data.threadMap.end() ) + { + ctxValid.emplace_back( it ); + } + } + sz = ctxValid.size(); + f.Write( &sz, sizeof( sz ) ); + for( auto& ctx : ctxValid ) + { + f.Write( &ctx->first, sizeof( ctx->first ) ); + sz = ctx->second->v.size(); + f.Write( &sz, sizeof( sz ) ); + int64_t refTime = 0; + for( auto& cs : ctx->second->v ) + { + WriteTimeOffset( f, refTime, cs.start ); + WriteTimeOffset( f, refTime, cs.end ); + f.Write( &cs.cpu, sizeof( cs.cpu ) + sizeof( cs.reason ) + sizeof( cs.state ) ); + } + } } void Worker::WriteTimeline( FileWrite& f, const Vector& vec, int64_t& refTime ) diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 359ae0b8..c45a51c6 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -30,14 +30,15 @@ namespace EventType { enum Type : uint32_t { - Locks = 1 << 0, - Messages = 1 << 1, - Plots = 1 << 2, - Memory = 1 << 3, - FrameImages = 1 << 4, + Locks = 1 << 0, + Messages = 1 << 1, + Plots = 1 << 2, + Memory = 1 << 3, + FrameImages = 1 << 4, + ContextSwitches = 1 << 5, - None = 0, - All = std::numeric_limits::max() + None = 0, + All = std::numeric_limits::max() }; } @@ -65,7 +66,8 @@ struct LoadProgress Plots, Memory, CallStacks, - FrameImages + FrameImages, + ContextSwitches }; LoadProgress() : total( 0 ), progress( 0 ), subTotal( 0 ), subProgress( 0 ) {}