From b07718ab9e338028e79a6fed0e540b37a8ba0e15 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 10 Dec 2017 22:42:39 +0100 Subject: [PATCH] Track list of shared locks. --- server/TracyEvent.hpp | 6 +++++- server/TracyView.cpp | 25 ++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index 18ab072a..cbff0572 100644 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -100,7 +100,10 @@ struct LockEvent { Wait, Obtain, - Release + Release, + WaitShared, + ObtainShared, + ReleaseShared }; int64_t time; @@ -110,6 +113,7 @@ struct LockEvent Type type; uint8_t lockCount; uint64_t waitList; + uint64_t sharedList; }; enum { LockEventSize = sizeof( LockEvent ) }; diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 733cd83b..83e28ffe 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -793,7 +793,7 @@ void View::ProcessLockSharedWait( const QueueLockWait& ev ) { auto lev = m_slab.Alloc(); lev->time = ev.time * m_timerMul; - lev->type = LockEvent::Type::Wait; + lev->type = LockEvent::Type::WaitShared; lev->srcloc = 0; auto it = m_lockMap.find( ev.id ); @@ -811,7 +811,7 @@ void View::ProcessLockSharedObtain( const QueueLockObtain& ev ) { auto lev = m_slab.Alloc(); lev->time = ev.time * m_timerMul; - lev->type = LockEvent::Type::Obtain; + lev->type = LockEvent::Type::ObtainShared; lev->srcloc = 0; assert( m_lockMap.find( ev.id ) != m_lockMap.end() ); @@ -822,7 +822,7 @@ void View::ProcessLockSharedRelease( const QueueLockRelease& ev ) { auto lev = m_slab.Alloc(); lev->time = ev.time * m_timerMul; - lev->type = LockEvent::Type::Release; + lev->type = LockEvent::Type::ReleaseShared; lev->srcloc = 0; assert( m_lockMap.find( ev.id ) != m_lockMap.end() ); @@ -847,7 +847,9 @@ void View::ProcessLockMark( const QueueLockMark& ev ) switch( (*it)->type ) { case LockEvent::Type::Obtain: + case LockEvent::Type::ObtainShared: case LockEvent::Type::Wait: + case LockEvent::Type::WaitShared: (*it)->srcloc = ShrinkSourceLocation( ev.srcloc ); return; default: @@ -1334,12 +1336,14 @@ void View::UpdateLockCount( LockMap& lockmap, size_t pos ) uint8_t lockingThread; uint8_t lockCount; uint64_t waitList; + uint64_t sharedList; if( pos == 0 ) { lockingThread = 0; lockCount = 0; waitList = 0; + sharedList = 0; } else { @@ -1347,9 +1351,12 @@ void View::UpdateLockCount( LockMap& lockmap, size_t pos ) lockingThread = tl->lockingThread; lockCount = tl->lockCount; waitList = tl->waitList; + sharedList = tl->sharedList; } const auto end = timeline.size(); + // ObtainShared and ReleaseShared should assert on lockCount == 0, but + // due to the async retrieval of data from threads that not possible. while( pos != end ) { const auto tl = timeline[pos]; @@ -1357,6 +1364,7 @@ void View::UpdateLockCount( LockMap& lockmap, size_t pos ) switch( (LockEvent::Type)tl->type ) { case LockEvent::Type::Wait: + case LockEvent::Type::WaitShared: waitList |= tbit; break; case LockEvent::Type::Obtain: @@ -1370,11 +1378,22 @@ void View::UpdateLockCount( LockMap& lockmap, size_t pos ) assert( lockCount > 0 ); lockCount--; break; + case LockEvent::Type::ObtainShared: + assert( ( waitList & tbit ) != 0 ); + assert( ( sharedList & tbit ) == 0 ); + waitList &= ~tbit; + sharedList |= tbit; + break; + case LockEvent::Type::ReleaseShared: + assert( ( sharedList & tbit ) != 0 ); + sharedList &= ~tbit; + break; default: break; } tl->lockingThread = lockingThread; tl->waitList = waitList; + tl->sharedList = sharedList; tl->lockCount = lockCount; assert( tl->lockingThread == lockingThread ); pos++;