From 48a07bf4f881d880b52b16f6aa6d3144f6c03beb Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 30 Mar 2019 00:52:25 +0100 Subject: [PATCH] Cache zone self times. --- server/TracyView.cpp | 26 ++++++++++++++++++++++---- server/TracyView.hpp | 7 +++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 8e7b86d5..6b4a053d 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -4437,7 +4437,7 @@ void View::DrawZoneInfoWindow() const auto end = m_worker.GetZoneEnd( ev ); const auto ztime = end - ev.start; - const auto selftime = ztime - GetZoneChildTime( ev ); + const auto selftime = GetZoneSelfTime( ev ); TextFocused( "Time from start of program:", TimeToString( ev.start - m_worker.GetTimeBegin() ) ); TextFocused( "Execution time:", TimeToString( ztime ) ); if( ImGui::IsItemHovered() ) @@ -5009,7 +5009,7 @@ void View::DrawGpuInfoWindow() const auto end = m_worker.GetZoneEnd( ev ); const auto ztime = end - ev.gpuStart; - const auto selftime = ztime - GetZoneChildTime( ev ); + const auto selftime = GetZoneSelfTime( ev ); TextFocused( "Time from start of program:", TimeToString( ev.gpuStart - m_worker.GetTimeBegin() ) ); TextFocused( "GPU execution time:", TimeToString( ztime ) ); TextFocused( "GPU self time:", TimeToString( selftime ) ); @@ -9850,7 +9850,7 @@ void View::ZoneTooltip( const ZoneEvent& ev ) auto& srcloc = m_worker.GetSourceLocation( ev.srcloc ); const auto end = m_worker.GetZoneEnd( ev ); const auto ztime = end - ev.start; - const auto selftime = ztime - GetZoneChildTime( ev ); + const auto selftime = GetZoneSelfTime( ev ); ImGui::BeginTooltip(); if( ev.name.active ) @@ -9899,7 +9899,7 @@ void View::ZoneTooltip( const GpuEvent& ev ) const auto& srcloc = m_worker.GetSourceLocation( ev.srcloc ); const auto end = m_worker.GetZoneEnd( ev ); const auto ztime = end - ev.gpuStart; - const auto selftime = ztime - GetZoneChildTime( ev ); + const auto selftime = GetZoneSelfTime( ev ); ImGui::BeginTooltip(); ImGui::TextUnformatted( m_worker.GetString( srcloc.name ) ); @@ -10262,4 +10262,22 @@ int64_t View::GetZoneChildTimeFast( const ZoneEvent& zone ) return time; } +int64_t View::GetZoneSelfTime( const ZoneEvent& zone ) +{ + if( m_cache.zoneSelfTime.first == &zone ) return m_cache.zoneSelfTime.second; + const auto ztime = m_worker.GetZoneEnd( zone ) - zone.start; + const auto selftime = ztime - GetZoneChildTime( zone ); + if( zone.end >= 0 ) m_cache.zoneSelfTime = std::make_pair( &zone, selftime ); + return selftime; +} + +int64_t View::GetZoneSelfTime( const GpuEvent& zone ) +{ + if( m_cache.gpuSelfTime.first == &zone ) return m_cache.gpuSelfTime.second; + const auto ztime = m_worker.GetZoneEnd( zone ) - zone.gpuStart; + const auto selftime = ztime - GetZoneChildTime( zone ); + if( zone.gpuEnd >= 0 ) m_cache.gpuSelfTime = std::make_pair( &zone, selftime ); + return selftime; +} + } diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 9a649117..e2544c93 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -188,6 +188,8 @@ private: int64_t GetZoneChildTime( const ZoneEvent& zone ); int64_t GetZoneChildTime( const GpuEvent& zone ); int64_t GetZoneChildTimeFast( const ZoneEvent& zone ); + int64_t GetZoneSelfTime( const ZoneEvent& zone ); + int64_t GetZoneSelfTime( const GpuEvent& zone ); flat_hash_map> m_visData; flat_hash_map> m_visibleMsgThread; @@ -472,6 +474,11 @@ private: std::unique_ptr bins; bool drawAvgMed = true; } m_frameSortData; + + struct { + std::pair zoneSelfTime = { nullptr, 0 }; + std::pair gpuSelfTime = { nullptr, 0 }; + } m_cache; }; }