From 5c379603b5e3d02f6e6c217d1c9c18b5e37f68d2 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 29 Nov 2021 19:23:31 +0100 Subject: [PATCH] Move onlyActive check out of the loops. --- server/TracyView.cpp | 82 ++++++++++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 22 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index a33fbb5f..712fa509 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -17049,42 +17049,80 @@ unordered_flat_map View::GetCallstackPaths( const M if( it != mem.data.end() ) { auto end = std::lower_bound( mem.data.begin(), mem.data.end(), m_memInfo.range.max, []( const auto& lhs, const auto& rhs ) { return lhs.TimeAlloc() < rhs; } ); - while( it != end ) + if( onlyActive ) { - auto& ev = *it++; - - if( ev.CsAlloc() == 0 ) continue; - if( onlyActive && ev.TimeFree() >= 0 && ev.TimeFree() < m_memInfo.range.max ) continue; - - auto pit = pathSum.find( ev.CsAlloc() ); - if( pit == pathSum.end() ) + while( it != end ) { - pathSum.emplace( ev.CsAlloc(), MemPathData { 1, ev.Size() } ); + auto& ev = *it++; + if( ev.CsAlloc() == 0 ) continue; + if( ev.TimeFree() >= 0 && ev.TimeFree() < m_memInfo.range.max ) continue; + auto pit = pathSum.find( ev.CsAlloc() ); + if( pit == pathSum.end() ) + { + pathSum.emplace( ev.CsAlloc(), MemPathData { 1, ev.Size() } ); + } + else + { + pit->second.cnt++; + pit->second.mem += ev.Size(); + } } - else + } + else + { + while( it != end ) { - pit->second.cnt++; - pit->second.mem += ev.Size(); + auto& ev = *it++; + if( ev.CsAlloc() == 0 ) continue; + auto pit = pathSum.find( ev.CsAlloc() ); + if( pit == pathSum.end() ) + { + pathSum.emplace( ev.CsAlloc(), MemPathData { 1, ev.Size() } ); + } + else + { + pit->second.cnt++; + pit->second.mem += ev.Size(); + } } } } } else { - for( auto& ev : mem.data ) + if( onlyActive ) { - if( ev.CsAlloc() == 0 ) continue; - if( onlyActive && ev.TimeFree() >= 0 ) continue; - - auto it = pathSum.find( ev.CsAlloc() ); - if( it == pathSum.end() ) + for( auto& ev : mem.data ) { - pathSum.emplace( ev.CsAlloc(), MemPathData { 1, ev.Size() } ); + if( ev.CsAlloc() == 0 ) continue; + if( ev.TimeFree() >= 0 ) continue; + auto it = pathSum.find( ev.CsAlloc() ); + if( it == pathSum.end() ) + { + pathSum.emplace( ev.CsAlloc(), MemPathData { 1, ev.Size() } ); + } + else + { + it->second.cnt++; + it->second.mem += ev.Size(); + } } - else + } + else + { + for( auto& ev : mem.data ) { - it->second.cnt++; - it->second.mem += ev.Size(); + if( ev.CsAlloc() == 0 ) continue; + auto it = pathSum.find( ev.CsAlloc() ); + if( it == pathSum.end() ) + { + pathSum.emplace( ev.CsAlloc(), MemPathData { 1, ev.Size() } ); + } + else + { + it->second.cnt++; + it->second.mem += ev.Size(); + } } } }