Pack time and source location in LockEvent.

This commit is contained in:
Bartosz Taudul 2019-08-15 20:39:16 +02:00
parent 2e31c26ae5
commit 5e20b3f28a
3 changed files with 83 additions and 57 deletions

View File

@ -120,8 +120,25 @@ struct LockEvent
ReleaseShared
};
int64_t time;
int16_t srcloc;
int64_t Time() const
{
return int64_t( _start_time ) >> 16;
}
void SetTime( int64_t time )
{
assert( time < ( 1ll << 47 ) );
_start_time = ( _start_time & 0xFFFF ) | ( time << 16 );
}
int16_t SrcLoc() const
{
return int16_t( _start_time & 0xFFFF );
}
void SetSrcLoc( int16_t srcloc )
{
_start_time = ( _start_time & 0xFFFFFFFFFFFF0000 ) | srcloc;
}
uint64_t _start_time;
uint8_t thread;
Type type;
};

View File

@ -2094,9 +2094,9 @@ void View::DrawZones()
auto lptr = lockmap.timeline.data();
auto eptr = lptr + lockmap.timeline.size() - 1;
while( lptr->ptr->thread != thread ) lptr++;
if( lptr->ptr->time < first ) first = lptr->ptr->time;
if( lptr->ptr->Time() < first ) first = lptr->ptr->Time();
while( eptr->ptr->thread != thread ) eptr--;
if( eptr->ptr->time > last ) last = eptr->ptr->time;
if( eptr->ptr->Time() > last ) last = eptr->ptr->Time();
}
if( last >= 0 )
@ -3254,11 +3254,11 @@ void View::DrawLockHeader( uint32_t id, const LockMap& lockmap, const SourceLoca
{
if( timeAnnounce == 0 )
{
timeAnnounce = lockmap.timeline.front().ptr->time;
timeAnnounce = lockmap.timeline.front().ptr->Time();
}
if( timeTerminate == 0 )
{
timeTerminate = lockmap.timeline.back().ptr->time;
timeTerminate = lockmap.timeline.back().ptr->Time();
}
}
const auto lockLen = timeTerminate - timeAnnounce;
@ -3364,8 +3364,8 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
const auto thread = it->second;
const auto threadBit = GetThreadBit( thread );
auto vbegin = std::lower_bound( tl.begin(), tl.end(), std::max( range.start, m_zvStart - delay ), [] ( const auto& l, const auto& r ) { return l.ptr->time < r; } );
const auto vend = std::lower_bound( vbegin, tl.end(), std::min( range.end, m_zvEnd + resolution ), [] ( const auto& l, const auto& r ) { return l.ptr->time < r; } );
auto vbegin = std::lower_bound( tl.begin(), tl.end(), std::max( range.start, m_zvStart - delay ), [] ( const auto& l, const auto& r ) { return l.ptr->Time() < r; } );
const auto vend = std::lower_bound( vbegin, tl.end(), std::min( range.end, m_zvEnd + resolution ), [] ( const auto& l, const auto& r ) { return l.ptr->Time() < r; } );
if( vbegin > tl.begin() ) vbegin--;
@ -3439,8 +3439,8 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
LockState drawState = state;
auto next = GetNextLockFunc( vbegin, vend, state, threadBit );
const auto t0 = vbegin->ptr->time;
int64_t t1 = next == tl.end() ? m_worker.GetLastTime() : next->ptr->time;
const auto t0 = vbegin->ptr->Time();
int64_t t1 = next == tl.end() ? m_worker.GetLastTime() : next->ptr->Time();
const auto px0 = std::max( pxend, ( t0 - m_zvStart ) * pxns );
auto tx0 = px0;
double px1 = ( t1 - m_zvStart ) * pxns;
@ -3464,7 +3464,7 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
}
drawState = CombineLockState( drawState, state );
condensed++;
const auto t2 = n == tl.end() ? m_worker.GetLastTime() : n->ptr->time;
const auto t2 = n == tl.end() ? m_worker.GetLastTime() : n->ptr->Time();
const auto px2 = ( t2 - m_zvStart ) * pxns;
if( px2 - px1 > MinVisSize ) break;
if( drawState != ns && px2 - px0 > MinVisSize && !( ns == LockState::Nothing || ns == LockState::HasLock ) ) break;
@ -3493,7 +3493,7 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
}
drawState = CombineLockState( drawState, state );
condensed++;
const auto t2 = n == tl.end() ? m_worker.GetLastTime() : n->ptr->time;
const auto t2 = n == tl.end() ? m_worker.GetLastTime() : n->ptr->Time();
const auto px2 = ( t2 - m_zvStart ) * pxns;
if( px2 - px1 > MinVisSize ) break;
if( drawState != ns && px2 - px0 > MinVisSize && ns != LockState::Nothing ) break;
@ -3548,7 +3548,7 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
b--;
}
b++;
highlight.begin = b->ptr->time;
highlight.begin = b->ptr->Time();
auto e = next;
while( e != tl.end() )
@ -3556,7 +3556,7 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
if( e->lockingThread != next->lockingThread )
{
highlight.id = v.first;
highlight.end = e->ptr->time;
highlight.end = e->ptr->Time();
highlight.thread = thread;
break;
}
@ -3577,9 +3577,9 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
{
if( it->ptr->thread == thread )
{
if( ( it->lockingThread == thread || IsThreadWaiting( it->waitList, threadBit ) ) && it->ptr->srcloc != 0 )
if( ( it->lockingThread == thread || IsThreadWaiting( it->waitList, threadBit ) ) && it->ptr->SrcLoc() != 0 )
{
markloc = it->ptr->srcloc;
markloc = it->ptr->SrcLoc();
break;
}
}
@ -3792,7 +3792,7 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
const auto cfilled = drawState == LockState::HasLock ? 0xFF228A22 : ( drawState == LockState::HasBlockingLock ? 0xFF228A8A : 0xFF2222BD );
draw->AddRectFilled( wpos + ImVec2( std::max( px0, -10.0 ), offset ), wpos + ImVec2( std::min( pxend, double( w + 10 ) ), offset + ty ), cfilled );
if( m_lockHighlight.thread != thread && ( drawState == LockState::HasBlockingLock ) != m_lockHighlight.blocked && next != tl.end() && m_lockHighlight.id == int64_t( v.first ) && m_lockHighlight.begin <= vbegin->ptr->time && m_lockHighlight.end >= next->ptr->time )
if( m_lockHighlight.thread != thread && ( drawState == LockState::HasBlockingLock ) != m_lockHighlight.blocked && next != tl.end() && m_lockHighlight.id == int64_t( v.first ) && m_lockHighlight.begin <= vbegin->ptr->Time() && m_lockHighlight.end >= next->ptr->Time() )
{
const auto t = uint8_t( ( sin( std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::system_clock::now().time_since_epoch() ).count() * 0.01 ) * 0.5 + 0.5 ) * 255 );
draw->AddRect( wpos + ImVec2( std::max( px0, -10.0 ), offset ), wpos + ImVec2( std::min( pxend, double( w + 10 ) ), offset + ty ), 0x00FFFFFF | ( t << 24 ), 0.f, -1, 2.f );
@ -9792,11 +9792,11 @@ void View::DrawLockInfoWindow()
{
if( timeAnnounce == 0 )
{
timeAnnounce = lock.timeline.front().ptr->time;
timeAnnounce = lock.timeline.front().ptr->Time();
}
if( timeTerminate == 0 )
{
timeTerminate = lock.timeline.back().ptr->time;
timeTerminate = lock.timeline.back().ptr->Time();
}
}
@ -9813,7 +9813,7 @@ void View::DrawLockInfoWindow()
{
if( v.lockCount == 0 )
{
holdTotalTime += v.ptr->time - holdStartTime;
holdTotalTime += v.ptr->Time() - holdStartTime;
holdState = false;
}
}
@ -9821,7 +9821,7 @@ void View::DrawLockInfoWindow()
{
if( v.lockCount != 0 )
{
holdStartTime = v.ptr->time;
holdStartTime = v.ptr->Time();
holdState = true;
}
}
@ -9829,7 +9829,7 @@ void View::DrawLockInfoWindow()
{
if( v.waitList == 0 )
{
waitTotalTime += v.ptr->time - waitStartTime;
waitTotalTime += v.ptr->Time() - waitStartTime;
waitState = false;
}
else
@ -9841,7 +9841,7 @@ void View::DrawLockInfoWindow()
{
if( v.waitList != 0 )
{
waitStartTime = v.ptr->time;
waitStartTime = v.ptr->Time();
waitState = true;
maxWaitingThreads = std::max<uint32_t>( maxWaitingThreads, TracyCountBits( v.waitList ) );
}

View File

@ -230,7 +230,7 @@ static tracy_force_inline int64_t ReadTimeOffset( FileRead& f, int64_t& refTime
static tracy_force_inline void UpdateLockRange( LockMap& lockmap, const LockEvent& ev )
{
const auto lt = ev.time;
const auto lt = ev.Time();
auto& range = lockmap.range[ev.thread];
if( range.start > lt ) range.start = lt;
if( range.end < lt ) range.end = lt;
@ -646,8 +646,11 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
for( uint64_t i=0; i<tsz; i++ )
{
auto lev = m_slab.Alloc<LockEvent>();
lev->time = ReadTimeOffset( f, refTime );
f.Read( &lev->srcloc, sizeof( LockEvent::srcloc ) + sizeof( LockEvent::thread ) + sizeof( LockEvent::type ) );
lev->SetTime( ReadTimeOffset( f, refTime ) );
int16_t srcloc;
f.Read( srcloc );
lev->SetSrcLoc( srcloc );
f.Read( &lev->thread, sizeof( LockEvent::thread ) + sizeof( LockEvent::type ) );
*ptr++ = { lev };
UpdateLockRange( lockmap, *lev );
}
@ -657,8 +660,11 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
for( uint64_t i=0; i<tsz; i++ )
{
auto lev = m_slab.Alloc<LockEventShared>();
lev->time = ReadTimeOffset( f, refTime );
f.Read( &lev->srcloc, sizeof( LockEventShared::srcloc ) + sizeof( LockEventShared::thread ) + sizeof( LockEventShared::type ) );
lev->SetTime( ReadTimeOffset( f, refTime ) );
int16_t srcloc;
f.Read( srcloc );
lev->SetSrcLoc( srcloc );
f.Read( &lev->thread, sizeof( LockEventShared::thread ) + sizeof( LockEventShared::type ) );
*ptr++ = { lev };
UpdateLockRange( lockmap, *lev );
}
@ -672,10 +678,10 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
for( uint64_t i=0; i<tsz; i++ )
{
auto lev = m_slab.Alloc<LockEvent>();
lev->time = ReadTimeOffset( f, refTime );
lev->SetTime( ReadTimeOffset( f, refTime ) );
int32_t srcloc;
f.Read( srcloc );
lev->srcloc = int16_t( srcloc );
lev->SetSrcLoc( int16_t( srcloc ) );
f.Read( &lev->thread, sizeof( LockEvent::thread ) + sizeof( LockEvent::type ) );
*ptr++ = { lev };
UpdateLockRange( lockmap, *lev );
@ -686,10 +692,10 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
for( uint64_t i=0; i<tsz; i++ )
{
auto lev = m_slab.Alloc<LockEventShared>();
lev->time = ReadTimeOffset( f, refTime );
lev->SetTime( ReadTimeOffset( f, refTime ) );
int32_t srcloc;
f.Read( srcloc );
lev->srcloc = int16_t( srcloc );
lev->SetSrcLoc( int16_t( srcloc ) );
f.Read( &lev->thread, sizeof( LockEventShared::thread ) + sizeof( LockEventShared::type ) );
*ptr++ = { lev };
UpdateLockRange( lockmap, *lev );
@ -703,11 +709,12 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
for( uint64_t i=0; i<tsz; i++ )
{
auto lev = m_slab.Alloc<LockEvent>();
f.Read( lev->time );
lev->time -= m_data.baseTime;
int64_t time;
f.Read( time );
lev->SetTime( time - m_data.baseTime );
int32_t srcloc;
f.Read( srcloc );
lev->srcloc = int16_t( srcloc );
lev->SetSrcLoc( int16_t( srcloc ) );
f.Read( &lev->thread, sizeof( LockEvent::thread ) + sizeof( LockEvent::type ) );
*ptr++ = { lev };
UpdateLockRange( lockmap, *lev );
@ -718,11 +725,12 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
for( uint64_t i=0; i<tsz; i++ )
{
auto lev = m_slab.Alloc<LockEventShared>();
f.Read( lev->time );
lev->time -= m_data.baseTime;
int64_t time;
f.Read( time );
lev->SetTime( time - m_data.baseTime );
int32_t srcloc;
f.Read( srcloc );
lev->srcloc = int16_t( srcloc );
lev->SetSrcLoc( int16_t( srcloc ) );
f.Read( &lev->thread, sizeof( LockEventShared::thread ) + sizeof( LockEventShared::type ) );
*ptr++ = { lev };
UpdateLockRange( lockmap, *lev );
@ -758,11 +766,11 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
f.Read( tsz );
if( fileVer >= FileVersion( 0, 5, 2 ) )
{
f.Skip( tsz * ( sizeof( LockEvent::time ) + sizeof( LockEvent::type ) + sizeof( LockEvent::srcloc ) + sizeof( LockEvent::thread ) ) );
f.Skip( tsz * ( sizeof( int64_t ) + sizeof( LockEvent::type ) + sizeof( int16_t ) + sizeof( LockEvent::thread ) ) );
}
else
{
f.Skip( tsz * ( sizeof( LockEvent::time ) + sizeof( LockEvent::type ) + sizeof( int32_t ) + sizeof( LockEvent::thread ) ) );
f.Skip( tsz * ( sizeof( int64_t ) + sizeof( LockEvent::type ) + sizeof( int32_t ) + sizeof( LockEvent::thread ) ) );
}
}
}
@ -2297,7 +2305,7 @@ void Worker::NewZone( ZoneEvent* zone, uint64_t thread )
void Worker::InsertLockEvent( LockMap& lockmap, LockEvent* lev, uint64_t thread )
{
const auto lt = lev->time;
const auto lt = lev->Time();
m_data.lastTime = std::max( m_data.lastTime, lt );
NoticeThread( thread );
@ -2319,7 +2327,7 @@ void Worker::InsertLockEvent( LockMap& lockmap, LockEvent* lev, uint64_t thread
}
else
{
assert( timeline.back().ptr->time <= lt );
assert( timeline.back().ptr->Time() <= lt );
timeline.push_back_non_empty( { lev } );
UpdateLockCount( lockmap, timeline.size() - 1 );
}
@ -3283,9 +3291,9 @@ void Worker::ProcessLockWait( const QueueLockWait& ev )
}
auto lev = ev.type == LockType::Lockable ? m_slab.Alloc<LockEvent>() : m_slab.Alloc<LockEventShared>();
lev->time = TscTime( ev.time - m_data.baseTime );
lev->SetTime( TscTime( ev.time - m_data.baseTime ) );
lev->SetSrcLoc( 0 );
lev->type = LockEvent::Type::Wait;
lev->srcloc = 0;
InsertLockEvent( *it->second, lev, ev.thread );
}
@ -3297,9 +3305,9 @@ void Worker::ProcessLockObtain( const QueueLockObtain& ev )
auto& lock = *it->second;
auto lev = lock.type == LockType::Lockable ? m_slab.Alloc<LockEvent>() : m_slab.Alloc<LockEventShared>();
lev->time = TscTime( ev.time - m_data.baseTime );
lev->SetTime( TscTime( ev.time - m_data.baseTime ) );
lev->SetSrcLoc( 0 );
lev->type = LockEvent::Type::Obtain;
lev->srcloc = 0;
InsertLockEvent( lock, lev, ev.thread );
}
@ -3311,9 +3319,9 @@ void Worker::ProcessLockRelease( const QueueLockRelease& ev )
auto& lock = *it->second;
auto lev = lock.type == LockType::Lockable ? m_slab.Alloc<LockEvent>() : m_slab.Alloc<LockEventShared>();
lev->time = TscTime( ev.time - m_data.baseTime );
lev->SetTime( TscTime( ev.time - m_data.baseTime ) );
lev->SetSrcLoc( 0 );
lev->type = LockEvent::Type::Release;
lev->srcloc = 0;
InsertLockEvent( lock, lev, ev.thread );
}
@ -3332,9 +3340,9 @@ void Worker::ProcessLockSharedWait( const QueueLockWait& ev )
assert( ev.type == LockType::SharedLockable );
auto lev = m_slab.Alloc<LockEventShared>();
lev->time = TscTime( ev.time - m_data.baseTime );
lev->SetTime( TscTime( ev.time - m_data.baseTime ) );
lev->SetSrcLoc( 0 );
lev->type = LockEvent::Type::WaitShared;
lev->srcloc = 0;
InsertLockEvent( *it->second, lev, ev.thread );
}
@ -3347,9 +3355,9 @@ void Worker::ProcessLockSharedObtain( const QueueLockObtain& ev )
assert( lock.type == LockType::SharedLockable );
auto lev = m_slab.Alloc<LockEventShared>();
lev->time = TscTime( ev.time - m_data.baseTime );
lev->SetTime( TscTime( ev.time - m_data.baseTime ) );
lev->SetSrcLoc( 0 );
lev->type = LockEvent::Type::ObtainShared;
lev->srcloc = 0;
InsertLockEvent( lock, lev, ev.thread );
}
@ -3362,9 +3370,9 @@ void Worker::ProcessLockSharedRelease( const QueueLockRelease& ev )
assert( lock.type == LockType::SharedLockable );
auto lev = m_slab.Alloc<LockEventShared>();
lev->time = TscTime( ev.time - m_data.baseTime );
lev->SetTime( TscTime( ev.time - m_data.baseTime ) );
lev->SetSrcLoc( 0 );
lev->type = LockEvent::Type::ReleaseShared;
lev->srcloc = 0;
InsertLockEvent( lock, lev, ev.thread );
}
@ -3390,7 +3398,7 @@ void Worker::ProcessLockMark( const QueueLockMark& ev )
case LockEvent::Type::ObtainShared:
case LockEvent::Type::Wait:
case LockEvent::Type::WaitShared:
it->ptr->srcloc = ShrinkSourceLocation( ev.srcloc );
it->ptr->SetSrcLoc( ShrinkSourceLocation( ev.srcloc ) );
return;
default:
break;
@ -4553,8 +4561,9 @@ void Worker::Write( FileWrite& f )
f.Write( &sz, sizeof( sz ) );
for( auto& lev : v.second->timeline )
{
WriteTimeOffset( f, refTime, lev.ptr->time );
f.Write( &lev.ptr->srcloc, sizeof( lev.ptr->srcloc ) );
WriteTimeOffset( f, refTime, lev.ptr->Time() );
const int16_t srcloc = lev.ptr->SrcLoc();
f.Write( &srcloc, sizeof( srcloc ) );
f.Write( &lev.ptr->thread, sizeof( lev.ptr->thread ) );
f.Write( &lev.ptr->type, sizeof( lev.ptr->type ) );
}