From 01985f50efc7e6348680334a7970536128d76ffc Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 26 Oct 2019 16:30:13 +0200 Subject: [PATCH] Cache source location zones counter search. --- server/TracyWorker.cpp | 24 ++++++++++++++++++------ server/TracyWorker.hpp | 9 +++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index ca1bca3b..235b6bb9 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -2609,7 +2609,9 @@ int16_t Worker::NewShrinkedSourceLocation( uint64_t srcloc ) m_data.srclocZonesLast.first = sz; m_data.srclocZonesLast.second = &res.first->second; #else - m_data.sourceLocationZonesCnt.emplace( sz, 0 ); + auto res = m_data.sourceLocationZonesCnt.emplace( sz, 0 ); + m_data.srclocCntLast.first = sz; + m_data.srclocCntLast.second = &res.first->second; #endif m_sourceLocationShrink.emplace( srcloc, sz ); m_data.shrinkSrclocLast.first = srcloc; @@ -2688,6 +2690,15 @@ Worker::SourceLocationZones* Worker::GetSourceLocationZonesReal( uint16_t srcloc m_data.srclocZonesLast.second = &it->second; return &it->second; } +#else +uint64_t* Worker::GetSourceLocationZonesCntReal( uint16_t srcloc ) +{ + auto it = m_data.sourceLocationZonesCnt.find( srcloc ); + assert( it != m_data.sourceLocationZonesCnt.end() ); + m_data.srclocCntLast.first = srcloc; + m_data.srclocCntLast.second = &it->second; + return &it->second; +} #endif const ThreadData* Worker::GetThreadData( uint64_t tid ) const @@ -2721,9 +2732,8 @@ void Worker::NewZone( ZoneEvent* zone, uint64_t thread ) ztd.SetZone( zone ); ztd.SetThread( CompressThread( thread ) ); #else - auto it = m_data.sourceLocationZonesCnt.find( zone->SrcLoc() ); - assert( it != m_data.sourceLocationZonesCnt.end() ); - it->second++; + auto cnt = GetSourceLocationZonesCnt( zone->SrcLoc() ); + (*cnt)++; #endif auto td = NoticeThread( thread ); @@ -2887,14 +2897,16 @@ void Worker::AddSourceLocationPayload( uint64_t ptr, char* data, size_t sz ) m_data.sourceLocationPayloadMap.emplace( slptr, idx ); m_pendingSourceLocationPayload.emplace( ptr, -int16_t( idx + 1 ) ); m_data.sourceLocationPayload.push_back( slptr ); -#ifndef TRACY_NO_STATISTICS const auto key = -int16_t( idx + 1 ); +#ifndef TRACY_NO_STATISTICS auto res = m_data.sourceLocationZones.emplace( key, SourceLocationZones() ); m_data.srclocZonesLast.first = key; m_data.srclocZonesLast.second = &res.first->second; #else - m_data.sourceLocationZonesCnt.emplace( -int16_t( idx + 1 ), 0 ); + auto res = m_data.sourceLocationZonesCnt.emplace( key, 0 ); + m_data.srclocCntLast.first = key; + m_data.srclocCntLast.second = &res.first->second; #endif } else diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index f4662104..95b3b0c1 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -218,6 +218,8 @@ private: std::pair shrinkSrclocLast = std::make_pair( std::numeric_limits::max(), 0 ); #ifndef TRACY_NO_STATISTICS std::pair srclocZonesLast = std::make_pair( std::numeric_limits::max(), nullptr ); +#else + std::pair srclocCntLast = std::make_pair( std::numeric_limits::max(), nullptr ); #endif }; @@ -508,6 +510,13 @@ private: return GetSourceLocationZonesReal( srcloc ); } SourceLocationZones* GetSourceLocationZonesReal( uint16_t srcloc ); +#else + uint64_t* GetSourceLocationZonesCnt( uint16_t srcloc ) + { + if( m_data.srclocCntLast.first == srcloc ) return m_data.srclocCntLast.second; + return GetSourceLocationZonesCntReal( srcloc ); + } + uint64_t* GetSourceLocationZonesCntReal( uint16_t srcloc ); #endif tracy_force_inline void NewZone( ZoneEvent* zone, uint64_t thread );