From 4c8e9f7d5dbce1092eefaa394a8e83078a7f52f7 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 4 Oct 2017 19:42:44 +0200 Subject: [PATCH] Track number of held locks. --- server/TracyEvent.hpp | 1 + server/TracyView.cpp | 29 ++++++++++++++++++++++++++++- server/TracyView.hpp | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) 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;