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

View File

@ -2179,10 +2179,10 @@ void View::DrawZones()
const auto thread = it->second;
auto lptr = lockmap.timeline.data();
auto eptr = lptr + lockmap.timeline.size() - 1;
while( (*lptr)->thread != thread ) lptr++;
if( (*lptr)->time < first ) first = (*lptr)->time;
while( (*eptr)->thread != thread ) eptr--;
if( (*eptr)->time > last ) last = (*eptr)->time;
while( lptr->ptr->thread != thread ) lptr++;
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( last >= 0 )
@ -2806,7 +2806,7 @@ enum class LockState
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;
next++;
@ -2816,14 +2816,14 @@ static Vector<LockEvent*>::const_iterator GetNextLockEvent( const Vector<LockEve
case LockState::Nothing:
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;
}
else if( IsThreadWaiting( (*next)->waitList, threadBit ) )
else if( IsThreadWaiting( next->waitList, threadBit ) )
{
nextState = LockState::WaitLock;
break;
@ -2835,20 +2835,20 @@ static Vector<LockEvent*>::const_iterator GetNextLockEvent( const Vector<LockEve
case LockState::HasLock:
while( next < end )
{
if( (*next)->lockCount == 0 )
if( next->lockCount == 0 )
{
nextState = LockState::Nothing;
break;
}
if( (*next)->waitList != 0 )
if( next->waitList != 0 )
{
if( AreOtherWaiting( (*next)->waitList, threadBit ) )
if( AreOtherWaiting( next->waitList, threadBit ) )
{
nextState = LockState::HasBlockingLock;
}
break;
}
if( (*next)->waitList != (*it)->waitList || (*next)->lockCount != (*it)->lockCount )
if( next->waitList != it->waitList || next->lockCount != it->lockCount )
{
break;
}
@ -2858,12 +2858,12 @@ static Vector<LockEvent*>::const_iterator GetNextLockEvent( const Vector<LockEve
case LockState::HasBlockingLock:
while( next < end )
{
if( (*next)->lockCount == 0 )
if( next->lockCount == 0 )
{
nextState = LockState::Nothing;
break;
}
if( (*next)->waitList != (*it)->waitList || (*next)->lockCount != (*it)->lockCount )
if( next->waitList != it->waitList || next->lockCount != it->lockCount )
{
break;
}
@ -2873,16 +2873,16 @@ static Vector<LockEvent*>::const_iterator GetNextLockEvent( const Vector<LockEve
case LockState::WaitLock:
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;
}
if( (*next)->lockingThread != (*it)->lockingThread )
if( next->lockingThread != it->lockingThread )
{
break;
}
if( (*next)->lockCount == 0 )
if( next->lockCount == 0 )
{
break;
}
@ -2897,9 +2897,9 @@ static Vector<LockEvent*>::const_iterator GetNextLockEvent( const Vector<LockEve
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;
next++;
@ -2908,11 +2908,11 @@ static Vector<LockEvent*>::const_iterator GetNextLockEventShared( const Vector<L
case LockState::Nothing:
while( next < end )
{
const auto ptr = (const LockEventShared*)*next;
if( ptr->lockCount != 0 )
const auto ptr = (const LockEventShared*)next->ptr;
if( next->lockCount != 0 )
{
const auto wait = ptr->waitList | ptr->waitShared;
if( GetThreadBit( ptr->lockingThread ) == threadBit )
const auto wait = next->waitList | ptr->waitShared;
if( GetThreadBit( next->lockingThread ) == threadBit )
{
nextState = AreOtherWaiting( wait, threadBit ) ? LockState::HasBlockingLock : LockState::HasLock;
break;
@ -2925,10 +2925,10 @@ static Vector<LockEvent*>::const_iterator GetNextLockEventShared( const Vector<L
}
else if( IsThreadWaiting( ptr->sharedList, threadBit ) )
{
nextState = ( ptr->waitList != 0 ) ? LockState::HasBlockingLock : LockState::HasLock;
nextState = ( next->waitList != 0 ) ? LockState::HasBlockingLock : LockState::HasLock;
break;
}
else if( ptr->sharedList != 0 && IsThreadWaiting( ptr->waitList, threadBit ) )
else if( ptr->sharedList != 0 && IsThreadWaiting( next->waitList, threadBit ) )
{
nextState = LockState::WaitLock;
break;
@ -2939,15 +2939,15 @@ static Vector<LockEvent*>::const_iterator GetNextLockEventShared( const Vector<L
case LockState::HasLock:
while( next < end )
{
const auto ptr = (const LockEventShared*)*next;
if( ptr->lockCount == 0 && !IsThreadWaiting( ptr->sharedList, threadBit ) )
const auto ptr = (const LockEventShared*)next->ptr;
if( next->lockCount == 0 && !IsThreadWaiting( ptr->sharedList, threadBit ) )
{
nextState = LockState::Nothing;
break;
}
if( ptr->waitList != 0 )
if( next->waitList != 0 )
{
if( AreOtherWaiting( ptr->waitList, threadBit ) )
if( AreOtherWaiting( next->waitList, threadBit ) )
{
nextState = LockState::HasBlockingLock;
}
@ -2958,7 +2958,7 @@ static Vector<LockEvent*>::const_iterator GetNextLockEventShared( const Vector<L
nextState = LockState::HasBlockingLock;
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;
}
@ -2968,13 +2968,13 @@ static Vector<LockEvent*>::const_iterator GetNextLockEventShared( const Vector<L
case LockState::HasBlockingLock:
while( next < end )
{
const auto ptr = (const LockEventShared*)*next;
if( ptr->lockCount == 0 && !IsThreadWaiting( ptr->sharedList, threadBit ) )
const auto ptr = (const LockEventShared*)next->ptr;
if( next->lockCount == 0 && !IsThreadWaiting( ptr->sharedList, threadBit ) )
{
nextState = LockState::Nothing;
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;
}
@ -2984,23 +2984,23 @@ static Vector<LockEvent*>::const_iterator GetNextLockEventShared( const Vector<L
case LockState::WaitLock:
while( next < end )
{
const auto ptr = (const LockEventShared*)*next;
if( GetThreadBit( ptr->lockingThread ) == threadBit )
const auto ptr = (const LockEventShared*)next->ptr;
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;
break;
}
if( IsThreadWaiting( ptr->sharedList, threadBit ) )
{
nextState = ( ptr->waitList != 0 ) ? LockState::HasBlockingLock : LockState::HasLock;
nextState = ( next->waitList != 0 ) ? LockState::HasBlockingLock : LockState::HasLock;
break;
}
if( ptr->lockingThread != itptr->lockingThread )
if( next->lockingThread != it->lockingThread )
{
break;
}
if( ptr->lockCount == 0 && !IsThreadWaiting( ptr->waitShared, threadBit ) )
if( next->lockCount == 0 && !IsThreadWaiting( ptr->waitShared, threadBit ) )
{
break;
}
@ -3041,11 +3041,11 @@ void View::DrawLockHeader( uint32_t id, const LockMap& lockmap, const SourceLoca
{
if( timeAnnounce == 0 )
{
timeAnnounce = lockmap.timeline.front()->time;
timeAnnounce = lockmap.timeline.front().ptr->time;
}
if( timeTerminate == 0 )
{
timeTerminate = lockmap.timeline.back()->time;
timeTerminate = lockmap.timeline.back().ptr->time;
}
}
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 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; } );
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; } );
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--;
LockState state = LockState::Nothing;
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;
}
@ -3173,23 +3173,23 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
}
else
{
const auto ptr = (LockEventShared*)*vbegin;
if( ptr->lockCount != 0 )
auto ptr = (const LockEventShared*)vbegin->ptr;
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;
}
}
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;
}
@ -3216,8 +3216,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)->time;
int64_t t1 = next == tl.end() ? m_worker.GetLastTime() : (*next)->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;
@ -3239,7 +3239,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)->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 || ( 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;
while( b != tl.begin() )
{
if( (*b)->lockingThread != (*vbegin)->lockingThread )
if( b->lockingThread != vbegin->lockingThread )
{
break;
}
b--;
}
b++;
highlight.begin = (*b)->time;
highlight.begin = b->ptr->time;
auto e = next;
while( e != tl.end() )
{
if( (*e)->lockingThread != (*next)->lockingThread )
if( e->lockingThread != next->lockingThread )
{
highlight.id = v.first;
highlight.end = (*e)->time;
highlight.end = e->ptr->time;
highlight.thread = thread;
break;
}
@ -3320,11 +3320,11 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
auto it = vbegin;
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;
}
}
@ -3345,31 +3345,31 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
switch( drawState )
{
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 ) );
}
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." );
}
break;
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
{
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;
ImGui::Indent( ty );
while( waitList != 0 )
@ -3386,7 +3386,7 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
}
case LockState::WaitLock:
{
if( (*vbegin)->lockCount > 0 )
if( vbegin->lockCount > 0 )
{
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::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 );
break;
}
@ -3406,14 +3406,14 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
}
else
{
const auto ptr = (const LockEventShared*)*vbegin;
const auto ptr = (const LockEventShared*)vbegin->ptr;
switch( drawState )
{
case LockState::HasLock:
assert( ptr->waitList == 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 ) );
}
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 )
{
assert( ptr->lockCount == 1 );
ImGui::Text( "Thread \"%s\" has lock. Blocked threads (%i):", m_worker.GetThreadString( tid ), TracyCountBits( ptr->waitList ) + TracyCountBits( ptr->waitShared ) );
assert( vbegin->lockCount == 1 );
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 )
{
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
{
@ -3467,10 +3467,10 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
t++;
}
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;
ImGui::Indent( ty );
while( waitList != 0 )
@ -3498,19 +3498,19 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
}
case LockState::WaitLock:
{
assert( ptr->lockCount == 0 || ptr->lockCount == 1 );
if( ptr->lockCount != 0 || ptr->sharedList != 0 )
assert( vbegin->lockCount == 0 || vbegin->lockCount == 1 );
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
{
ImGui::Text( "Thread \"%s\" waits to obtain lock after release by thread:", m_worker.GetThreadString( tid ) );
}
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;
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 );
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 );
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 )
{
timeAnnounce = lock.timeline.front()->time;
timeAnnounce = lock.timeline.front().ptr->time;
}
if( timeTerminate == 0 )
{
timeTerminate = lock.timeline.back()->time;
timeTerminate = lock.timeline.back().ptr->time;
}
}
@ -8428,39 +8428,39 @@ void View::DrawLockInfoWindow()
{
if( holdState )
{
if( v->lockCount == 0 )
if( v.lockCount == 0 )
{
holdTotalTime += v->time - holdStartTime;
holdTotalTime += v.ptr->time - holdStartTime;
holdState = false;
}
}
else
{
if( v->lockCount != 0 )
if( v.lockCount != 0 )
{
holdStartTime = v->time;
holdStartTime = v.ptr->time;
holdState = true;
}
}
if( waitState )
{
if( v->waitList == 0 )
if( v.waitList == 0 )
{
waitTotalTime += v->time - waitStartTime;
waitTotalTime += v.ptr->time - waitStartTime;
waitState = false;
}
else
{
maxWaitingThreads = std::max<uint32_t>( maxWaitingThreads, TracyCountBits( v->waitList ) );
maxWaitingThreads = std::max<uint32_t>( maxWaitingThreads, TracyCountBits( v.waitList ) );
}
}
else
{
if( v->waitList != 0 )
if( v.waitList != 0 )
{
waitStartTime = v->time;
waitStartTime = v.ptr->time;
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
{
const auto tl = timeline[pos-1];
lockingThread = tl->lockingThread;
lockCount = tl->lockCount;
waitList = tl->waitList;
const auto& tl = timeline[pos-1];
lockingThread = tl.lockingThread;
lockCount = tl.lockCount;
waitList = tl.waitList;
}
const auto end = timeline.size();
while( pos != end )
{
const auto tl = timeline[pos];
const auto tbit = uint64_t( 1 ) << tl->thread;
switch( (LockEvent::Type)tl->type )
auto& tl = timeline[pos];
const auto tbit = uint64_t( 1 ) << tl.ptr->thread;
switch( (LockEvent::Type)tl.ptr->type )
{
case LockEvent::Type::Wait:
waitList |= tbit;
@ -94,7 +94,7 @@ static void UpdateLockCountLockable( LockMap& lockmap, size_t pos )
assert( lockCount < std::numeric_limits<uint8_t>::max() );
assert( ( waitList & tbit ) != 0 );
waitList &= ~tbit;
lockingThread = tl->thread;
lockingThread = tl.ptr->thread;
lockCount++;
break;
case LockEvent::Type::Release:
@ -104,9 +104,9 @@ static void UpdateLockCountLockable( LockMap& lockmap, size_t pos )
default:
break;
}
tl->lockingThread = lockingThread;
tl->waitList = waitList;
tl->lockCount = lockCount;
tl.lockingThread = lockingThread;
tl.waitList = waitList;
tl.lockCount = lockCount;
pos++;
}
}
@ -130,12 +130,13 @@ static void UpdateLockCountSharedLockable( LockMap& lockmap, size_t pos )
}
else
{
const auto tl = (LockEventShared*)timeline[pos-1];
lockingThread = tl->lockingThread;
lockCount = tl->lockCount;
waitShared = tl->waitShared;
waitList = tl->waitList;
sharedList = tl->sharedList;
const auto& tl = timeline[pos-1];
const auto tlp = (LockEventShared*)tl.ptr;
lockingThread = tl.lockingThread;
lockCount = tl.lockCount;
waitShared = tlp->waitShared;
waitList = tl.waitList;
sharedList = tlp->sharedList;
}
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.
while( pos != end )
{
const auto tl = (LockEventShared*)timeline[pos];
const auto tbit = uint64_t( 1 ) << tl->thread;
switch( (LockEvent::Type)tl->type )
auto& tl = timeline[pos];
const auto tlp = (LockEventShared*)tl.ptr;
const auto tbit = uint64_t( 1 ) << tlp->thread;
switch( (LockEvent::Type)tlp->type )
{
case LockEvent::Type::Wait:
waitList |= tbit;
@ -157,7 +159,7 @@ static void UpdateLockCountSharedLockable( LockMap& lockmap, size_t pos )
assert( lockCount < std::numeric_limits<uint8_t>::max() );
assert( ( waitList & tbit ) != 0 );
waitList &= ~tbit;
lockingThread = tl->thread;
lockingThread = tlp->thread;
lockCount++;
break;
case LockEvent::Type::Release:
@ -177,11 +179,11 @@ static void UpdateLockCountSharedLockable( LockMap& lockmap, size_t pos )
default:
break;
}
tl->lockingThread = lockingThread;
tl->waitShared = waitShared;
tl->waitList = waitList;
tl->sharedList = sharedList;
tl->lockCount = lockCount;
tl.lockingThread = lockingThread;
tlp->waitShared = waitShared;
tl.waitList = waitList;
tlp->sharedList = sharedList;
tl.lockCount = lockCount;
pos++;
}
}
@ -611,7 +613,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
auto lev = m_slab.Alloc<LockEvent>();
lev->time = ReadTimeOffset( f, refTime );
f.Read( &lev->srcloc, sizeof( LockEvent::srcloc ) + sizeof( LockEvent::thread ) + sizeof( LockEvent::type ) );
*ptr++ = lev;
*ptr++ = { lev };
UpdateLockRange( lockmap, *lev );
}
}
@ -622,7 +624,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
auto lev = m_slab.Alloc<LockEventShared>();
lev->time = ReadTimeOffset( f, refTime );
f.Read( &lev->srcloc, sizeof( LockEventShared::srcloc ) + sizeof( LockEventShared::thread ) + sizeof( LockEventShared::type ) );
*ptr++ = lev;
*ptr++ = { lev };
UpdateLockRange( lockmap, *lev );
}
}
@ -635,7 +637,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
{
auto lev = m_slab.Alloc<LockEvent>();
f.Read( lev, sizeof( LockEvent::time ) + sizeof( LockEvent::srcloc ) + sizeof( LockEvent::thread ) + sizeof( LockEvent::type ) );
*ptr++ = lev;
*ptr++ = { lev };
UpdateLockRange( lockmap, *lev );
}
}
@ -645,7 +647,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
{
auto lev = m_slab.Alloc<LockEventShared>();
f.Read( lev, sizeof( LockEventShared::time ) + sizeof( LockEventShared::srcloc ) + sizeof( LockEventShared::thread ) + sizeof( LockEventShared::type ) );
*ptr++ = lev;
*ptr++ = { lev };
UpdateLockRange( lockmap, *lev );
}
}
@ -661,7 +663,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
f.Skip( sizeof( uint8_t ) );
f.Read( lev->type );
f.Skip( sizeof( uint8_t ) + sizeof( uint64_t ) );
*ptr++ = lev;
*ptr++ = { lev };
UpdateLockRange( lockmap, *lev );
}
}
@ -674,7 +676,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
f.Skip( sizeof( uint8_t ) );
f.Read( lev->type );
f.Skip( sizeof( uint8_t ) + sizeof( uint64_t ) * 3 );
*ptr++ = lev;
*ptr++ = { lev };
UpdateLockRange( lockmap, *lev );
}
}
@ -2008,18 +2010,18 @@ void Worker::InsertLockEvent( LockMap& lockmap, LockEvent* lev, uint64_t thread
auto& timeline = lockmap.timeline;
if( timeline.empty() )
{
timeline.push_back( lev );
timeline.push_back( { lev } );
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 );
}
else
{
auto it = std::lower_bound( timeline.begin(), timeline.end(), lt, [] ( const auto& lhs, const auto& rhs ) { return lhs->time < rhs; } );
it = timeline.insert( it, lev );
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 } );
UpdateLockCount( lockmap, std::distance( timeline.begin(), it ) );
}
@ -2936,15 +2938,15 @@ void Worker::ProcessLockMark( const QueueLockMark& ev )
for(;;)
{
--it;
if( (*it)->thread == thread )
if( it->ptr->thread == thread )
{
switch( (*it)->type )
switch( it->ptr->type )
{
case LockEvent::Type::Obtain:
case LockEvent::Type::ObtainShared:
case LockEvent::Type::Wait:
case LockEvent::Type::WaitShared:
(*it)->srcloc = ShrinkSourceLocation( ev.srcloc );
it->ptr->srcloc = ShrinkSourceLocation( ev.srcloc );
return;
default:
break;
@ -3950,10 +3952,10 @@ void Worker::Write( FileWrite& f )
f.Write( &sz, sizeof( sz ) );
for( auto& lev : v.second->timeline )
{
WriteTimeOffset( f, refTime, lev->time );
f.Write( &lev->srcloc, sizeof( lev->srcloc ) );
f.Write( &lev->thread, sizeof( lev->thread ) );
f.Write( &lev->type, sizeof( lev->type ) );
WriteTimeOffset( f, refTime, lev.ptr->time );
f.Write( &lev.ptr->srcloc, sizeof( lev.ptr->srcloc ) );
f.Write( &lev.ptr->thread, sizeof( lev.ptr->thread ) );
f.Write( &lev.ptr->type, sizeof( lev.ptr->type ) );
}
}