From a48d54085450ced8e00381cfc93a8a21290d0cfd Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 1 Nov 2020 16:24:08 +0100 Subject: [PATCH] Cache statistics range-limited data. --- server/TracyView.cpp | 73 +++++++++++++++++++++++++++++--------------- server/TracyView.hpp | 11 +++++++ 2 files changed, 60 insertions(+), 24 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 34cca8b4..0c3d3059 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -11939,34 +11939,16 @@ void View::DrawStatistics() { if( !filterActive ) { - size_t cnt = 0; - int64_t total = 0; - int64_t selfTotal = 0; - for( auto& v : it->second.zones ) + auto cit = m_statCache.find( it->first ); + if( cit != m_statCache.end() && cit->second.range == m_statRange && cit->second.sourceCount == it->second.zones.size() ) { - auto& z = *v.Zone(); - const auto start = z.Start(); - const auto end = z.End(); - if( start >= min && end <= max ) + if( cit->second.count != 0 ) { - const auto zt = end - start; - total += zt; - if( m_statSelf ) selfTotal += zt - GetZoneChildTimeFast( z ); - cnt++; + slzcnt++; + srcloc.push_back_no_space_check( SrcLocZonesSlim { it->first, cit->second.count, cit->second.total, cit->second.selfTotal } ); } } - if( cnt != 0 ) - { - slzcnt++; - srcloc.push_back_no_space_check( SrcLocZonesSlim { it->first, cnt, total, selfTotal } ); - } - } - else - { - slzcnt++; - auto& sl = m_worker.GetSourceLocation( it->first ); - auto name = m_worker.GetString( sl.name.active ? sl.name : sl.function ); - if( m_statisticsFilter.PassFilter( name ) ) + else { size_t cnt = 0; int64_t total = 0; @@ -11986,8 +11968,51 @@ void View::DrawStatistics() } if( cnt != 0 ) { + slzcnt++; srcloc.push_back_no_space_check( SrcLocZonesSlim { it->first, cnt, total, selfTotal } ); } + m_statCache[it->first] = StatisticsCache { RangeSlim { m_statRange.min, m_statRange.max, m_statRange.active }, it->second.zones.size(), cnt, total, selfTotal }; + } + } + else + { + slzcnt++; + auto& sl = m_worker.GetSourceLocation( it->first ); + auto name = m_worker.GetString( sl.name.active ? sl.name : sl.function ); + if( m_statisticsFilter.PassFilter( name ) ) + { + auto cit = m_statCache.find( it->first ); + if( cit != m_statCache.end() && cit->second.range == m_statRange && cit->second.sourceCount == it->second.zones.size() ) + { + if( cit->second.count != 0 ) + { + srcloc.push_back_no_space_check( SrcLocZonesSlim { it->first, cit->second.count, cit->second.total, cit->second.selfTotal } ); + } + } + else + { + size_t cnt = 0; + int64_t total = 0; + int64_t selfTotal = 0; + for( auto& v : it->second.zones ) + { + auto& z = *v.Zone(); + const auto start = z.Start(); + const auto end = z.End(); + if( start >= min && end <= max ) + { + const auto zt = end - start; + total += zt; + if( m_statSelf ) selfTotal += zt - GetZoneChildTimeFast( z ); + cnt++; + } + } + if( cnt != 0 ) + { + srcloc.push_back_no_space_check( SrcLocZonesSlim { it->first, cnt, total, selfTotal } ); + } + m_statCache[it->first] = StatisticsCache { RangeSlim { m_statRange.min, m_statRange.max, m_statRange.active }, it->second.zones.size(), cnt, total, selfTotal }; + } } } } diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 9b333328..ae7cd429 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -56,6 +56,15 @@ class View uint64_t count; }; + struct StatisticsCache + { + RangeSlim range; + size_t sourceCount; + size_t count; + int64_t total; + int64_t selfTotal; + }; + public: struct VisData { @@ -468,6 +477,8 @@ private: RangeSlim m_setRangePopup; bool m_setRangePopupOpen = false; + unordered_flat_map m_statCache; + void(*m_cbMainThread)(std::function); struct FindZone {