mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-22 22:44:34 +00:00
Compress external threads. Saves 4 bytes per ctx switch.
Dropped support for loading context switch data in previous versions of traces.
This commit is contained in:
parent
21e7a4bb16
commit
1712431dfd
@ -261,20 +261,15 @@ enum { ContextSwitchDataSize = sizeof( ContextSwitchData ) };
|
||||
// might come after context switch data).
|
||||
struct ContextSwitchCpu
|
||||
{
|
||||
int64_t Start() const { return int64_t( _start_thread1 ) >> 16; }
|
||||
void SetStart( int64_t start ) { assert( start < ( 1ll << 47 ) ); _start_thread1 = ( _start_thread1 & 0xFFFF ) | uint64_t( start << 16 ); }
|
||||
int64_t End() const { return int64_t( _end_thread2 ) >> 16; }
|
||||
void SetEnd( int64_t end ) { assert( end < ( 1ll << 47 ) ); _end_thread2 = ( _end_thread2 & 0xFFFF ) | uint64_t( end << 16 ); }
|
||||
uint64_t Thread() const { return uint64_t( uint16_t( _start_thread1 ) ) | ( uint64_t( uint16_t( _end_thread2 ) ) << 16 ) | ( uint64_t( _thread3 ) << 32 ); }
|
||||
void SetThread( uint64_t thread ) {
|
||||
_start_thread1 = ( _start_thread1 & 0xFFFFFFFFFFFF0000 ) | uint16_t( thread );
|
||||
_end_thread2 = ( _end_thread2 & 0xFFFFFFFFFFFF0000 ) | uint16_t( thread >> 16 );
|
||||
_thread3 = uint32_t( thread >> 32 );
|
||||
}
|
||||
int64_t Start() const { return int64_t( _start_thread ) >> 16; }
|
||||
void SetStart( int64_t start ) { assert( start < ( 1ll << 47 ) ); _start_thread = ( _start_thread & 0xFFFF ) | uint64_t( start << 16 ); }
|
||||
int64_t End() const { return _end; }
|
||||
void SetEnd( int64_t end ) { assert( end < ( 1ll << 47 ) ); _end = end; }
|
||||
uint16_t Thread() const { return uint16_t( _start_thread ); }
|
||||
void SetThread( uint16_t thread ) { _start_thread = ( _start_thread & 0xFFFFFFFFFFFF0000 ) | thread; }
|
||||
|
||||
uint64_t _start_thread1;
|
||||
uint64_t _end_thread2;
|
||||
uint32_t _thread3;
|
||||
uint64_t _start_thread;
|
||||
uint64_t _end;
|
||||
};
|
||||
|
||||
enum { ContextSwitchCpuSize = sizeof( ContextSwitchCpu ) };
|
||||
|
@ -7,7 +7,7 @@ namespace Version
|
||||
{
|
||||
enum { Major = 0 };
|
||||
enum { Minor = 5 };
|
||||
enum { Patch = 5 };
|
||||
enum { Patch = 6 };
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3991,7 +3991,7 @@ int View::DrawCpuData( int offset, double pxns, const ImVec2& wpos, bool hover,
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto thread = it->Thread();
|
||||
const auto thread = m_worker.DecompressThreadExternal( it->Thread() );
|
||||
const auto local = m_worker.IsThreadLocal( thread );
|
||||
auto txt = local ? m_worker.GetThreadString( thread ) : m_worker.GetExternalName( thread ).first;
|
||||
bool untracked = false;
|
||||
|
@ -516,6 +516,10 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
|
||||
}
|
||||
|
||||
m_data.localThreadCompress.Load( f, fileVer );
|
||||
if( fileVer >= FileVersion( 0, 5, 6 ) )
|
||||
{
|
||||
m_data.externalThreadCompress.Load( f, fileVer );
|
||||
}
|
||||
|
||||
f.Read( sz );
|
||||
for( uint64_t i=0; i<sz; i++ )
|
||||
@ -1380,7 +1384,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
|
||||
}
|
||||
}
|
||||
|
||||
if( fileVer >= FileVersion( 0, 5, 1 ) )
|
||||
if( fileVer >= FileVersion( 0, 5, 6 ) )
|
||||
{
|
||||
s_loadProgress.subTotal.store( 0, std::memory_order_relaxed );
|
||||
s_loadProgress.progress.store( LoadProgress::ContextSwitches, std::memory_order_relaxed );
|
||||
@ -1399,21 +1403,11 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
|
||||
data->v.reserve_exact( csz, m_slab );
|
||||
int64_t runningTime = 0;
|
||||
int64_t refTime = 0;
|
||||
if( fileVer <= FileVersion( 0, 5, 2 ) ) refTime = -m_data.baseTime;
|
||||
auto ptr = data->v.data();
|
||||
for( uint64_t j=0; j<csz; j++ )
|
||||
{
|
||||
if( fileVer >= FileVersion( 0, 5, 4 ) )
|
||||
{
|
||||
ptr->wakeup = ReadTimeOffset( f, refTime );
|
||||
ptr->SetStart( ReadTimeOffset( f, refTime ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t start = ReadTimeOffset( f, refTime );
|
||||
ptr->wakeup = start;
|
||||
ptr->SetStart( start );
|
||||
}
|
||||
ptr->wakeup = ReadTimeOffset( f, refTime );
|
||||
ptr->SetStart( ReadTimeOffset( f, refTime ) );
|
||||
int64_t diff;
|
||||
f.Read( diff );
|
||||
if( diff > 0 ) runningTime += diff;
|
||||
@ -1447,10 +1441,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
|
||||
f.Skip( csz * sizeof( ContextSwitchData ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
@ -1468,7 +1459,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
|
||||
{
|
||||
ptr->SetStart( ReadTimeOffset( f, refTime ) );
|
||||
ptr->SetEnd( ReadTimeOffset( f, refTime ) );
|
||||
uint64_t thread;
|
||||
uint16_t thread;
|
||||
f.Read( thread );
|
||||
ptr->SetThread( thread );
|
||||
ptr++;
|
||||
@ -1485,10 +1476,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
|
||||
f.Skip( sizeof( uint64_t ) * 3 * sz );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( fileVer >= FileVersion( 0, 5, 5 ) )
|
||||
{
|
||||
f.Read( sz );
|
||||
for( uint64_t i=0; i<sz; i++ )
|
||||
{
|
||||
@ -4121,7 +4109,7 @@ void Worker::ProcessContextSwitch( const QueueContextSwitch& ev )
|
||||
if( !cs.empty() )
|
||||
{
|
||||
auto& cx = cs.back();
|
||||
assert( cx.Thread() == ev.oldThread );
|
||||
assert( m_data.externalThreadCompress.DecompressThread( cx.Thread() ) == ev.oldThread );
|
||||
cx.SetEnd( time );
|
||||
}
|
||||
}
|
||||
@ -4163,7 +4151,7 @@ void Worker::ProcessContextSwitch( const QueueContextSwitch& ev )
|
||||
auto& cx = cs.push_next();
|
||||
cx.SetStart( time );
|
||||
cx.SetEnd( -1 );
|
||||
cx.SetThread( ev.newThread );
|
||||
cx.SetThread( m_data.externalThreadCompress.CompressThread( ev.newThread ) );
|
||||
|
||||
CheckExternalName( ev.newThread );
|
||||
|
||||
@ -4786,6 +4774,7 @@ void Worker::Write( FileWrite& f )
|
||||
}
|
||||
|
||||
m_data.localThreadCompress.Save( f );
|
||||
m_data.externalThreadCompress.Save( f );
|
||||
|
||||
sz = m_data.sourceLocation.size();
|
||||
f.Write( &sz, sizeof( sz ) );
|
||||
@ -5037,7 +5026,7 @@ void Worker::Write( FileWrite& f )
|
||||
{
|
||||
WriteTimeOffset( f, refTime, cx.Start() );
|
||||
WriteTimeOffset( f, refTime, cx.End() );
|
||||
uint64_t thread = cx.Thread();
|
||||
uint16_t thread = cx.Thread();
|
||||
f.Write( &thread, sizeof( thread ) );
|
||||
}
|
||||
}
|
||||
|
@ -194,6 +194,7 @@ private:
|
||||
flat_hash_map<uint32_t, LockMap*, nohash<uint32_t>> lockMap;
|
||||
|
||||
ThreadCompress localThreadCompress;
|
||||
ThreadCompress externalThreadCompress;
|
||||
std::pair<uint64_t, ThreadData*> threadDataLast;
|
||||
|
||||
Vector<Vector<ZoneEvent*>> zoneChildren;
|
||||
@ -359,6 +360,7 @@ public:
|
||||
|
||||
tracy_force_inline uint16_t CompressThread( uint64_t thread ) { return m_data.localThreadCompress.CompressThread( thread ); }
|
||||
tracy_force_inline uint64_t DecompressThread( uint16_t thread ) const { return m_data.localThreadCompress.DecompressThread( thread ); }
|
||||
tracy_force_inline uint64_t DecompressThreadExternal( uint16_t thread ) const { return m_data.externalThreadCompress.DecompressThread( thread ); }
|
||||
|
||||
std::shared_mutex& GetMbpsDataLock() { return m_mbpsData.lock; }
|
||||
const std::vector<float>& GetMbpsData() const { return m_mbpsData.mbps; }
|
||||
|
Loading…
Reference in New Issue
Block a user