From 858c94e12e79670eb37606e5732f88c12ace7d5a Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 14 Aug 2019 17:54:50 +0200 Subject: [PATCH] Add interface for calculation zone running time. --- server/TracyView.cpp | 19 +++++++++++++++++++ server/TracyView.hpp | 1 + 2 files changed, 20 insertions(+) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 77cedf78..2f6a5687 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -11483,4 +11483,23 @@ int64_t View::GetZoneSelfTime( const GpuEvent& zone ) return selftime; } +bool View::GetZoneRunningTime( const ContextSwitch* ctx, const ZoneEvent& ev, int64_t& time, uint64_t& cnt ) +{ + auto it = std::lower_bound( ctx->v.begin(), ctx->v.end(), ev.start, [] ( const auto& l, const auto& r ) { return (uint64_t)l.end < (uint64_t)r; } ); + if( it == ctx->v.end() ) return false; + const auto end = m_worker.GetZoneEnd( ev ); + const auto eit = std::upper_bound( it, ctx->v.end(), end, [] ( const auto& l, const auto& r ) { return l < r.start; } ); + cnt = std::distance( it, eit ); + int64_t running = 0; + while( it < eit ) + { + const auto t0 = std::max( ev.start, it->start ); + const auto t1 = (int64_t)std::min( end, it->end ); + running += t1 - t0; + ++it; + } + time = running; + return true; +} + } diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 619558e5..d89afcde 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -196,6 +196,7 @@ private: int64_t GetZoneChildTimeFast( const ZoneEvent& zone ); int64_t GetZoneSelfTime( const ZoneEvent& zone ); int64_t GetZoneSelfTime( const GpuEvent& zone ); + bool GetZoneRunningTime( const ContextSwitch* ctx, const ZoneEvent& ev, int64_t& time, uint64_t& cnt ); void SetPlaybackFrame( uint32_t idx );