diff --git a/server/TracySourceView.cpp b/server/TracySourceView.cpp index 1c12a695..6166db5f 100644 --- a/server/TracySourceView.cpp +++ b/server/TracySourceView.cpp @@ -4108,6 +4108,62 @@ void SourceView::GatherIpHwStats( AddrStat& iptotalSrc, AddrStat& iptotalAsm, un } } +void SourceView::CountHwStats( unordered_flat_map& hwCountSrc, unordered_flat_map& hwCountAsm, AddrStat& hwMaxSrc, AddrStat& hwMaxAsm, Worker& worker, const View& view ) +{ + auto filename = m_source.filename(); + for( auto& v : m_asm ) + { + const auto& addr = v.addr; + if( m_calcInlineStats && worker.GetInlineSymbolForAddress( addr ) != m_symAddr ) continue; + const auto hw = worker.GetHwSampleData( addr ); + if( !hw ) continue; + uint64_t branch, cache; + if( view.m_statRange.active ) + { + branch = sqrt( CountHwSamples( hw->branchMiss, view.m_statRange ) * CountHwSamples( hw->branchRetired, view.m_statRange ) ); + cache = sqrt( CountHwSamples( hw->cacheMiss, view.m_statRange ) * CountHwSamples( hw->cacheRef, view.m_statRange ) ); + } + else + { + branch = sqrt( hw->branchMiss.size() * hw->branchRetired.size() ); + cache = sqrt( hw->cacheMiss.size() * hw->cacheRef.size() ); + } + assert( ipcountAsm.find( addr ) == ipcountAsm.end() ); + hwCountAsm.emplace( addr, AddrStat { branch, cache } ); + if( hwMaxAsm.local < branch ) hwMaxAsm.local = branch; + if( hwMaxAsm.ext < cache ) hwMaxAsm.ext = cache; + + if( filename ) + { + uint32_t line; + const auto fref = worker.GetLocationForAddress( addr, line ); + if( line != 0 ) + { + auto ffn = worker.GetString( fref ); + if( strcmp( ffn, filename ) == 0 ) + { + auto it = hwCountSrc.find( line ); + if( it == hwCountSrc.end() ) + { + hwCountSrc.emplace( line, AddrStat{ branch, cache } ); + if( hwMaxSrc.local < branch ) hwMaxSrc.local = branch; + if( hwMaxSrc.ext < cache ) hwMaxSrc.ext = cache; + } + else + { + const auto branchSum = it->second.local + branch; + const auto cacheSum = it->second.ext + cache; + it->second.local = branchSum; + it->second.ext = cacheSum; + if( hwMaxSrc.local < branchSum ) hwMaxSrc.local = branchSum; + if( hwMaxSrc.ext < cacheSum ) hwMaxSrc.ext = cacheSum; + } + } + } + } + } +} + void SourceView::GatherIpStats( uint64_t baseAddr, AddrStat& iptotalSrc, AddrStat& iptotalAsm, unordered_flat_map& ipcountSrc, unordered_flat_map& ipcountAsm, AddrStat& ipmaxSrc, AddrStat& ipmaxAsm, const Worker& worker, bool limitView, const View& view ) { const auto slzReady = worker.AreSourceLocationZonesReady(); diff --git a/server/TracySourceView.hpp b/server/TracySourceView.hpp index 062d44e7..3b32f0fb 100644 --- a/server/TracySourceView.hpp +++ b/server/TracySourceView.hpp @@ -164,6 +164,7 @@ private: void GatherIpStats( uint64_t baseAddr, AddrStat& iptotalSrc, AddrStat& iptotalAsm, unordered_flat_map& ipcountSrc, unordered_flat_map& ipcountAsm, AddrStat& ipmaxSrc, AddrStat& ipmaxAsm, const Worker& worker, bool limitView, const View& view ); void GatherAdditionalIpStats( uint64_t baseAddr, AddrStat& iptotalSrc, AddrStat& iptotalAsm, unordered_flat_map& ipcountSrc, unordered_flat_map& ipcountAsm, AddrStat& ipmaxSrc, AddrStat& ipmaxAsm, const Worker& worker, bool limitView, const View& view ); uint32_t CountAsmIpStats( uint64_t baseAddr, const Worker& worker, bool limitView, const View& view ); + void CountHwStats( unordered_flat_map& hwCountSrc, unordered_flat_map& hwCountAsm, AddrStat& hwMaxSrc, AddrStat& hwMaxAsm, Worker& worker, const View& view ); void SelectMicroArchitecture( const char* moniker );