From 737671adbf2892ae95b2576bd54f1b2e867b6beb Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 12 Oct 2017 20:14:17 +0200 Subject: [PATCH] Remove lock announce message. This removes problem with static initialization order of mutices vs tracy. Lock source location is now transferred in lock wait message. --- client/TracyLock.hpp | 11 +++-------- common/TracyQueue.hpp | 10 +--------- server/TracyView.cpp | 23 ++++++++++++----------- server/TracyView.hpp | 1 - 4 files changed, 16 insertions(+), 29 deletions(-) diff --git a/client/TracyLock.hpp b/client/TracyLock.hpp index 844832d3..9745ff56 100644 --- a/client/TracyLock.hpp +++ b/client/TracyLock.hpp @@ -17,15 +17,8 @@ class Lockable public: tracy_force_inline Lockable( const SourceLocation* srcloc ) : m_id( s_lockCounter.fetch_add( 1, std::memory_order_relaxed ) ) + , m_lckloc( (uint64_t)srcloc ) { - Magic magic; - auto& token = s_token.ptr; - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - item->hdr.type = QueueType::LockAnnounce; - item->lockAnnounce.id = m_id; - item->lockAnnounce.srcloc = (uint64_t)srcloc; - tail.store( magic + 1, std::memory_order_release ); } Lockable( const Lockable& ) = delete; @@ -44,6 +37,7 @@ public: item->lockWait.id = m_id; item->lockWait.thread = thread; item->lockWait.time = Profiler::GetTime( cpu ); + item->lockWait.lckloc = m_lckloc; tail.store( magic + 1, std::memory_order_release ); } @@ -113,6 +107,7 @@ public: private: T m_lockable; uint64_t m_id; + uint64_t m_lckloc; }; }; diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index e657dee3..b452e983 100644 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -17,7 +17,6 @@ enum class QueueType : uint8_t SourceLocation, ZoneText, ZoneName, - LockAnnounce, LockWait, LockObtain, LockRelease, @@ -73,17 +72,12 @@ struct QueueZoneName uint64_t name; // ptr }; -struct QueueLockAnnounce -{ - uint64_t id; - uint64_t srcloc; // ptr -}; - struct QueueLockWait { uint64_t id; int64_t time; uint64_t thread; + uint64_t lckloc; // ptr }; struct QueueLockObtain @@ -128,7 +122,6 @@ struct QueueItem QueueSourceLocation srcloc; QueueZoneText zoneText; QueueZoneName zoneName; - QueueLockAnnounce lockAnnounce; QueueLockWait lockWait; QueueLockObtain lockObtain; QueueLockRelease lockRelease; @@ -150,7 +143,6 @@ static const size_t QueueDataSize[] = { sizeof( QueueHeader ) + sizeof( QueueSourceLocation ), sizeof( QueueHeader ) + sizeof( QueueZoneText ), sizeof( QueueHeader ) + sizeof( QueueZoneName ), - sizeof( QueueHeader ) + sizeof( QueueLockAnnounce ), sizeof( QueueHeader ) + sizeof( QueueLockWait ), sizeof( QueueHeader ) + sizeof( QueueLockObtain ), sizeof( QueueHeader ) + sizeof( QueueLockRelease ), diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 5ce54f26..d3dbfc9d 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -416,9 +416,6 @@ void View::Process( const QueueItem& ev ) case QueueType::ZoneName: ProcessZoneName( ev.zoneName ); break; - case QueueType::LockAnnounce: - ProcessLockAnnounce( ev.lockAnnounce ); - break; case QueueType::LockWait: ProcessLockWait( ev.lockWait ); break; @@ -500,13 +497,6 @@ void View::ProcessZoneName( const QueueZoneName& ev ) GetTextData( *zone )->zoneName = ev.name; } -void View::ProcessLockAnnounce( const QueueLockAnnounce& ev ) -{ - CheckSourceLocation( ev.srcloc ); - std::lock_guard lock( m_lock ); - m_lockMap[ev.id].srcloc = ev.srcloc; -} - void View::ProcessLockWait( const QueueLockWait& ev ) { auto lev = m_slab.Alloc(); @@ -514,8 +504,19 @@ void View::ProcessLockWait( const QueueLockWait& ev ) lev->type = LockEvent::Type::Wait; lev->srcloc = 0; + auto it = m_lockMap.find( ev.id ); std::lock_guard lock( m_lock ); - InsertLockEvent( m_lockMap[ev.id], lev, ev.thread ); + if( it == m_lockMap.end() ) + { + it = m_lockMap.emplace( ev.id, LockMap { ev.lckloc } ).first; + CheckSourceLocation( ev.lckloc ); + } + else if( it->second.srcloc == 0 ) + { + it->second.srcloc = ev.lckloc; + CheckSourceLocation( ev.lckloc ); + } + InsertLockEvent( it->second, lev, ev.thread ); } void View::ProcessLockObtain( const QueueLockObtain& ev ) diff --git a/server/TracyView.hpp b/server/TracyView.hpp index ebda7cc7..e23b41f0 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -75,7 +75,6 @@ private: void ProcessFrameMark( const QueueFrameMark& ev ); void ProcessZoneText( const QueueZoneText& ev ); void ProcessZoneName( const QueueZoneName& ev ); - void ProcessLockAnnounce( const QueueLockAnnounce& ev ); void ProcessLockWait( const QueueLockWait& ev ); void ProcessLockObtain( const QueueLockObtain& ev ); void ProcessLockRelease( const QueueLockRelease& ev );