From 9d2c03bc5b3197f36c8e69a53a7f5a62d9d2af61 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 9 Apr 2020 22:23:57 +0200 Subject: [PATCH] Allow showing sample data for whole symbol. --- server/TracySourceView.cpp | 94 +++++++++++++++++++++++--------------- server/TracySourceView.hpp | 3 ++ 2 files changed, 60 insertions(+), 37 deletions(-) diff --git a/server/TracySourceView.cpp b/server/TracySourceView.cpp index 06a1eda3..1f5f3596 100644 --- a/server/TracySourceView.cpp +++ b/server/TracySourceView.cpp @@ -36,6 +36,7 @@ SourceView::SourceView( ImFont* font ) , m_highlightAddr( 0 ) , m_asmRelative( false ) , m_asmShowSourceLocation( true ) + , m_calcInlineStats( true ) , m_showJumps( true ) { } @@ -416,7 +417,7 @@ void SourceView::RenderSymbolView( const Worker& worker ) inlineList++; } - ImGui::TextDisabled( ICON_FA_SITEMAP " Function:" ); + SmallCheckbox( ICON_FA_SITEMAP " Function:", &m_calcInlineStats ); ImGui::SameLine(); ImGui::SetNextItemWidth( -1 ); ImGui::PushStyleVar( ImGuiStyleVar_FramePadding, ImVec2( 0, 0 ) ); @@ -472,48 +473,31 @@ void SourceView::RenderSymbolView( const Worker& worker ) uint32_t iptotalSrc = 0, iptotalAsm = 0; unordered_flat_map ipcountSrc, ipcountAsm; - auto ipmap = worker.GetSymbolInstructionPointers( m_symAddr ); - if( ipmap ) + if( m_calcInlineStats ) { - for( auto& ip : *ipmap ) + GatherIpStats( m_symAddr, iptotalSrc, iptotalAsm, ipcountSrc, ipcountAsm, worker ); + } + else + { + GatherIpStats( m_baseAddr, iptotalSrc, iptotalAsm, ipcountSrc, ipcountAsm, worker ); + auto iptr = worker.GetInlineSymbolList( m_baseAddr, m_codeLen ); + if( iptr ) { - if( m_file ) + const auto symEnd = m_baseAddr + m_codeLen; + while( *iptr < symEnd ) { - auto frame = worker.GetCallstackFrame( ip.first ); - if( frame ) - { - auto ffn = worker.GetString( frame->data[0].file ); - if( strcmp( ffn, m_file ) == 0 ) - { - const auto line = frame->data[0].line; - auto it = ipcountSrc.find( line ); - if( it == ipcountSrc.end() ) - { - ipcountSrc.emplace( line, ip.second ); - } - else - { - it->second += ip.second; - } - iptotalSrc += ip.second; - } - } + GatherIpStats( *iptr, iptotalSrc, iptotalAsm, ipcountSrc, ipcountAsm, worker ); + iptr++; } - - auto addr = worker.GetCanonicalPointer( ip.first ); - assert( ipcountAsm.find( addr ) == ipcountAsm.end() ); - ipcountAsm.emplace( addr, ip.second ); - iptotalAsm += ip.second; - } - - if( iptotalAsm > 0 ) - { - ImGui::SameLine(); - ImGui::Spacing(); - ImGui::SameLine(); - TextFocused( ICON_FA_EYE_DROPPER " Samples:", RealToString( iptotalAsm ) ); } } + if( iptotalAsm > 0 ) + { + ImGui::SameLine(); + ImGui::Spacing(); + ImGui::SameLine(); + TextFocused( ICON_FA_EYE_DROPPER " Samples:", RealToString( iptotalAsm ) ); + } ImGui::Separator(); @@ -1175,4 +1159,40 @@ void SourceView::SelectAsmLinesHover( uint32_t file, uint32_t line, const Worker } } +void SourceView::GatherIpStats( uint64_t addr, uint32_t& iptotalSrc, uint32_t& iptotalAsm, unordered_flat_map& ipcountSrc, unordered_flat_map& ipcountAsm, const Worker& worker ) +{ + auto ipmap = worker.GetSymbolInstructionPointers( addr ); + if( !ipmap ) return; + for( auto& ip : *ipmap ) + { + if( m_file ) + { + auto frame = worker.GetCallstackFrame( ip.first ); + if( frame ) + { + auto ffn = worker.GetString( frame->data[0].file ); + if( strcmp( ffn, m_file ) == 0 ) + { + const auto line = frame->data[0].line; + auto it = ipcountSrc.find( line ); + if( it == ipcountSrc.end() ) + { + ipcountSrc.emplace( line, ip.second ); + } + else + { + it->second += ip.second; + } + iptotalSrc += ip.second; + } + } + } + + auto addr = worker.GetCanonicalPointer( ip.first ); + assert( ipcountAsm.find( addr ) == ipcountAsm.end() ); + ipcountAsm.emplace( addr, ip.second ); + iptotalAsm += ip.second; + } +} + } diff --git a/server/TracySourceView.hpp b/server/TracySourceView.hpp index a7eb46f6..41782c23 100644 --- a/server/TracySourceView.hpp +++ b/server/TracySourceView.hpp @@ -70,6 +70,8 @@ private: void SelectAsmLines( uint32_t file, uint32_t line, const Worker& worker, bool changeAsmLine = true, uint64_t targetAddr = 0 ); void SelectAsmLinesHover( uint32_t file, uint32_t line, const Worker& worker ); + void GatherIpStats( uint64_t addr, uint32_t& iptotalSrc, uint32_t& iptotalAsm, unordered_flat_map& ipcountSrc, unordered_flat_map& ipcountAsm, const Worker& worker ); + ImFont* m_font; const char* m_file; uint32_t m_fileStringIdx; @@ -87,6 +89,7 @@ private: DecayValue m_highlightAddr; bool m_asmRelative; bool m_asmShowSourceLocation; + bool m_calcInlineStats; std::vector m_lines; std::vector m_asm;