From 1f0b4656f4621223a4df8b6829a432f7b56b3597 Mon Sep 17 00:00:00 2001 From: Terence Rokop Date: Sat, 5 Jun 2021 11:06:32 -0700 Subject: [PATCH] Introduce SrcLocCountMap Add to ThreadData a map from source location to a counter, which will be used to keep track of the number of appearances of zones with the corresponding source locations on each thread's stack. --- server/TracyEvent.hpp | 49 ++++++++++++++++++++++++++++++++++++++++++ server/TracyWorker.cpp | 1 + 2 files changed, 50 insertions(+) diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index 84547ce2..1f349a06 100644 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -587,12 +587,57 @@ enum { GhostZoneSize = sizeof( GhostZone ) }; #pragma pack() +using SrcLocCountMap = unordered_flat_map; + +tracy_force_inline void IncSrcLocCount(SrcLocCountMap& countMap, int16_t srcloc) +{ + const auto it = countMap.find( srcloc ); + if( it == countMap.end() ) + { + countMap.emplace( srcloc, 1 ); + return; + } + + assert( it->second != 0 ); + it->second++; +} + +tracy_force_inline bool DecSrcLocCount(SrcLocCountMap& countMap, int16_t srcloc) +{ + const auto it = countMap.find( srcloc ); + assert( it != countMap.end() ); + assert( it->second != 0 ); + + if( it->second == 1 ) + { + countMap.erase( it ); + return false; + } + + it->second--; + return true; +} + +tracy_force_inline bool HasSrcLocCount(SrcLocCountMap& countMap, int16_t srcloc) +{ + const auto it = countMap.find( srcloc ); + + if( it != countMap.end() ) + { + assert( it->second != 0 ); + return true; + } + + return false; +} + struct ThreadData { uint64_t id; uint64_t count; Vector> timeline; Vector> stack; + SrcLocCountMap stackCount; Vector> messages; uint32_t nextZoneId; Vector zoneIdStack; @@ -604,6 +649,10 @@ struct ThreadData Vector samples; SampleData pendingSample; uint64_t kernelSampleCnt; + + tracy_force_inline void IncStackCount(int16_t srcloc) { IncSrcLocCount( stackCount, srcloc ); } + + tracy_force_inline bool DecStackCount(int16_t srcloc) { return DecSrcLocCount( stackCount, srcloc ); } }; struct GpuCtxThreadData diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index a55aae86..1b860248 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -2006,6 +2006,7 @@ Worker::~Worker() { v->timeline.~Vector(); v->stack.~Vector(); + v->stackCount.~Table(); v->messages.~Vector(); v->zoneIdStack.~Vector(); v->samples.~Vector();