mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-26 16:04: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).
|
// might come after context switch data).
|
||||||
struct ContextSwitchCpu
|
struct ContextSwitchCpu
|
||||||
{
|
{
|
||||||
int64_t Start() const { return int64_t( _start_thread1 ) >> 16; }
|
int64_t Start() const { return int64_t( _start_thread ) >> 16; }
|
||||||
void SetStart( int64_t start ) { assert( start < ( 1ll << 47 ) ); _start_thread1 = ( _start_thread1 & 0xFFFF ) | uint64_t( start << 16 ); }
|
void SetStart( int64_t start ) { assert( start < ( 1ll << 47 ) ); _start_thread = ( _start_thread & 0xFFFF ) | uint64_t( start << 16 ); }
|
||||||
int64_t End() const { return int64_t( _end_thread2 ) >> 16; }
|
int64_t End() const { return _end; }
|
||||||
void SetEnd( int64_t end ) { assert( end < ( 1ll << 47 ) ); _end_thread2 = ( _end_thread2 & 0xFFFF ) | uint64_t( end << 16 ); }
|
void SetEnd( int64_t end ) { assert( end < ( 1ll << 47 ) ); _end = end; }
|
||||||
uint64_t Thread() const { return uint64_t( uint16_t( _start_thread1 ) ) | ( uint64_t( uint16_t( _end_thread2 ) ) << 16 ) | ( uint64_t( _thread3 ) << 32 ); }
|
uint16_t Thread() const { return uint16_t( _start_thread ); }
|
||||||
void SetThread( uint64_t thread ) {
|
void SetThread( uint16_t thread ) { _start_thread = ( _start_thread & 0xFFFFFFFFFFFF0000 ) | thread; }
|
||||||
_start_thread1 = ( _start_thread1 & 0xFFFFFFFFFFFF0000 ) | uint16_t( thread );
|
|
||||||
_end_thread2 = ( _end_thread2 & 0xFFFFFFFFFFFF0000 ) | uint16_t( thread >> 16 );
|
|
||||||
_thread3 = uint32_t( thread >> 32 );
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t _start_thread1;
|
uint64_t _start_thread;
|
||||||
uint64_t _end_thread2;
|
uint64_t _end;
|
||||||
uint32_t _thread3;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { ContextSwitchCpuSize = sizeof( ContextSwitchCpu ) };
|
enum { ContextSwitchCpuSize = sizeof( ContextSwitchCpu ) };
|
||||||
|
@ -7,7 +7,7 @@ namespace Version
|
|||||||
{
|
{
|
||||||
enum { Major = 0 };
|
enum { Major = 0 };
|
||||||
enum { Minor = 5 };
|
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
|
else
|
||||||
{
|
{
|
||||||
const auto thread = it->Thread();
|
const auto thread = m_worker.DecompressThreadExternal( it->Thread() );
|
||||||
const auto local = m_worker.IsThreadLocal( thread );
|
const auto local = m_worker.IsThreadLocal( thread );
|
||||||
auto txt = local ? m_worker.GetThreadString( thread ) : m_worker.GetExternalName( thread ).first;
|
auto txt = local ? m_worker.GetThreadString( thread ) : m_worker.GetExternalName( thread ).first;
|
||||||
bool untracked = false;
|
bool untracked = false;
|
||||||
|
@ -516,6 +516,10 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_data.localThreadCompress.Load( f, fileVer );
|
m_data.localThreadCompress.Load( f, fileVer );
|
||||||
|
if( fileVer >= FileVersion( 0, 5, 6 ) )
|
||||||
|
{
|
||||||
|
m_data.externalThreadCompress.Load( f, fileVer );
|
||||||
|
}
|
||||||
|
|
||||||
f.Read( sz );
|
f.Read( sz );
|
||||||
for( uint64_t i=0; i<sz; i++ )
|
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.subTotal.store( 0, std::memory_order_relaxed );
|
||||||
s_loadProgress.progress.store( LoadProgress::ContextSwitches, 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 );
|
data->v.reserve_exact( csz, m_slab );
|
||||||
int64_t runningTime = 0;
|
int64_t runningTime = 0;
|
||||||
int64_t refTime = 0;
|
int64_t refTime = 0;
|
||||||
if( fileVer <= FileVersion( 0, 5, 2 ) ) refTime = -m_data.baseTime;
|
|
||||||
auto ptr = data->v.data();
|
auto ptr = data->v.data();
|
||||||
for( uint64_t j=0; j<csz; j++ )
|
for( uint64_t j=0; j<csz; j++ )
|
||||||
{
|
{
|
||||||
if( fileVer >= FileVersion( 0, 5, 4 ) )
|
ptr->wakeup = ReadTimeOffset( f, refTime );
|
||||||
{
|
ptr->SetStart( ReadTimeOffset( f, refTime ) );
|
||||||
ptr->wakeup = ReadTimeOffset( f, refTime );
|
|
||||||
ptr->SetStart( ReadTimeOffset( f, refTime ) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int64_t start = ReadTimeOffset( f, refTime );
|
|
||||||
ptr->wakeup = start;
|
|
||||||
ptr->SetStart( start );
|
|
||||||
}
|
|
||||||
int64_t diff;
|
int64_t diff;
|
||||||
f.Read( diff );
|
f.Read( diff );
|
||||||
if( diff > 0 ) runningTime += diff;
|
if( diff > 0 ) runningTime += diff;
|
||||||
@ -1447,10 +1441,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
|
|||||||
f.Skip( csz * sizeof( ContextSwitchData ) );
|
f.Skip( csz * sizeof( ContextSwitchData ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if( fileVer >= FileVersion( 0, 5, 3 ) )
|
|
||||||
{
|
|
||||||
s_loadProgress.subTotal.store( 0, std::memory_order_relaxed );
|
s_loadProgress.subTotal.store( 0, std::memory_order_relaxed );
|
||||||
s_loadProgress.progress.store( LoadProgress::ContextSwitchesPerCpu, std::memory_order_relaxed );
|
s_loadProgress.progress.store( LoadProgress::ContextSwitchesPerCpu, std::memory_order_relaxed );
|
||||||
f.Read( sz );
|
f.Read( sz );
|
||||||
@ -1468,7 +1459,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
|
|||||||
{
|
{
|
||||||
ptr->SetStart( ReadTimeOffset( f, refTime ) );
|
ptr->SetStart( ReadTimeOffset( f, refTime ) );
|
||||||
ptr->SetEnd( ReadTimeOffset( f, refTime ) );
|
ptr->SetEnd( ReadTimeOffset( f, refTime ) );
|
||||||
uint64_t thread;
|
uint16_t thread;
|
||||||
f.Read( thread );
|
f.Read( thread );
|
||||||
ptr->SetThread( thread );
|
ptr->SetThread( thread );
|
||||||
ptr++;
|
ptr++;
|
||||||
@ -1485,10 +1476,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
|
|||||||
f.Skip( sizeof( uint64_t ) * 3 * sz );
|
f.Skip( sizeof( uint64_t ) * 3 * sz );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if( fileVer >= FileVersion( 0, 5, 5 ) )
|
|
||||||
{
|
|
||||||
f.Read( sz );
|
f.Read( sz );
|
||||||
for( uint64_t i=0; i<sz; i++ )
|
for( uint64_t i=0; i<sz; i++ )
|
||||||
{
|
{
|
||||||
@ -4121,7 +4109,7 @@ void Worker::ProcessContextSwitch( const QueueContextSwitch& ev )
|
|||||||
if( !cs.empty() )
|
if( !cs.empty() )
|
||||||
{
|
{
|
||||||
auto& cx = cs.back();
|
auto& cx = cs.back();
|
||||||
assert( cx.Thread() == ev.oldThread );
|
assert( m_data.externalThreadCompress.DecompressThread( cx.Thread() ) == ev.oldThread );
|
||||||
cx.SetEnd( time );
|
cx.SetEnd( time );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4163,7 +4151,7 @@ void Worker::ProcessContextSwitch( const QueueContextSwitch& ev )
|
|||||||
auto& cx = cs.push_next();
|
auto& cx = cs.push_next();
|
||||||
cx.SetStart( time );
|
cx.SetStart( time );
|
||||||
cx.SetEnd( -1 );
|
cx.SetEnd( -1 );
|
||||||
cx.SetThread( ev.newThread );
|
cx.SetThread( m_data.externalThreadCompress.CompressThread( ev.newThread ) );
|
||||||
|
|
||||||
CheckExternalName( ev.newThread );
|
CheckExternalName( ev.newThread );
|
||||||
|
|
||||||
@ -4786,6 +4774,7 @@ void Worker::Write( FileWrite& f )
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_data.localThreadCompress.Save( f );
|
m_data.localThreadCompress.Save( f );
|
||||||
|
m_data.externalThreadCompress.Save( f );
|
||||||
|
|
||||||
sz = m_data.sourceLocation.size();
|
sz = m_data.sourceLocation.size();
|
||||||
f.Write( &sz, sizeof( sz ) );
|
f.Write( &sz, sizeof( sz ) );
|
||||||
@ -5037,7 +5026,7 @@ void Worker::Write( FileWrite& f )
|
|||||||
{
|
{
|
||||||
WriteTimeOffset( f, refTime, cx.Start() );
|
WriteTimeOffset( f, refTime, cx.Start() );
|
||||||
WriteTimeOffset( f, refTime, cx.End() );
|
WriteTimeOffset( f, refTime, cx.End() );
|
||||||
uint64_t thread = cx.Thread();
|
uint16_t thread = cx.Thread();
|
||||||
f.Write( &thread, sizeof( thread ) );
|
f.Write( &thread, sizeof( thread ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,6 +194,7 @@ private:
|
|||||||
flat_hash_map<uint32_t, LockMap*, nohash<uint32_t>> lockMap;
|
flat_hash_map<uint32_t, LockMap*, nohash<uint32_t>> lockMap;
|
||||||
|
|
||||||
ThreadCompress localThreadCompress;
|
ThreadCompress localThreadCompress;
|
||||||
|
ThreadCompress externalThreadCompress;
|
||||||
std::pair<uint64_t, ThreadData*> threadDataLast;
|
std::pair<uint64_t, ThreadData*> threadDataLast;
|
||||||
|
|
||||||
Vector<Vector<ZoneEvent*>> zoneChildren;
|
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 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 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; }
|
std::shared_mutex& GetMbpsDataLock() { return m_mbpsData.lock; }
|
||||||
const std::vector<float>& GetMbpsData() const { return m_mbpsData.mbps; }
|
const std::vector<float>& GetMbpsData() const { return m_mbpsData.mbps; }
|
||||||
|
Loading…
Reference in New Issue
Block a user