Track number of held locks.

This commit is contained in:
Bartosz Taudul 2017-10-04 19:42:44 +02:00
parent 39bb9a3ad1
commit 4c8e9f7d5d
3 changed files with 30 additions and 1 deletions

View File

@ -41,6 +41,7 @@ struct LockEvent
int64_t time;
uint64_t thread;
uint8_t lockCount;
Type type;
};

View File

@ -681,11 +681,38 @@ void View::InsertLockEvent( Vector<LockEvent*>& timeline, LockEvent* lev )
if( timeline.empty() || timeline.back()->time < lev->time )
{
timeline.push_back( lev );
UpdateLockCount( timeline, timeline.size() - 1 );
}
else
{
auto it = std::lower_bound( timeline.begin(), timeline.end(), lev->time, [] ( const auto& lhs, const auto& rhs ) { return lhs->time < rhs; } );
timeline.insert( it, lev );
it = timeline.insert( it, lev );
UpdateLockCount( timeline, std::distance( timeline.begin(), it ) );
}
}
void View::UpdateLockCount( Vector<LockEvent*>& timeline, size_t pos )
{
uint8_t count = pos == 0 ? 0 : timeline[pos-1]->lockCount;
const auto end = timeline.size();
while( pos != end )
{
switch( timeline[pos]->type )
{
case LockEvent::Type::Obtain:
assert( count < std::numeric_limits<uint8_t>::max() );
count++;
break;
case LockEvent::Type::Release:
assert( count > 0 );
count--;
break;
default:
break;
}
timeline[pos]->lockCount = count;
pos++;
}
}

View File

@ -85,6 +85,7 @@ private:
void InsertZone( Event* zone, Event* parent, Vector<Event*>& vec );
void InsertLockEvent( Vector<LockEvent*>& timeline, LockEvent* lev );
void UpdateLockCount( Vector<LockEvent*>& timeline, size_t pos );
uint64_t GetFrameTime( size_t idx ) const;
uint64_t GetFrameBegin( size_t idx ) const;