1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Remove double indirection in GetNextLockEvent().

This commit is contained in:
Bartosz Taudul 2019-03-16 14:18:43 +01:00
parent 6db1a9ccd4
commit 7e6a8135df
3 changed files with 159 additions and 153 deletions

View File

@ -106,11 +106,6 @@ struct LockEvent
int32_t srcloc; int32_t srcloc;
uint8_t thread; uint8_t thread;
Type type; Type type;
// All above is read/saved as-is.
uint8_t lockingThread;
uint8_t lockCount;
uint64_t waitList;
}; };
struct LockEventShared : public LockEvent struct LockEventShared : public LockEvent
@ -119,11 +114,20 @@ struct LockEventShared : public LockEvent
uint64_t sharedList; uint64_t sharedList;
}; };
struct LockEventPtr
{
LockEvent* ptr;
uint8_t lockingThread;
uint8_t lockCount;
uint64_t waitList;
};
enum { LockEventSize = sizeof( LockEvent ) }; enum { LockEventSize = sizeof( LockEvent ) };
enum { LockEventSharedSize = sizeof( LockEventShared ) }; enum { LockEventSharedSize = sizeof( LockEventShared ) };
enum { LockEventPtrSize = sizeof( LockEventPtr ) };
enum { MaxLockThreads = sizeof( LockEvent::waitList ) * 8 }; enum { MaxLockThreads = sizeof( LockEventPtr::waitList ) * 8 };
static_assert( std::numeric_limits<decltype(LockEvent::lockCount)>::max() >= MaxLockThreads, "Not enough space for lock count." ); static_assert( std::numeric_limits<decltype(LockEventPtr::lockCount)>::max() >= MaxLockThreads, "Not enough space for lock count." );
struct GpuEvent struct GpuEvent
@ -259,7 +263,7 @@ struct LockMap
}; };
uint32_t srcloc; uint32_t srcloc;
Vector<LockEvent*> timeline; Vector<LockEventPtr> timeline;
flat_hash_map<uint64_t, uint8_t, nohash<uint64_t>> threadMap; flat_hash_map<uint64_t, uint8_t, nohash<uint64_t>> threadMap;
std::vector<uint64_t> threadList; std::vector<uint64_t> threadList;
LockType type; LockType type;

View File

@ -2179,10 +2179,10 @@ void View::DrawZones()
const auto thread = it->second; const auto thread = it->second;
auto lptr = lockmap.timeline.data(); auto lptr = lockmap.timeline.data();
auto eptr = lptr + lockmap.timeline.size() - 1; auto eptr = lptr + lockmap.timeline.size() - 1;
while( (*lptr)->thread != thread ) lptr++; while( lptr->ptr->thread != thread ) lptr++;
if( (*lptr)->time < first ) first = (*lptr)->time; if( lptr->ptr->time < first ) first = lptr->ptr->time;
while( (*eptr)->thread != thread ) eptr--; while( eptr->ptr->thread != thread ) eptr--;
if( (*eptr)->time > last ) last = (*eptr)->time; if( eptr->ptr->time > last ) last = eptr->ptr->time;
} }
if( last >= 0 ) if( last >= 0 )
@ -2806,7 +2806,7 @@ enum class LockState
WaitLock // red WaitLock // red
}; };
static Vector<LockEvent*>::const_iterator GetNextLockEvent( const Vector<LockEvent*>::const_iterator& it, const Vector<LockEvent*>::const_iterator& end, LockState& nextState, uint64_t threadBit ) static Vector<LockEventPtr>::const_iterator GetNextLockEvent( const Vector<LockEventPtr>::const_iterator& it, const Vector<LockEventPtr>::const_iterator& end, LockState& nextState, uint64_t threadBit )
{ {
auto next = it; auto next = it;
next++; next++;
@ -2816,14 +2816,14 @@ static Vector<LockEvent*>::const_iterator GetNextLockEvent( const Vector<LockEve
case LockState::Nothing: case LockState::Nothing:
while( next < end ) while( next < end )
{ {
if( (*next)->lockCount != 0 ) if( next->lockCount != 0 )
{ {
if( GetThreadBit( (*next)->lockingThread ) == threadBit ) if( GetThreadBit( next->lockingThread ) == threadBit )
{ {
nextState = AreOtherWaiting( (*next)->waitList, threadBit ) ? LockState::HasBlockingLock : LockState::HasLock; nextState = AreOtherWaiting( next->waitList, threadBit ) ? LockState::HasBlockingLock : LockState::HasLock;
break; break;
} }
else if( IsThreadWaiting( (*next)->waitList, threadBit ) ) else if( IsThreadWaiting( next->waitList, threadBit ) )
{ {
nextState = LockState::WaitLock; nextState = LockState::WaitLock;
break; break;
@ -2835,20 +2835,20 @@ static Vector<LockEvent*>::const_iterator GetNextLockEvent( const Vector<LockEve
case LockState::HasLock: case LockState::HasLock:
while( next < end ) while( next < end )
{ {
if( (*next)->lockCount == 0 ) if( next->lockCount == 0 )
{ {
nextState = LockState::Nothing; nextState = LockState::Nothing;
break; break;
} }
if( (*next)->waitList != 0 ) if( next->waitList != 0 )
{ {
if( AreOtherWaiting( (*next)->waitList, threadBit ) ) if( AreOtherWaiting( next->waitList, threadBit ) )
{ {
nextState = LockState::HasBlockingLock; nextState = LockState::HasBlockingLock;
} }
break; break;
} }
if( (*next)->waitList != (*it)->waitList || (*next)->lockCount != (*it)->lockCount ) if( next->waitList != it->waitList || next->lockCount != it->lockCount )
{ {
break; break;
} }
@ -2858,12 +2858,12 @@ static Vector<LockEvent*>::const_iterator GetNextLockEvent( const Vector<LockEve
case LockState::HasBlockingLock: case LockState::HasBlockingLock:
while( next < end ) while( next < end )
{ {
if( (*next)->lockCount == 0 ) if( next->lockCount == 0 )
{ {
nextState = LockState::Nothing; nextState = LockState::Nothing;
break; break;
} }
if( (*next)->waitList != (*it)->waitList || (*next)->lockCount != (*it)->lockCount ) if( next->waitList != it->waitList || next->lockCount != it->lockCount )
{ {
break; break;
} }
@ -2873,16 +2873,16 @@ static Vector<LockEvent*>::const_iterator GetNextLockEvent( const Vector<LockEve
case LockState::WaitLock: case LockState::WaitLock:
while( next < end ) while( next < end )
{ {
if( GetThreadBit( (*next)->lockingThread ) == threadBit ) if( GetThreadBit( next->lockingThread ) == threadBit )
{ {
nextState = AreOtherWaiting( (*next)->waitList, threadBit ) ? LockState::HasBlockingLock : LockState::HasLock; nextState = AreOtherWaiting( next->waitList, threadBit ) ? LockState::HasBlockingLock : LockState::HasLock;
break; break;
} }
if( (*next)->lockingThread != (*it)->lockingThread ) if( next->lockingThread != it->lockingThread )
{ {
break; break;
} }
if( (*next)->lockCount == 0 ) if( next->lockCount == 0 )
{ {
break; break;
} }
@ -2897,9 +2897,9 @@ static Vector<LockEvent*>::const_iterator GetNextLockEvent( const Vector<LockEve
return next; return next;
} }
static Vector<LockEvent*>::const_iterator GetNextLockEventShared( const Vector<LockEvent*>::const_iterator& it, const Vector<LockEvent*>::const_iterator& end, LockState& nextState, uint64_t threadBit ) static Vector<LockEventPtr>::const_iterator GetNextLockEventShared( const Vector<LockEventPtr>::const_iterator& it, const Vector<LockEventPtr>::const_iterator& end, LockState& nextState, uint64_t threadBit )
{ {
const auto itptr = (const LockEventShared*)*it; const auto itptr = (const LockEventShared*)it->ptr;
auto next = it; auto next = it;
next++; next++;
@ -2908,11 +2908,11 @@ static Vector<LockEvent*>::const_iterator GetNextLockEventShared( const Vector<L
case LockState::Nothing: case LockState::Nothing:
while( next < end ) while( next < end )
{ {
const auto ptr = (const LockEventShared*)*next; const auto ptr = (const LockEventShared*)next->ptr;
if( ptr->lockCount != 0 ) if( next->lockCount != 0 )
{ {
const auto wait = ptr->waitList | ptr->waitShared; const auto wait = next->waitList | ptr->waitShared;
if( GetThreadBit( ptr->lockingThread ) == threadBit ) if( GetThreadBit( next->lockingThread ) == threadBit )
{ {
nextState = AreOtherWaiting( wait, threadBit ) ? LockState::HasBlockingLock : LockState::HasLock; nextState = AreOtherWaiting( wait, threadBit ) ? LockState::HasBlockingLock : LockState::HasLock;
break; break;
@ -2925,10 +2925,10 @@ static Vector<LockEvent*>::const_iterator GetNextLockEventShared( const Vector<L
} }
else if( IsThreadWaiting( ptr->sharedList, threadBit ) ) else if( IsThreadWaiting( ptr->sharedList, threadBit ) )
{ {
nextState = ( ptr->waitList != 0 ) ? LockState::HasBlockingLock : LockState::HasLock; nextState = ( next->waitList != 0 ) ? LockState::HasBlockingLock : LockState::HasLock;
break; break;
} }
else if( ptr->sharedList != 0 && IsThreadWaiting( ptr->waitList, threadBit ) ) else if( ptr->sharedList != 0 && IsThreadWaiting( next->waitList, threadBit ) )
{ {
nextState = LockState::WaitLock; nextState = LockState::WaitLock;
break; break;
@ -2939,15 +2939,15 @@ static Vector<LockEvent*>::const_iterator GetNextLockEventShared( const Vector<L
case LockState::HasLock: case LockState::HasLock:
while( next < end ) while( next < end )
{ {
const auto ptr = (const LockEventShared*)*next; const auto ptr = (const LockEventShared*)next->ptr;
if( ptr->lockCount == 0 && !IsThreadWaiting( ptr->sharedList, threadBit ) ) if( next->lockCount == 0 && !IsThreadWaiting( ptr->sharedList, threadBit ) )
{ {
nextState = LockState::Nothing; nextState = LockState::Nothing;
break; break;
} }
if( ptr->waitList != 0 ) if( next->waitList != 0 )
{ {
if( AreOtherWaiting( ptr->waitList, threadBit ) ) if( AreOtherWaiting( next->waitList, threadBit ) )
{ {
nextState = LockState::HasBlockingLock; nextState = LockState::HasBlockingLock;
} }
@ -2958,7 +2958,7 @@ static Vector<LockEvent*>::const_iterator GetNextLockEventShared( const Vector<L
nextState = LockState::HasBlockingLock; nextState = LockState::HasBlockingLock;
break; break;
} }
if( ptr->waitList != itptr->waitList || ptr->waitShared != itptr->waitShared || ptr->lockCount != itptr->lockCount || ptr->sharedList != itptr->sharedList ) if( next->waitList != it->waitList || ptr->waitShared != itptr->waitShared || next->lockCount != it->lockCount || ptr->sharedList != itptr->sharedList )
{ {
break; break;
} }
@ -2968,13 +2968,13 @@ static Vector<LockEvent*>::const_iterator GetNextLockEventShared( const Vector<L
case LockState::HasBlockingLock: case LockState::HasBlockingLock:
while( next < end ) while( next < end )
{ {
const auto ptr = (const LockEventShared*)*next; const auto ptr = (const LockEventShared*)next->ptr;
if( ptr->lockCount == 0 && !IsThreadWaiting( ptr->sharedList, threadBit ) ) if( next->lockCount == 0 && !IsThreadWaiting( ptr->sharedList, threadBit ) )
{ {
nextState = LockState::Nothing; nextState = LockState::Nothing;
break; break;
} }
if( ptr->waitList != itptr->waitList || ptr->waitShared != itptr->waitShared || ptr->lockCount != itptr->lockCount || ptr->sharedList != itptr->sharedList ) if( next->waitList != it->waitList || ptr->waitShared != itptr->waitShared || next->lockCount != it->lockCount || ptr->sharedList != itptr->sharedList )
{ {
break; break;
} }
@ -2984,23 +2984,23 @@ static Vector<LockEvent*>::const_iterator GetNextLockEventShared( const Vector<L
case LockState::WaitLock: case LockState::WaitLock:
while( next < end ) while( next < end )
{ {
const auto ptr = (const LockEventShared*)*next; const auto ptr = (const LockEventShared*)next->ptr;
if( GetThreadBit( ptr->lockingThread ) == threadBit ) if( GetThreadBit( next->lockingThread ) == threadBit )
{ {
const auto wait = ptr->waitList | ptr->waitShared; const auto wait = next->waitList | ptr->waitShared;
nextState = AreOtherWaiting( wait, threadBit ) ? LockState::HasBlockingLock : LockState::HasLock; nextState = AreOtherWaiting( wait, threadBit ) ? LockState::HasBlockingLock : LockState::HasLock;
break; break;
} }
if( IsThreadWaiting( ptr->sharedList, threadBit ) ) if( IsThreadWaiting( ptr->sharedList, threadBit ) )
{ {
nextState = ( ptr->waitList != 0 ) ? LockState::HasBlockingLock : LockState::HasLock; nextState = ( next->waitList != 0 ) ? LockState::HasBlockingLock : LockState::HasLock;
break; break;
} }
if( ptr->lockingThread != itptr->lockingThread ) if( next->lockingThread != it->lockingThread )
{ {
break; break;
} }
if( ptr->lockCount == 0 && !IsThreadWaiting( ptr->waitShared, threadBit ) ) if( next->lockCount == 0 && !IsThreadWaiting( ptr->waitShared, threadBit ) )
{ {
break; break;
} }
@ -3041,11 +3041,11 @@ void View::DrawLockHeader( uint32_t id, const LockMap& lockmap, const SourceLoca
{ {
if( timeAnnounce == 0 ) if( timeAnnounce == 0 )
{ {
timeAnnounce = lockmap.timeline.front()->time; timeAnnounce = lockmap.timeline.front().ptr->time;
} }
if( timeTerminate == 0 ) if( timeTerminate == 0 )
{ {
timeTerminate = lockmap.timeline.back()->time; timeTerminate = lockmap.timeline.back().ptr->time;
} }
} }
const auto lockLen = timeTerminate - timeAnnounce; const auto lockLen = timeTerminate - timeAnnounce;
@ -3151,21 +3151,21 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
const auto thread = it->second; const auto thread = it->second;
const auto threadBit = GetThreadBit( thread ); 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->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->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--; if( vbegin > tl.begin() ) vbegin--;
LockState state = LockState::Nothing; LockState state = LockState::Nothing;
if( lockmap.type == LockType::Lockable ) if( lockmap.type == LockType::Lockable )
{ {
if( (*vbegin)->lockCount != 0 ) if( vbegin->lockCount != 0 )
{ {
if( (*vbegin)->lockingThread == thread ) if( vbegin->lockingThread == thread )
{ {
state = AreOtherWaiting( (*vbegin)->waitList, threadBit ) ? LockState::HasBlockingLock : LockState::HasLock; state = AreOtherWaiting( vbegin->waitList, threadBit ) ? LockState::HasBlockingLock : LockState::HasLock;
} }
else if( IsThreadWaiting( (*vbegin)->waitList, threadBit ) ) else if( IsThreadWaiting( vbegin->waitList, threadBit ) )
{ {
state = LockState::WaitLock; state = LockState::WaitLock;
} }
@ -3173,23 +3173,23 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
} }
else else
{ {
const auto ptr = (LockEventShared*)*vbegin; auto ptr = (const LockEventShared*)vbegin->ptr;
if( ptr->lockCount != 0 ) if( vbegin->lockCount != 0 )
{ {
if( ptr->lockingThread == thread ) if( vbegin->lockingThread == thread )
{ {
state = ( AreOtherWaiting( ptr->waitList, threadBit ) || AreOtherWaiting( ptr->waitShared, threadBit ) ) ? LockState::HasBlockingLock : LockState::HasLock; state = ( AreOtherWaiting( vbegin->waitList, threadBit ) || AreOtherWaiting( ptr->waitShared, threadBit ) ) ? LockState::HasBlockingLock : LockState::HasLock;
} }
else if( IsThreadWaiting( ptr->waitList, threadBit ) || IsThreadWaiting( ptr->waitShared, threadBit ) ) else if( IsThreadWaiting( vbegin->waitList, threadBit ) || IsThreadWaiting( ptr->waitShared, threadBit ) )
{ {
state = LockState::WaitLock; state = LockState::WaitLock;
} }
} }
else if( IsThreadWaiting( ptr->sharedList, threadBit ) ) else if( IsThreadWaiting( ptr->sharedList, threadBit ) )
{ {
state = ptr->waitList != 0 ? LockState::HasBlockingLock : LockState::HasLock; state = vbegin->waitList != 0 ? LockState::HasBlockingLock : LockState::HasLock;
} }
else if( ptr->sharedList != 0 && IsThreadWaiting( ptr->waitList, threadBit ) ) else if( ptr->sharedList != 0 && IsThreadWaiting( vbegin->waitList, threadBit ) )
{ {
state = LockState::WaitLock; state = LockState::WaitLock;
} }
@ -3216,8 +3216,8 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
LockState drawState = state; LockState drawState = state;
auto next = GetNextLockFunc( vbegin, vend, state, threadBit ); auto next = GetNextLockFunc( vbegin, vend, state, threadBit );
const auto t0 = (*vbegin)->time; const auto t0 = vbegin->ptr->time;
int64_t t1 = next == tl.end() ? m_worker.GetLastTime() : (*next)->time; int64_t t1 = next == tl.end() ? m_worker.GetLastTime() : next->ptr->time;
const auto px0 = std::max( pxend, ( t0 - m_zvStart ) * pxns ); const auto px0 = std::max( pxend, ( t0 - m_zvStart ) * pxns );
auto tx0 = px0; auto tx0 = px0;
double px1 = ( t1 - m_zvStart ) * pxns; double px1 = ( t1 - m_zvStart ) * pxns;
@ -3239,7 +3239,7 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
} }
drawState = CombineLockState( drawState, state ); drawState = CombineLockState( drawState, state );
condensed++; condensed++;
const auto t2 = n == tl.end() ? m_worker.GetLastTime() : (*n)->time; const auto t2 = n == tl.end() ? m_worker.GetLastTime() : n->ptr->time;
const auto px2 = ( t2 - m_zvStart ) * pxns; const auto px2 = ( t2 - m_zvStart ) * pxns;
if( px2 - px1 > MinVisSize ) break; if( px2 - px1 > MinVisSize ) break;
if( drawState != ns && px2 - px0 > MinVisSize && !( ns == LockState::Nothing || ( m_onlyContendedLocks && ns == LockState::HasLock ) ) ) break; if( drawState != ns && px2 - px0 > MinVisSize && !( ns == LockState::Nothing || ( m_onlyContendedLocks && ns == LockState::HasLock ) ) ) break;
@ -3286,22 +3286,22 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
auto b = vbegin; auto b = vbegin;
while( b != tl.begin() ) while( b != tl.begin() )
{ {
if( (*b)->lockingThread != (*vbegin)->lockingThread ) if( b->lockingThread != vbegin->lockingThread )
{ {
break; break;
} }
b--; b--;
} }
b++; b++;
highlight.begin = (*b)->time; highlight.begin = b->ptr->time;
auto e = next; auto e = next;
while( e != tl.end() ) while( e != tl.end() )
{ {
if( (*e)->lockingThread != (*next)->lockingThread ) if( e->lockingThread != next->lockingThread )
{ {
highlight.id = v.first; highlight.id = v.first;
highlight.end = (*e)->time; highlight.end = e->ptr->time;
highlight.thread = thread; highlight.thread = thread;
break; break;
} }
@ -3320,11 +3320,11 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
auto it = vbegin; auto it = vbegin;
for(;;) for(;;)
{ {
if( (*it)->thread == thread ) if( it->ptr->thread == thread )
{ {
if( ( (*it)->lockingThread == thread || IsThreadWaiting( (*it)->waitList, threadBit ) ) && (*it)->srcloc != 0 ) if( ( it->lockingThread == thread || IsThreadWaiting( it->waitList, threadBit ) ) && it->ptr->srcloc != 0 )
{ {
markloc = (*it)->srcloc; markloc = it->ptr->srcloc;
break; break;
} }
} }
@ -3345,31 +3345,31 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
switch( drawState ) switch( drawState )
{ {
case LockState::HasLock: case LockState::HasLock:
if( (*vbegin)->lockCount == 1 ) if( vbegin->lockCount == 1 )
{ {
ImGui::Text( "Thread \"%s\" has lock. No other threads are waiting.", m_worker.GetThreadString( tid ) ); ImGui::Text( "Thread \"%s\" has lock. No other threads are waiting.", m_worker.GetThreadString( tid ) );
} }
else else
{ {
ImGui::Text( "Thread \"%s\" has %i locks. No other threads are waiting.", m_worker.GetThreadString( tid ), (*vbegin)->lockCount ); ImGui::Text( "Thread \"%s\" has %i locks. No other threads are waiting.", m_worker.GetThreadString( tid ), vbegin->lockCount );
} }
if( (*vbegin)->waitList != 0 ) if( vbegin->waitList != 0 )
{ {
assert( !AreOtherWaiting( (*next)->waitList, threadBit ) ); assert( !AreOtherWaiting( next->ptr->waitList, threadBit ) );
ImGui::TextUnformatted( "Recursive lock acquire in thread." ); ImGui::TextUnformatted( "Recursive lock acquire in thread." );
} }
break; break;
case LockState::HasBlockingLock: case LockState::HasBlockingLock:
{ {
if( (*vbegin)->lockCount == 1 ) if( vbegin->lockCount == 1 )
{ {
ImGui::Text( "Thread \"%s\" has lock. Blocked threads (%i):", m_worker.GetThreadString( tid ), TracyCountBits( (*vbegin)->waitList ) ); ImGui::Text( "Thread \"%s\" has lock. Blocked threads (%i):", m_worker.GetThreadString( tid ), TracyCountBits( vbegin->waitList ) );
} }
else else
{ {
ImGui::Text( "Thread \"%s\" has %i locks. Blocked threads (%i):", m_worker.GetThreadString( tid ), (*vbegin)->lockCount, TracyCountBits( (*vbegin)->waitList ) ); ImGui::Text( "Thread \"%s\" has %i locks. Blocked threads (%i):", m_worker.GetThreadString( tid ), vbegin->lockCount, TracyCountBits( vbegin->waitList ) );
} }
auto waitList = (*vbegin)->waitList; auto waitList = vbegin->waitList;
int t = 0; int t = 0;
ImGui::Indent( ty ); ImGui::Indent( ty );
while( waitList != 0 ) while( waitList != 0 )
@ -3386,7 +3386,7 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
} }
case LockState::WaitLock: case LockState::WaitLock:
{ {
if( (*vbegin)->lockCount > 0 ) if( vbegin->lockCount > 0 )
{ {
ImGui::Text( "Thread \"%s\" is blocked by other thread:", m_worker.GetThreadString( tid ) ); ImGui::Text( "Thread \"%s\" is blocked by other thread:", m_worker.GetThreadString( tid ) );
} }
@ -3395,7 +3395,7 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
ImGui::Text( "Thread \"%s\" waits to obtain lock after release by thread:", m_worker.GetThreadString( tid ) ); ImGui::Text( "Thread \"%s\" waits to obtain lock after release by thread:", m_worker.GetThreadString( tid ) );
} }
ImGui::Indent( ty ); ImGui::Indent( ty );
ImGui::Text( "\"%s\"", m_worker.GetThreadString( lockmap.threadList[(*vbegin)->lockingThread] ) ); ImGui::Text( "\"%s\"", m_worker.GetThreadString( lockmap.threadList[vbegin->lockingThread] ) );
ImGui::Unindent( ty ); ImGui::Unindent( ty );
break; break;
} }
@ -3406,14 +3406,14 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
} }
else else
{ {
const auto ptr = (const LockEventShared*)*vbegin; const auto ptr = (const LockEventShared*)vbegin->ptr;
switch( drawState ) switch( drawState )
{ {
case LockState::HasLock: case LockState::HasLock:
assert( ptr->waitList == 0 ); assert( ptr->waitList == 0 );
if( ptr->sharedList == 0 ) if( ptr->sharedList == 0 )
{ {
assert( ptr->lockCount == 1 ); assert( vbegin->lockCount == 1 );
ImGui::Text( "Thread \"%s\" has lock. No other threads are waiting.", m_worker.GetThreadString( tid ) ); ImGui::Text( "Thread \"%s\" has lock. No other threads are waiting.", m_worker.GetThreadString( tid ) );
} }
else if( TracyCountBits( ptr->sharedList ) == 1 ) else if( TracyCountBits( ptr->sharedList ) == 1 )
@ -3443,12 +3443,12 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
{ {
if( ptr->sharedList == 0 ) if( ptr->sharedList == 0 )
{ {
assert( ptr->lockCount == 1 ); assert( vbegin->lockCount == 1 );
ImGui::Text( "Thread \"%s\" has lock. Blocked threads (%i):", m_worker.GetThreadString( tid ), TracyCountBits( ptr->waitList ) + TracyCountBits( ptr->waitShared ) ); ImGui::Text( "Thread \"%s\" has lock. Blocked threads (%i):", m_worker.GetThreadString( tid ), TracyCountBits( vbegin->waitList ) + TracyCountBits( ptr->waitShared ) );
} }
else if( TracyCountBits( ptr->sharedList ) == 1 ) else if( TracyCountBits( ptr->sharedList ) == 1 )
{ {
ImGui::Text( "Thread \"%s\" has a sole shared lock. Blocked threads (%i):", m_worker.GetThreadString( tid ), TracyCountBits( ptr->waitList ) + TracyCountBits( ptr->waitShared ) ); ImGui::Text( "Thread \"%s\" has a sole shared lock. Blocked threads (%i):", m_worker.GetThreadString( tid ), TracyCountBits( vbegin->waitList ) + TracyCountBits( ptr->waitShared ) );
} }
else else
{ {
@ -3467,10 +3467,10 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
t++; t++;
} }
ImGui::Unindent( ty ); ImGui::Unindent( ty );
ImGui::Text( "Blocked threads (%i):", TracyCountBits( ptr->waitList ) + TracyCountBits( ptr->waitShared ) ); ImGui::Text( "Blocked threads (%i):", TracyCountBits( vbegin->waitList ) + TracyCountBits( ptr->waitShared ) );
} }
auto waitList = ptr->waitList; auto waitList = vbegin->waitList;
int t = 0; int t = 0;
ImGui::Indent( ty ); ImGui::Indent( ty );
while( waitList != 0 ) while( waitList != 0 )
@ -3498,19 +3498,19 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
} }
case LockState::WaitLock: case LockState::WaitLock:
{ {
assert( ptr->lockCount == 0 || ptr->lockCount == 1 ); assert( vbegin->lockCount == 0 || vbegin->lockCount == 1 );
if( ptr->lockCount != 0 || ptr->sharedList != 0 ) if( vbegin->lockCount != 0 || ptr->sharedList != 0 )
{ {
ImGui::Text( "Thread \"%s\" is blocked by other threads (%i):", m_worker.GetThreadString( tid ), ptr->lockCount + TracyCountBits( ptr->sharedList ) ); ImGui::Text( "Thread \"%s\" is blocked by other threads (%i):", m_worker.GetThreadString( tid ), vbegin->lockCount + TracyCountBits( ptr->sharedList ) );
} }
else else
{ {
ImGui::Text( "Thread \"%s\" waits to obtain lock after release by thread:", m_worker.GetThreadString( tid ) ); ImGui::Text( "Thread \"%s\" waits to obtain lock after release by thread:", m_worker.GetThreadString( tid ) );
} }
ImGui::Indent( ty ); ImGui::Indent( ty );
if( ptr->lockCount != 0 ) if( vbegin->lockCount != 0 )
{ {
ImGui::Text( "\"%s\"", m_worker.GetThreadString( lockmap.threadList[ptr->lockingThread] ) ); ImGui::Text( "\"%s\"", m_worker.GetThreadString( lockmap.threadList[vbegin->lockingThread] ) );
} }
auto sharedList = ptr->sharedList; auto sharedList = ptr->sharedList;
int t = 0; int t = 0;
@ -3537,7 +3537,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 ); 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 ); 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)->time && m_lockHighlight.end >= (*next)->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 ); 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 ); 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 );
@ -8409,11 +8409,11 @@ void View::DrawLockInfoWindow()
{ {
if( timeAnnounce == 0 ) if( timeAnnounce == 0 )
{ {
timeAnnounce = lock.timeline.front()->time; timeAnnounce = lock.timeline.front().ptr->time;
} }
if( timeTerminate == 0 ) if( timeTerminate == 0 )
{ {
timeTerminate = lock.timeline.back()->time; timeTerminate = lock.timeline.back().ptr->time;
} }
} }
@ -8428,39 +8428,39 @@ void View::DrawLockInfoWindow()
{ {
if( holdState ) if( holdState )
{ {
if( v->lockCount == 0 ) if( v.lockCount == 0 )
{ {
holdTotalTime += v->time - holdStartTime; holdTotalTime += v.ptr->time - holdStartTime;
holdState = false; holdState = false;
} }
} }
else else
{ {
if( v->lockCount != 0 ) if( v.lockCount != 0 )
{ {
holdStartTime = v->time; holdStartTime = v.ptr->time;
holdState = true; holdState = true;
} }
} }
if( waitState ) if( waitState )
{ {
if( v->waitList == 0 ) if( v.waitList == 0 )
{ {
waitTotalTime += v->time - waitStartTime; waitTotalTime += v.ptr->time - waitStartTime;
waitState = false; waitState = false;
} }
else else
{ {
maxWaitingThreads = std::max<uint32_t>( maxWaitingThreads, TracyCountBits( v->waitList ) ); maxWaitingThreads = std::max<uint32_t>( maxWaitingThreads, TracyCountBits( v.waitList ) );
} }
} }
else else
{ {
if( v->waitList != 0 ) if( v.waitList != 0 )
{ {
waitStartTime = v->time; waitStartTime = v.ptr->time;
waitState = true; waitState = true;
maxWaitingThreads = std::max<uint32_t>( maxWaitingThreads, TracyCountBits( v->waitList ) ); maxWaitingThreads = std::max<uint32_t>( maxWaitingThreads, TracyCountBits( v.waitList ) );
} }
} }
} }

View File

@ -74,18 +74,18 @@ static void UpdateLockCountLockable( LockMap& lockmap, size_t pos )
} }
else else
{ {
const auto tl = timeline[pos-1]; const auto& tl = timeline[pos-1];
lockingThread = tl->lockingThread; lockingThread = tl.lockingThread;
lockCount = tl->lockCount; lockCount = tl.lockCount;
waitList = tl->waitList; waitList = tl.waitList;
} }
const auto end = timeline.size(); const auto end = timeline.size();
while( pos != end ) while( pos != end )
{ {
const auto tl = timeline[pos]; auto& tl = timeline[pos];
const auto tbit = uint64_t( 1 ) << tl->thread; const auto tbit = uint64_t( 1 ) << tl.ptr->thread;
switch( (LockEvent::Type)tl->type ) switch( (LockEvent::Type)tl.ptr->type )
{ {
case LockEvent::Type::Wait: case LockEvent::Type::Wait:
waitList |= tbit; waitList |= tbit;
@ -94,7 +94,7 @@ static void UpdateLockCountLockable( LockMap& lockmap, size_t pos )
assert( lockCount < std::numeric_limits<uint8_t>::max() ); assert( lockCount < std::numeric_limits<uint8_t>::max() );
assert( ( waitList & tbit ) != 0 ); assert( ( waitList & tbit ) != 0 );
waitList &= ~tbit; waitList &= ~tbit;
lockingThread = tl->thread; lockingThread = tl.ptr->thread;
lockCount++; lockCount++;
break; break;
case LockEvent::Type::Release: case LockEvent::Type::Release:
@ -104,9 +104,9 @@ static void UpdateLockCountLockable( LockMap& lockmap, size_t pos )
default: default:
break; break;
} }
tl->lockingThread = lockingThread; tl.lockingThread = lockingThread;
tl->waitList = waitList; tl.waitList = waitList;
tl->lockCount = lockCount; tl.lockCount = lockCount;
pos++; pos++;
} }
} }
@ -130,12 +130,13 @@ static void UpdateLockCountSharedLockable( LockMap& lockmap, size_t pos )
} }
else else
{ {
const auto tl = (LockEventShared*)timeline[pos-1]; const auto& tl = timeline[pos-1];
lockingThread = tl->lockingThread; const auto tlp = (LockEventShared*)tl.ptr;
lockCount = tl->lockCount; lockingThread = tl.lockingThread;
waitShared = tl->waitShared; lockCount = tl.lockCount;
waitList = tl->waitList; waitShared = tlp->waitShared;
sharedList = tl->sharedList; waitList = tl.waitList;
sharedList = tlp->sharedList;
} }
const auto end = timeline.size(); const auto end = timeline.size();
@ -143,9 +144,10 @@ static void UpdateLockCountSharedLockable( LockMap& lockmap, size_t pos )
// due to the async retrieval of data from threads that not possible. // due to the async retrieval of data from threads that not possible.
while( pos != end ) while( pos != end )
{ {
const auto tl = (LockEventShared*)timeline[pos]; auto& tl = timeline[pos];
const auto tbit = uint64_t( 1 ) << tl->thread; const auto tlp = (LockEventShared*)tl.ptr;
switch( (LockEvent::Type)tl->type ) const auto tbit = uint64_t( 1 ) << tlp->thread;
switch( (LockEvent::Type)tlp->type )
{ {
case LockEvent::Type::Wait: case LockEvent::Type::Wait:
waitList |= tbit; waitList |= tbit;
@ -157,7 +159,7 @@ static void UpdateLockCountSharedLockable( LockMap& lockmap, size_t pos )
assert( lockCount < std::numeric_limits<uint8_t>::max() ); assert( lockCount < std::numeric_limits<uint8_t>::max() );
assert( ( waitList & tbit ) != 0 ); assert( ( waitList & tbit ) != 0 );
waitList &= ~tbit; waitList &= ~tbit;
lockingThread = tl->thread; lockingThread = tlp->thread;
lockCount++; lockCount++;
break; break;
case LockEvent::Type::Release: case LockEvent::Type::Release:
@ -177,11 +179,11 @@ static void UpdateLockCountSharedLockable( LockMap& lockmap, size_t pos )
default: default:
break; break;
} }
tl->lockingThread = lockingThread; tl.lockingThread = lockingThread;
tl->waitShared = waitShared; tlp->waitShared = waitShared;
tl->waitList = waitList; tl.waitList = waitList;
tl->sharedList = sharedList; tlp->sharedList = sharedList;
tl->lockCount = lockCount; tl.lockCount = lockCount;
pos++; pos++;
} }
} }
@ -611,7 +613,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
auto lev = m_slab.Alloc<LockEvent>(); auto lev = m_slab.Alloc<LockEvent>();
lev->time = ReadTimeOffset( f, refTime ); lev->time = ReadTimeOffset( f, refTime );
f.Read( &lev->srcloc, sizeof( LockEvent::srcloc ) + sizeof( LockEvent::thread ) + sizeof( LockEvent::type ) ); f.Read( &lev->srcloc, sizeof( LockEvent::srcloc ) + sizeof( LockEvent::thread ) + sizeof( LockEvent::type ) );
*ptr++ = lev; *ptr++ = { lev };
UpdateLockRange( lockmap, *lev ); UpdateLockRange( lockmap, *lev );
} }
} }
@ -622,7 +624,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
auto lev = m_slab.Alloc<LockEventShared>(); auto lev = m_slab.Alloc<LockEventShared>();
lev->time = ReadTimeOffset( f, refTime ); lev->time = ReadTimeOffset( f, refTime );
f.Read( &lev->srcloc, sizeof( LockEventShared::srcloc ) + sizeof( LockEventShared::thread ) + sizeof( LockEventShared::type ) ); f.Read( &lev->srcloc, sizeof( LockEventShared::srcloc ) + sizeof( LockEventShared::thread ) + sizeof( LockEventShared::type ) );
*ptr++ = lev; *ptr++ = { lev };
UpdateLockRange( lockmap, *lev ); UpdateLockRange( lockmap, *lev );
} }
} }
@ -635,7 +637,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
{ {
auto lev = m_slab.Alloc<LockEvent>(); auto lev = m_slab.Alloc<LockEvent>();
f.Read( lev, sizeof( LockEvent::time ) + sizeof( LockEvent::srcloc ) + sizeof( LockEvent::thread ) + sizeof( LockEvent::type ) ); f.Read( lev, sizeof( LockEvent::time ) + sizeof( LockEvent::srcloc ) + sizeof( LockEvent::thread ) + sizeof( LockEvent::type ) );
*ptr++ = lev; *ptr++ = { lev };
UpdateLockRange( lockmap, *lev ); UpdateLockRange( lockmap, *lev );
} }
} }
@ -645,7 +647,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
{ {
auto lev = m_slab.Alloc<LockEventShared>(); auto lev = m_slab.Alloc<LockEventShared>();
f.Read( lev, sizeof( LockEventShared::time ) + sizeof( LockEventShared::srcloc ) + sizeof( LockEventShared::thread ) + sizeof( LockEventShared::type ) ); f.Read( lev, sizeof( LockEventShared::time ) + sizeof( LockEventShared::srcloc ) + sizeof( LockEventShared::thread ) + sizeof( LockEventShared::type ) );
*ptr++ = lev; *ptr++ = { lev };
UpdateLockRange( lockmap, *lev ); UpdateLockRange( lockmap, *lev );
} }
} }
@ -661,7 +663,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
f.Skip( sizeof( uint8_t ) ); f.Skip( sizeof( uint8_t ) );
f.Read( lev->type ); f.Read( lev->type );
f.Skip( sizeof( uint8_t ) + sizeof( uint64_t ) ); f.Skip( sizeof( uint8_t ) + sizeof( uint64_t ) );
*ptr++ = lev; *ptr++ = { lev };
UpdateLockRange( lockmap, *lev ); UpdateLockRange( lockmap, *lev );
} }
} }
@ -674,7 +676,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
f.Skip( sizeof( uint8_t ) ); f.Skip( sizeof( uint8_t ) );
f.Read( lev->type ); f.Read( lev->type );
f.Skip( sizeof( uint8_t ) + sizeof( uint64_t ) * 3 ); f.Skip( sizeof( uint8_t ) + sizeof( uint64_t ) * 3 );
*ptr++ = lev; *ptr++ = { lev };
UpdateLockRange( lockmap, *lev ); UpdateLockRange( lockmap, *lev );
} }
} }
@ -2008,18 +2010,18 @@ void Worker::InsertLockEvent( LockMap& lockmap, LockEvent* lev, uint64_t thread
auto& timeline = lockmap.timeline; auto& timeline = lockmap.timeline;
if( timeline.empty() ) if( timeline.empty() )
{ {
timeline.push_back( lev ); timeline.push_back( { lev } );
UpdateLockCount( lockmap, timeline.size() - 1 ); UpdateLockCount( lockmap, timeline.size() - 1 );
} }
else if( timeline.back()->time < lt ) else if( timeline.back().ptr->time < lt )
{ {
timeline.push_back_non_empty( lev ); timeline.push_back_non_empty( { lev } );
UpdateLockCount( lockmap, timeline.size() - 1 ); UpdateLockCount( lockmap, timeline.size() - 1 );
} }
else else
{ {
auto it = std::lower_bound( timeline.begin(), timeline.end(), lt, [] ( const auto& lhs, const auto& rhs ) { return lhs->time < rhs; } ); auto it = std::lower_bound( timeline.begin(), timeline.end(), lt, [] ( const auto& lhs, const auto& rhs ) { return lhs.ptr->time < rhs; } );
it = timeline.insert( it, lev ); it = timeline.insert( it, { lev } );
UpdateLockCount( lockmap, std::distance( timeline.begin(), it ) ); UpdateLockCount( lockmap, std::distance( timeline.begin(), it ) );
} }
@ -2936,15 +2938,15 @@ void Worker::ProcessLockMark( const QueueLockMark& ev )
for(;;) for(;;)
{ {
--it; --it;
if( (*it)->thread == thread ) if( it->ptr->thread == thread )
{ {
switch( (*it)->type ) switch( it->ptr->type )
{ {
case LockEvent::Type::Obtain: case LockEvent::Type::Obtain:
case LockEvent::Type::ObtainShared: case LockEvent::Type::ObtainShared:
case LockEvent::Type::Wait: case LockEvent::Type::Wait:
case LockEvent::Type::WaitShared: case LockEvent::Type::WaitShared:
(*it)->srcloc = ShrinkSourceLocation( ev.srcloc ); it->ptr->srcloc = ShrinkSourceLocation( ev.srcloc );
return; return;
default: default:
break; break;
@ -3950,10 +3952,10 @@ void Worker::Write( FileWrite& f )
f.Write( &sz, sizeof( sz ) ); f.Write( &sz, sizeof( sz ) );
for( auto& lev : v.second->timeline ) for( auto& lev : v.second->timeline )
{ {
WriteTimeOffset( f, refTime, lev->time ); WriteTimeOffset( f, refTime, lev.ptr->time );
f.Write( &lev->srcloc, sizeof( lev->srcloc ) ); f.Write( &lev.ptr->srcloc, sizeof( lev.ptr->srcloc ) );
f.Write( &lev->thread, sizeof( lev->thread ) ); f.Write( &lev.ptr->thread, sizeof( lev.ptr->thread ) );
f.Write( &lev->type, sizeof( lev->type ) ); f.Write( &lev.ptr->type, sizeof( lev.ptr->type ) );
} }
} }