Order of lock events is now always well-defined.

This commit is contained in:
Bartosz Taudul 2020-07-26 13:54:40 +02:00
parent 3e3aa80fa7
commit 14a15bf152
3 changed files with 19 additions and 62 deletions

View File

@ -44,7 +44,6 @@ public:
MemWrite( &item->hdr.type, QueueType::LockTerminate ); MemWrite( &item->hdr.type, QueueType::LockTerminate );
MemWrite( &item->lockTerminate.id, m_id ); MemWrite( &item->lockTerminate.id, m_id );
MemWrite( &item->lockTerminate.time, Profiler::GetTime() ); MemWrite( &item->lockTerminate.time, Profiler::GetTime() );
MemWrite( &item->lockTerminate.type, LockType::Lockable );
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
GetProfiler().DeferItem( *item ); GetProfiler().DeferItem( *item );
#endif #endif
@ -71,7 +70,6 @@ public:
MemWrite( &item->lockWait.thread, GetThreadHandle() ); MemWrite( &item->lockWait.thread, GetThreadHandle() );
MemWrite( &item->lockWait.id, m_id ); MemWrite( &item->lockWait.id, m_id );
MemWrite( &item->lockWait.time, Profiler::GetTime() ); MemWrite( &item->lockWait.time, Profiler::GetTime() );
MemWrite( &item->lockWait.type, LockType::Lockable );
Profiler::QueueSerialFinish(); Profiler::QueueSerialFinish();
return true; return true;
} }
@ -261,7 +259,6 @@ public:
MemWrite( &item->hdr.type, QueueType::LockTerminate ); MemWrite( &item->hdr.type, QueueType::LockTerminate );
MemWrite( &item->lockTerminate.id, m_id ); MemWrite( &item->lockTerminate.id, m_id );
MemWrite( &item->lockTerminate.time, Profiler::GetTime() ); MemWrite( &item->lockTerminate.time, Profiler::GetTime() );
MemWrite( &item->lockTerminate.type, LockType::SharedLockable );
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
GetProfiler().DeferItem( *item ); GetProfiler().DeferItem( *item );
#endif #endif
@ -288,7 +285,6 @@ public:
MemWrite( &item->lockWait.thread, GetThreadHandle() ); MemWrite( &item->lockWait.thread, GetThreadHandle() );
MemWrite( &item->lockWait.id, m_id ); MemWrite( &item->lockWait.id, m_id );
MemWrite( &item->lockWait.time, Profiler::GetTime() ); MemWrite( &item->lockWait.time, Profiler::GetTime() );
MemWrite( &item->lockWait.type, LockType::SharedLockable );
Profiler::QueueSerialFinish(); Profiler::QueueSerialFinish();
return true; return true;
} }
@ -371,7 +367,6 @@ public:
MemWrite( &item->lockWait.thread, GetThreadHandle() ); MemWrite( &item->lockWait.thread, GetThreadHandle() );
MemWrite( &item->lockWait.id, m_id ); MemWrite( &item->lockWait.id, m_id );
MemWrite( &item->lockWait.time, Profiler::GetTime() ); MemWrite( &item->lockWait.time, Profiler::GetTime() );
MemWrite( &item->lockWait.type, LockType::SharedLockable );
Profiler::QueueSerialFinish(); Profiler::QueueSerialFinish();
return true; return true;
} }

View File

@ -190,7 +190,6 @@ struct QueueLockTerminate
{ {
uint32_t id; uint32_t id;
int64_t time; int64_t time;
LockType type;
}; };
struct QueueLockWait struct QueueLockWait
@ -198,7 +197,6 @@ struct QueueLockWait
uint64_t thread; uint64_t thread;
uint32_t id; uint32_t id;
int64_t time; int64_t time;
LockType type;
}; };
struct QueueLockObtain struct QueueLockObtain

View File

@ -4575,62 +4575,32 @@ void Worker::ProcessZoneValue( const QueueZoneValue& ev )
void Worker::ProcessLockAnnounce( const QueueLockAnnounce& ev ) void Worker::ProcessLockAnnounce( const QueueLockAnnounce& ev )
{ {
auto it = m_data.lockMap.find( ev.id ); auto it = m_data.lockMap.find( ev.id );
if( it == m_data.lockMap.end() ) assert( it == m_data.lockMap.end() );
{ auto lm = m_slab.AllocInit<LockMap>();
auto lm = m_slab.AllocInit<LockMap>(); lm->srcloc = ShrinkSourceLocation( ev.lckloc );
lm->srcloc = ShrinkSourceLocation( ev.lckloc ); lm->type = ev.type;
lm->type = ev.type; lm->timeAnnounce = TscTime( ev.time - m_data.baseTime );
lm->timeAnnounce = TscTime( ev.time - m_data.baseTime ); lm->timeTerminate = 0;
lm->timeTerminate = 0; lm->valid = true;
lm->valid = true; lm->isContended = false;
lm->isContended = false; m_data.lockMap.emplace( ev.id, lm );
m_data.lockMap.emplace( ev.id, lm );
}
else
{
it->second->srcloc = ShrinkSourceLocation( ev.lckloc );
assert( it->second->type == ev.type );
it->second->timeAnnounce = TscTime( ev.time - m_data.baseTime );
it->second->valid = true;
}
CheckSourceLocation( ev.lckloc ); CheckSourceLocation( ev.lckloc );
} }
void Worker::ProcessLockTerminate( const QueueLockTerminate& ev ) void Worker::ProcessLockTerminate( const QueueLockTerminate& ev )
{ {
auto it = m_data.lockMap.find( ev.id ); auto it = m_data.lockMap.find( ev.id );
if( it == m_data.lockMap.end() ) assert( it != m_data.lockMap.end() );
{ it->second->timeTerminate = TscTime( ev.time - m_data.baseTime );
auto lm = m_slab.AllocInit<LockMap>();
lm->type = ev.type;
lm->timeAnnounce = 0;
lm->timeTerminate = TscTime( ev.time - m_data.baseTime );
lm->valid = false;
lm->isContended = false;
m_data.lockMap.emplace( ev.id, lm );
}
else
{
assert( it->second->type == ev.type );
it->second->timeTerminate = TscTime( ev.time - m_data.baseTime );
}
} }
void Worker::ProcessLockWait( const QueueLockWait& ev ) void Worker::ProcessLockWait( const QueueLockWait& ev )
{ {
auto it = m_data.lockMap.find( ev.id ); auto it = m_data.lockMap.find( ev.id );
if( it == m_data.lockMap.end() ) assert( it != m_data.lockMap.end() );
{ auto& lock = *it->second;
auto lm = m_slab.AllocInit<LockMap>();
lm->timeAnnounce = 0;
lm->timeTerminate = 0;
lm->valid = false;
lm->type = ev.type;
lm->isContended = false;
it = m_data.lockMap.emplace( ev.id, lm ).first;
}
auto lev = ev.type == LockType::Lockable ? m_slab.Alloc<LockEvent>() : m_slab.Alloc<LockEventShared>(); auto lev = lock.type == LockType::Lockable ? m_slab.Alloc<LockEvent>() : m_slab.Alloc<LockEventShared>();
const auto refTime = m_refTimeSerial + ev.time; const auto refTime = m_refTimeSerial + ev.time;
m_refTimeSerial = refTime; m_refTimeSerial = refTime;
const auto time = TscTime( refTime - m_data.baseTime ); const auto time = TscTime( refTime - m_data.baseTime );
@ -4638,7 +4608,7 @@ void Worker::ProcessLockWait( const QueueLockWait& ev )
lev->SetSrcLoc( 0 ); lev->SetSrcLoc( 0 );
lev->type = LockEvent::Type::Wait; lev->type = LockEvent::Type::Wait;
InsertLockEvent( *it->second, lev, ev.thread, time ); InsertLockEvent( lock, lev, ev.thread, time );
} }
void Worker::ProcessLockObtain( const QueueLockObtain& ev ) void Worker::ProcessLockObtain( const QueueLockObtain& ev )
@ -4678,16 +4648,10 @@ void Worker::ProcessLockRelease( const QueueLockRelease& ev )
void Worker::ProcessLockSharedWait( const QueueLockWait& ev ) void Worker::ProcessLockSharedWait( const QueueLockWait& ev )
{ {
auto it = m_data.lockMap.find( ev.id ); auto it = m_data.lockMap.find( ev.id );
if( it == m_data.lockMap.end() ) assert( it != m_data.lockMap.end() );
{ auto& lock = *it->second;
auto lm = m_slab.AllocInit<LockMap>();
lm->valid = false;
lm->type = ev.type;
lm->isContended = false;
it = m_data.lockMap.emplace( ev.id, lm ).first;
}
assert( ev.type == LockType::SharedLockable ); assert( lock.type == LockType::SharedLockable );
auto lev = m_slab.Alloc<LockEventShared>(); auto lev = m_slab.Alloc<LockEventShared>();
const auto refTime = m_refTimeSerial + ev.time; const auto refTime = m_refTimeSerial + ev.time;
m_refTimeSerial = refTime; m_refTimeSerial = refTime;
@ -4696,7 +4660,7 @@ void Worker::ProcessLockSharedWait( const QueueLockWait& ev )
lev->SetSrcLoc( 0 ); lev->SetSrcLoc( 0 );
lev->type = LockEvent::Type::WaitShared; lev->type = LockEvent::Type::WaitShared;
InsertLockEvent( *it->second, lev, ev.thread, time ); InsertLockEvent( lock, lev, ev.thread, time );
} }
void Worker::ProcessLockSharedObtain( const QueueLockObtain& ev ) void Worker::ProcessLockSharedObtain( const QueueLockObtain& ev )