From 54735bacea4a71963bbba1527222be6d6c28513f Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 4 Oct 2017 18:51:50 +0200 Subject: [PATCH] Lock events dispatch. --- server/TracyEvent.hpp | 9 ------- server/TracyView.cpp | 59 +++++++++++++++++++++++++++++++++++++------ server/TracyView.hpp | 7 +++-- 3 files changed, 56 insertions(+), 19 deletions(-) diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index 6784d444..5a69034c 100755 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -46,15 +46,6 @@ struct LockEvent enum { LockEventSize = sizeof( LockEvent ) }; - -struct LockTimeline -{ - uint64_t id; - Vector timeline; -}; - -enum { LockTimelineSize = sizeof( LockTimeline ) }; - #pragma pack() } diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 5e246293..31933d09 100755 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -457,41 +457,80 @@ void View::ProcessLockAnnounce( const QueueLockAnnounce& ev ) { CheckSourceLocation( ev.srcloc ); - std::lock_guard lock( m_lock ); assert( m_lockMap.find( ev.id ) == m_lockMap.end() ); - m_lockMap.emplace( ev.id, LockMap { ev.srcloc } ); + auto it = m_pendingLocks.find( ev.id ); + + std::unique_lock lock( m_lock ); + auto& lockmap = m_lockMap.emplace( ev.id, LockMap { ev.id, ev.srcloc } ).first->second; + + if( it != m_pendingLocks.end() ) + { + for( auto& v : it->second ) + { + InsertLockEvent( lockmap.timeline, v ); + } + lock.unlock(); + m_pendingLocks.erase( it ); + } } void View::ProcessLockWait( const QueueLockWait& ev ) { + auto lev = m_slab.Alloc(); + lev->time = ev.time; + lev->thread = ev.thread; + lev->type = LockEvent::Type::Wait; + auto it = m_lockMap.find( ev.id ); if( it == m_lockMap.end() ) { auto& v = m_pendingLocks[ev.id]; - v.push_back( LockEvent { ev.time, ev.thread, LockEvent::Type::Wait } ); - return; + v.push_back( lev ); + } + else + { + std::lock_guard lock( m_lock ); + InsertLockEvent( it->second.timeline, lev ); } } void View::ProcessLockObtain( const QueueLockObtain& ev ) { + auto lev = m_slab.Alloc(); + lev->time = ev.time; + lev->thread = ev.thread; + lev->type = LockEvent::Type::Obtain; + auto it = m_lockMap.find( ev.id ); if( it == m_lockMap.end() ) { auto& v = m_pendingLocks[ev.id]; - v.push_back( LockEvent { ev.time, ev.thread, LockEvent::Type::Obtain } ); - return; + v.push_back( lev ); + } + else + { + std::lock_guard lock( m_lock ); + InsertLockEvent( it->second.timeline, lev ); } } void View::ProcessLockRelease( const QueueLockRelease& ev ) { + auto lev = m_slab.Alloc(); + lev->time = ev.time; + lev->thread = ev.thread; + lev->type = LockEvent::Type::Release; + auto it = m_lockMap.find( ev.id ); if( it == m_lockMap.end() ) { auto& v = m_pendingLocks[ev.id]; - v.push_back( LockEvent { ev.time, ev.thread, LockEvent::Type::Release } ); - return; + v.push_back( lev ); + } + else + { + std::lock_guard lock( m_lock ); + InsertLockEvent( it->second.timeline, lev ); } } @@ -637,6 +676,10 @@ void View::InsertZone( Event* zone, Event* parent, Vector& vec ) } } +void View::InsertLockEvent( Vector& timeline, const LockEvent* lev ) +{ +} + uint64_t View::GetFrameTime( size_t idx ) const { if( idx < m_frames.size() - 1 ) diff --git a/server/TracyView.hpp b/server/TracyView.hpp index c920baa7..2f5e01a7 100755 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -46,8 +46,9 @@ private: struct LockMap { + uint64_t id; uint64_t srcloc; - LockTimeline ev; + Vector timeline; }; void Worker(); @@ -83,6 +84,8 @@ private: void InsertZone( Event* zone, Event* parent, Vector& vec ); + void InsertLockEvent( Vector& timeline, const LockEvent* lev ); + uint64_t GetFrameTime( size_t idx ) const; uint64_t GetFrameBegin( size_t idx ) const; uint64_t GetFrameEnd( size_t idx ) const; @@ -143,7 +146,7 @@ private: std::unordered_set m_pendingSourceLocation; std::unordered_map m_pendingCustomStrings; std::unordered_map m_threadMap; - std::unordered_map> m_pendingLocks; + std::unordered_map> m_pendingLocks; Slab m_slab;