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();