diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index 5a69034c..b09321d7 100755 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -41,6 +41,7 @@ struct LockEvent int64_t time; uint64_t thread; + uint8_t lockCount; Type type; }; diff --git a/server/TracyView.cpp b/server/TracyView.cpp index b519beca..ca6fecfd 100755 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -681,11 +681,38 @@ void View::InsertLockEvent( Vector& 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& 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::max() ); + count++; + break; + case LockEvent::Type::Release: + assert( count > 0 ); + count--; + break; + default: + break; + } + timeline[pos]->lockCount = count; + pos++; } } diff --git a/server/TracyView.hpp b/server/TracyView.hpp index c754804d..2009a921 100755 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -85,6 +85,7 @@ private: void InsertZone( Event* zone, Event* parent, Vector& vec ); void InsertLockEvent( Vector& timeline, LockEvent* lev ); + void UpdateLockCount( Vector& timeline, size_t pos ); uint64_t GetFrameTime( size_t idx ) const; uint64_t GetFrameBegin( size_t idx ) const;