From 912cfdbc5ef0e31c029e80b9966baa2249395085 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 1 Apr 2018 21:47:08 +0200 Subject: [PATCH] Search for zone present in given thread at given time. --- server/TracyView.cpp | 28 ++++++++++++++++++++++++++++ server/TracyView.hpp | 1 + 2 files changed, 29 insertions(+) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 26f9ac78..f08c9647 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -4048,6 +4048,34 @@ uint64_t View::GetZoneThread( const GpuEvent& zone ) const return 0; } +const ZoneEvent* View::FindZoneAtTime( uint64_t thread, int64_t time ) const +{ + // TODO add thread rev-map + ThreadData* td = nullptr; + for( const auto& t : m_worker.GetThreadData() ) + { + if( t->id == thread ) + { + td = t; + break; + } + } + if( !td ) return nullptr; + + const Vector* timeline = &td->timeline; + if( timeline->empty() ) return nullptr; + ZoneEvent* ret = nullptr; + for(;;) + { + auto it = std::upper_bound( timeline->begin(), timeline->end(), time, [] ( const auto& l, const auto& r ) { return l < r->start; } ); + if( it != timeline->begin() ) --it; + if( (*it)->start > time || ( (*it)->end >= 0 && (*it)->end < time ) ) return ret; + ret = *it; + if( (*it)->child.empty() ) return ret; + timeline = &(*it)->child; + } +} + #ifndef TRACY_NO_STATISTICS void View::FindZones() { diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 7f6480a0..159484fc 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -99,6 +99,7 @@ private: const GpuEvent* GetZoneParent( const GpuEvent& zone ) const; uint64_t GetZoneThread( const ZoneEvent& zone ) const; uint64_t GetZoneThread( const GpuEvent& zone ) const; + const ZoneEvent* FindZoneAtTime( uint64_t thread, int64_t time ) const; #ifndef TRACY_NO_STATISTICS void FindZones();