From c2e9c00a3865fedd0009b74259ec4a6b706f0744 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 6 Feb 2019 13:53:14 +0100 Subject: [PATCH] Add top-down call stack memory tree. --- server/TracyView.cpp | 55 ++++++++++++++++++++++++++++++++++++++++---- server/TracyView.hpp | 3 ++- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 0b8f3e96..4a202aef 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -7678,7 +7678,7 @@ flat_hash_map> View::GetCallstackPath return pathSum; } -std::vector View::GetCallstackFrameTree( const MemData& mem ) const +std::vector View::GetCallstackFrameTreeBottomUp( const MemData& mem ) const { std::vector root; auto pathSum = GetCallstackPaths( mem ); @@ -7706,6 +7706,34 @@ std::vector View::GetCallstackFrameTree( const MemData& mem return root; } +std::vector View::GetCallstackFrameTreeTopDown( const MemData& mem ) const +{ + std::vector root; + auto pathSum = GetCallstackPaths( mem ); + for( auto& path : pathSum ) + { + auto& cs = m_worker.GetCallstack( path.first ); + + auto base = cs.front(); + auto treePtr = GetFrameTreeItem( root, base ); + treePtr->countInclusive += path.second.cnt; + treePtr->allocInclusive += path.second.mem; + treePtr->callstacks.emplace( path.first ); + + for( int i = 1; i < cs.size(); i++ ) + { + treePtr = GetFrameTreeItem( treePtr->children, cs[i] ); + treePtr->countInclusive += path.second.cnt; + treePtr->allocInclusive += path.second.mem; + treePtr->callstacks.emplace( path.first ); + } + + treePtr->countExclusive += path.second.cnt; + treePtr->allocExclusive += path.second.mem; + } + return root; +} + enum { ChunkBits = 10 }; enum { PageBits = 10 }; @@ -7990,16 +8018,35 @@ void View::DrawMemory() ImGui::Separator(); #ifdef TRACY_EXTENDED_FONT - if( ImGui::TreeNode( ICON_FA_ALIGN_JUSTIFY " Call stack tree" ) ) + if( ImGui::TreeNode( ICON_FA_ALIGN_JUSTIFY " Bottom-up call stack tree" ) ) #else - if( ImGui::TreeNode( "Call stack tree" ) ) + if( ImGui::TreeNode( "Bottom-up call stack tree" ) ) #endif { ImGui::TextDisabled( "Press ctrl key to display allocation info tooltip." ); ImGui::TextDisabled( "Right click on function name to display allocations list. Right click on file name to open source file." ); auto& mem = m_worker.GetMemData(); - auto tree = GetCallstackFrameTree( mem ); + auto tree = GetCallstackFrameTreeBottomUp( mem ); + + int idx = 0; + DrawFrameTreeLevel( tree, idx ); + + ImGui::TreePop(); + } + + ImGui::Separator(); +#ifdef TRACY_EXTENDED_FONT + if( ImGui::TreeNode( ICON_FA_ALIGN_JUSTIFY " Top-down call stack tree" ) ) +#else + if( ImGui::TreeNode( "Top-down call stack tree" ) ) +#endif + { + ImGui::TextDisabled( "Press ctrl key to display allocation info tooltip." ); + ImGui::TextDisabled( "Right click on function name to display allocations list. Right click on file name to open source file." ); + + auto& mem = m_worker.GetMemData(); + auto tree = GetCallstackFrameTreeTopDown( mem ); int idx = 0; DrawFrameTreeLevel( tree, idx ); diff --git a/server/TracyView.hpp b/server/TracyView.hpp index c65e48eb..eed950ce 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -120,7 +120,8 @@ private: void ListMemData( T ptr, T end, std::function DrawAddress, const char* id = nullptr ); flat_hash_map> GetCallstackPaths( const MemData& mem ) const; - std::vector GetCallstackFrameTree( const MemData& mem ) const; + std::vector GetCallstackFrameTreeBottomUp( const MemData& mem ) const; + std::vector GetCallstackFrameTreeTopDown( const MemData& mem ) const; void DrawFrameTreeLevel( std::vector& tree, int& idx ); void DrawInfoWindow();