Implement counting relative hw samples data.

This exploits the fact that AddrStat has two data fields (local and ext) to
store branch and cache information.
This commit is contained in:
Bartosz Taudul 2021-07-15 01:59:33 +02:00
parent 8c78af4d00
commit 9c7a122d94
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 57 additions and 0 deletions

View File

@ -4108,6 +4108,62 @@ void SourceView::GatherIpHwStats( AddrStat& iptotalSrc, AddrStat& iptotalAsm, un
}
}
void SourceView::CountHwStats( unordered_flat_map<uint64_t, AddrStat>& hwCountSrc, unordered_flat_map<uint64_t, AddrStat>& 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<uint64_t, AddrStat>& ipcountSrc, unordered_flat_map<uint64_t, AddrStat>& ipcountAsm, AddrStat& ipmaxSrc, AddrStat& ipmaxAsm, const Worker& worker, bool limitView, const View& view )
{
const auto slzReady = worker.AreSourceLocationZonesReady();

View File

@ -164,6 +164,7 @@ private:
void GatherIpStats( uint64_t baseAddr, AddrStat& iptotalSrc, AddrStat& iptotalAsm, unordered_flat_map<uint64_t, AddrStat>& ipcountSrc, unordered_flat_map<uint64_t, AddrStat>& 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<uint64_t, AddrStat>& ipcountSrc, unordered_flat_map<uint64_t, AddrStat>& 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<uint64_t, AddrStat>& hwCountSrc, unordered_flat_map<uint64_t, AddrStat>& hwCountAsm, AddrStat& hwMaxSrc, AddrStat& hwMaxAsm, Worker& worker, const View& view );
void SelectMicroArchitecture( const char* moniker );