Lock events dispatch.

This commit is contained in:
Bartosz Taudul 2017-10-04 18:51:50 +02:00
parent 110e5971d1
commit 54735bacea
3 changed files with 56 additions and 19 deletions

View File

@ -46,15 +46,6 @@ struct LockEvent
enum { LockEventSize = sizeof( LockEvent ) };
struct LockTimeline
{
uint64_t id;
Vector<LockEvent*> timeline;
};
enum { LockTimelineSize = sizeof( LockTimeline ) };
#pragma pack()
}

View File

@ -457,41 +457,80 @@ void View::ProcessLockAnnounce( const QueueLockAnnounce& ev )
{
CheckSourceLocation( ev.srcloc );
std::lock_guard<std::mutex> 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<std::mutex> 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<LockEvent>();
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<std::mutex> lock( m_lock );
InsertLockEvent( it->second.timeline, lev );
}
}
void View::ProcessLockObtain( const QueueLockObtain& ev )
{
auto lev = m_slab.Alloc<LockEvent>();
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<std::mutex> lock( m_lock );
InsertLockEvent( it->second.timeline, lev );
}
}
void View::ProcessLockRelease( const QueueLockRelease& ev )
{
auto lev = m_slab.Alloc<LockEvent>();
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<std::mutex> lock( m_lock );
InsertLockEvent( it->second.timeline, lev );
}
}
@ -637,6 +676,10 @@ void View::InsertZone( Event* zone, Event* parent, Vector<Event*>& vec )
}
}
void View::InsertLockEvent( Vector<LockEvent*>& timeline, const LockEvent* lev )
{
}
uint64_t View::GetFrameTime( size_t idx ) const
{
if( idx < m_frames.size() - 1 )

View File

@ -46,8 +46,9 @@ private:
struct LockMap
{
uint64_t id;
uint64_t srcloc;
LockTimeline ev;
Vector<LockEvent*> timeline;
};
void Worker();
@ -83,6 +84,8 @@ private:
void InsertZone( Event* zone, Event* parent, Vector<Event*>& vec );
void InsertLockEvent( Vector<LockEvent*>& 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<uint64_t> m_pendingSourceLocation;
std::unordered_map<uint64_t, Event*> m_pendingCustomStrings;
std::unordered_map<uint64_t, uint32_t> m_threadMap;
std::unordered_map<uint64_t, std::vector<LockEvent>> m_pendingLocks;
std::unordered_map<uint64_t, std::vector<LockEvent*>> m_pendingLocks;
Slab<EventSize*1024*1024> m_slab;