Save/load per-cpu context switches.

This commit is contained in:
Bartosz Taudul 2019-08-16 16:51:02 +02:00
parent 8bc4258e29
commit cef7e4b8d0
4 changed files with 67 additions and 3 deletions

View File

@ -626,6 +626,9 @@ int main( int argc, char** argv )
case tracy::LoadProgress::ContextSwitches: case tracy::LoadProgress::ContextSwitches:
ImGui::TextUnformatted( "Context switches..." ); ImGui::TextUnformatted( "Context switches..." );
break; break;
case tracy::LoadProgress::ContextSwitchesPerCpu:
ImGui::TextUnformatted( "CPU context switches..." );
break;
default: default:
assert( false ); assert( false );
break; break;

View File

@ -7,7 +7,7 @@ namespace Version
{ {
enum { Major = 0 }; enum { Major = 0 };
enum { Minor = 5 }; enum { Minor = 5 };
enum { Patch = 2 }; enum { Patch = 3 };
} }
} }

View File

@ -307,10 +307,14 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
{ {
s_loadProgress.total.store( 9, std::memory_order_relaxed ); s_loadProgress.total.store( 9, std::memory_order_relaxed );
} }
else else if( fileVer <= FileVersion( 0, 5, 2 ) )
{ {
s_loadProgress.total.store( 10, std::memory_order_relaxed ); s_loadProgress.total.store( 10, std::memory_order_relaxed );
} }
else
{
s_loadProgress.total.store( 11, std::memory_order_relaxed );
}
s_loadProgress.subTotal.store( 0, std::memory_order_relaxed ); s_loadProgress.subTotal.store( 0, std::memory_order_relaxed );
s_loadProgress.progress.store( LoadProgress::Initialization, std::memory_order_relaxed ); s_loadProgress.progress.store( LoadProgress::Initialization, std::memory_order_relaxed );
@ -1429,6 +1433,44 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
} }
} }
if( fileVer >= FileVersion( 0, 5, 3 ) )
{
s_loadProgress.subTotal.store( 0, std::memory_order_relaxed );
s_loadProgress.progress.store( LoadProgress::ContextSwitchesPerCpu, std::memory_order_relaxed );
f.Read( sz );
s_loadProgress.subTotal.store( sz, std::memory_order_relaxed );
if( eventMask & EventType::ContextSwitches )
{
uint64_t cnt = 0;
for( int i=0; i<256; i++ )
{
int64_t refTime = 0;
f.Read( sz );
m_data.cpuData[i].cs.reserve_exact( sz, m_slab );
auto ptr = m_data.cpuData[i].cs.data();
for( uint64_t j=0; j<sz; j++ )
{
ptr->SetStart( ReadTimeOffset( f, refTime ) );
ptr->SetEnd( ReadTimeOffset( f, refTime ) );
uint64_t thread;
f.Read( thread );
ptr->SetThread( thread );
ptr++;
}
cnt += sz;
s_loadProgress.subProgress.store( cnt, std::memory_order_relaxed );
}
}
else
{
for( int i=0; i<256; i++ )
{
f.Read( sz );
f.Skip( sizeof( uint64_t ) * 3 * sz );
}
}
}
s_loadProgress.total.store( 0, std::memory_order_relaxed ); s_loadProgress.total.store( 0, std::memory_order_relaxed );
m_loadTime = std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now() - loadStart ).count(); m_loadTime = std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now() - loadStart ).count();
@ -4826,6 +4868,24 @@ void Worker::Write( FileWrite& f )
f.Write( &state, sizeof( state ) ); f.Write( &state, sizeof( state ) );
} }
} }
sz = GetContextSwitchPerCpuCount();
f.Write( &sz, sizeof( sz ) );
for( int i=0; i<256; i++ )
{
sz = m_data.cpuData[i].cs.size();
f.Write( &sz, sizeof( sz ) );
int64_t refTime = 0;
for( auto& cx : m_data.cpuData[i].cs )
{
WriteTimeOffset( f, refTime, cx.Start() );
WriteTimeOffset( f, refTime, cx.End() );
uint64_t thread = cx.Thread();
// Don't care about external thread identifiers
if( m_data.threadMap.find( thread ) == m_data.threadMap.end() ) thread = 0;
f.Write( &thread, sizeof( thread ) );
}
}
} }
void Worker::WriteTimeline( FileWrite& f, const Vector<ZoneEvent*>& vec, int64_t& refTime ) void Worker::WriteTimeline( FileWrite& f, const Vector<ZoneEvent*>& vec, int64_t& refTime )

View File

@ -67,7 +67,8 @@ struct LoadProgress
Memory, Memory,
CallStacks, CallStacks,
FrameImages, FrameImages,
ContextSwitches ContextSwitches,
ContextSwitchesPerCpu
}; };
LoadProgress() : total( 0 ), progress( 0 ), subTotal( 0 ), subProgress( 0 ) {} LoadProgress() : total( 0 ), progress( 0 ), subTotal( 0 ), subProgress( 0 ) {}