From 2714152f840cf671dc431f0adbc641dec57a1550 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 8 Sep 2019 14:16:12 +0200 Subject: [PATCH] Allow calculating zone depth. --- server/TracyView.cpp | 18 ++++++++++++++++++ server/TracyView.hpp | 1 + 2 files changed, 19 insertions(+) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index f9616c12..2eef371d 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -12222,6 +12222,24 @@ void View::CrashTooltip() ImGui::EndTooltip(); } +int View::GetZoneDepth( const ZoneEvent& zone, uint64_t tid ) const +{ + auto td = m_worker.GetThreadData( tid ); + assert( td ); + auto timeline = &td->timeline; + int depth = 0; + for(;;) + { + auto it = std::upper_bound( timeline->begin(), timeline->end(), zone.Start(), [] ( const auto& l, const auto& r ) { return l < r->Start(); } ); + if( it != timeline->begin() ) --it; + assert( !( zone.end >= 0 && (*it)->Start() > zone.end ) ); + if( *it == &zone ) return depth; + assert( (*it)->child >= 0 ); + timeline = &m_worker.GetZoneChildren( (*it)->child ); + depth++; + } +} + const ZoneEvent* View::GetZoneParent( const ZoneEvent& zone ) const { for( const auto& thread : m_worker.GetThreadData() ) diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 35edf974..acc78933 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -178,6 +178,7 @@ private: void CallstackTooltip( uint32_t idx ); void CrashTooltip(); + int GetZoneDepth( const ZoneEvent& zone, uint64_t tid ) const; const ZoneEvent* GetZoneParent( const ZoneEvent& zone ) const; const GpuEvent* GetZoneParent( const GpuEvent& zone ) const; const ThreadData* GetZoneThreadData( const ZoneEvent& zone ) const;