diff --git a/client/TracyLock.hpp b/client/TracyLock.hpp index db791ecb..e9345941 100644 --- a/client/TracyLock.hpp +++ b/client/TracyLock.hpp @@ -18,9 +18,18 @@ 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 ) { assert( m_id != std::numeric_limits::max() ); + + 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.lckloc = (uint64_t)srcloc; + item->lockAnnounce.type = LockType::Lockable; + tail.store( magic + 1, std::memory_order_release ); } Lockable( const Lockable& ) = delete; @@ -38,7 +47,6 @@ public: item->lockWait.id = m_id; item->lockWait.thread = thread; item->lockWait.time = Profiler::GetTime(); - item->lockWait.lckloc = m_lckloc; tail.store( magic + 1, std::memory_order_release ); } @@ -106,7 +114,6 @@ public: private: T m_lockable; uint32_t m_id; - uint64_t m_lckloc; }; }; diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index e9495301..31c39c3c 100644 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -16,6 +16,7 @@ enum class QueueType : uint8_t ZoneEnd, FrameMarkMsg, SourceLocation, + LockAnnounce, LockWait, LockObtain, LockRelease, @@ -79,12 +80,23 @@ struct QueueZoneText uint64_t text; // ptr }; +enum class LockType : uint8_t +{ + Lockable +}; + +struct QueueLockAnnounce +{ + uint32_t id; + uint64_t lckloc; // ptr + LockType type; +}; + struct QueueLockWait { uint32_t id; int64_t time; uint64_t thread; - uint64_t lckloc; // ptr }; struct QueueLockObtain @@ -190,6 +202,7 @@ struct QueueItem QueueFrameMark frameMark; QueueSourceLocation srcloc; QueueZoneText zoneText; + QueueLockAnnounce lockAnnounce; QueueLockWait lockWait; QueueLockObtain lockObtain; QueueLockRelease lockRelease; @@ -218,6 +231,7 @@ static const size_t QueueDataSize[] = { sizeof( QueueHeader ) + sizeof( QueueZoneEnd ), sizeof( QueueHeader ) + sizeof( QueueFrameMark ), sizeof( QueueHeader ) + sizeof( QueueSourceLocation ), + sizeof( QueueHeader ) + sizeof( QueueLockAnnounce ), sizeof( QueueHeader ) + sizeof( QueueLockWait ), sizeof( QueueHeader ) + sizeof( QueueLockObtain ), sizeof( QueueHeader ) + sizeof( QueueLockRelease ), diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index 49b2853c..7fb5ae04 100644 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -177,7 +177,9 @@ struct LockMap Vector timeline; std::unordered_map threadMap; std::vector threadList; + LockType type; bool visible; + bool valid; }; struct LockHighlight diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 05b1accb..ab36cbfd 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -296,6 +296,8 @@ View::View( FileRead& f ) uint64_t tsz; f.Read( &id, sizeof( id ) ); f.Read( &lockmap.srcloc, sizeof( lockmap.srcloc ) ); + f.Read( &lockmap.type, sizeof( lockmap.type ) ); + f.Read( &lockmap.valid, sizeof( lockmap.valid ) ); f.Read( &tsz, sizeof( tsz ) ); for( uint64_t i=0; isecond.srcloc = ShrinkSourceLocation( ev.lckloc ); + it->second.type = ev.type; + it->second.visible = true; + it->second.valid = true; + } + CheckSourceLocation( ev.lckloc ); +} + void View::ProcessLockWait( const QueueLockWait& ev ) { auto lev = m_slab.Alloc(); @@ -724,16 +751,10 @@ void View::ProcessLockWait( const QueueLockWait& ev ) if( it == m_lockMap.end() ) { LockMap lm; - lm.srcloc = ShrinkSourceLocation( ev.lckloc ); - lm.visible = true; + lm.valid = false; it = m_lockMap.emplace( ev.id, std::move( lm ) ).first; - CheckSourceLocation( ev.lckloc ); - } - else if( it->second.srcloc == 0 ) - { - it->second.srcloc = ShrinkSourceLocation( ev.lckloc ); - CheckSourceLocation( ev.lckloc ); } + InsertLockEvent( it->second, lev, ev.thread ); } @@ -744,6 +765,7 @@ void View::ProcessLockObtain( const QueueLockObtain& ev ) lev->type = (uint8_t)LockEvent::Type::Obtain; lev->srcloc = 0; + assert( m_lockMap.find( ev.id ) != m_lockMap.end() ); InsertLockEvent( m_lockMap[ev.id], lev, ev.thread ); } @@ -754,6 +776,7 @@ void View::ProcessLockRelease( const QueueLockRelease& ev ) lev->type = (uint8_t)LockEvent::Type::Release; lev->srcloc = 0; + assert( m_lockMap.find( ev.id ) != m_lockMap.end() ); InsertLockEvent( m_lockMap[ev.id], lev, ev.thread ); } @@ -2859,7 +2882,7 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos, for( auto& v : m_lockMap ) { auto& lockmap = v.second; - if( !lockmap.visible ) continue; + if( !lockmap.visible || !lockmap.valid ) continue; auto it = lockmap.threadMap.find( tid ); if( it == lockmap.threadMap.end() ) continue; @@ -3597,9 +3620,12 @@ void View::DrawOptions() ImGui::Indent( tw ); for( auto& l : m_lockMap ) { - char buf[1024]; - sprintf( buf, "%" PRIu32 ": %s", l.first, GetString( GetSourceLocation( l.second.srcloc ).function ) ); - ImGui::Checkbox( buf , &l.second.visible ); + if( l.second.valid ) + { + char buf[1024]; + sprintf( buf, "%" PRIu32 ": %s", l.first, GetString( GetSourceLocation( l.second.srcloc ).function ) ); + ImGui::Checkbox( buf , &l.second.visible ); + } } ImGui::Unindent( tw ); ImGui::Separator(); @@ -3951,6 +3977,8 @@ void View::Write( FileWrite& f ) { f.Write( &v.first, sizeof( v.first ) ); f.Write( &v.second.srcloc, sizeof( v.second.srcloc ) ); + f.Write( &v.second.type, sizeof( v.second.type ) ); + f.Write( &v.second.valid, sizeof( v.second.valid ) ); sz = v.second.threadList.size(); f.Write( &sz, sizeof( sz ) ); for( auto& t : v.second.threadList ) diff --git a/server/TracyView.hpp b/server/TracyView.hpp index b4891103..22b6c364 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -74,6 +74,7 @@ private: tracy_force_inline void ProcessZoneEnd( const QueueZoneEnd& ev ); tracy_force_inline void ProcessFrameMark( const QueueFrameMark& ev ); tracy_force_inline void ProcessZoneText( const QueueZoneText& ev ); + tracy_force_inline void ProcessLockAnnounce( const QueueLockAnnounce& ev ); tracy_force_inline void ProcessLockWait( const QueueLockWait& ev ); tracy_force_inline void ProcessLockObtain( const QueueLockObtain& ev ); tracy_force_inline void ProcessLockRelease( const QueueLockRelease& ev );