Add top-down call stack memory tree.

This commit is contained in:
Bartosz Taudul 2019-02-06 13:53:14 +01:00
parent c689a494da
commit c2e9c00a38
2 changed files with 53 additions and 5 deletions

View File

@ -7678,7 +7678,7 @@ flat_hash_map<uint32_t, View::PathData, nohash<uint32_t>> View::GetCallstackPath
return pathSum;
}
std::vector<CallstackFrameTree> View::GetCallstackFrameTree( const MemData& mem ) const
std::vector<CallstackFrameTree> View::GetCallstackFrameTreeBottomUp( const MemData& mem ) const
{
std::vector<CallstackFrameTree> root;
auto pathSum = GetCallstackPaths( mem );
@ -7706,6 +7706,34 @@ std::vector<CallstackFrameTree> View::GetCallstackFrameTree( const MemData& mem
return root;
}
std::vector<CallstackFrameTree> View::GetCallstackFrameTreeTopDown( const MemData& mem ) const
{
std::vector<CallstackFrameTree> 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 );

View File

@ -120,7 +120,8 @@ private:
void ListMemData( T ptr, T end, std::function<void(T&)> DrawAddress, const char* id = nullptr );
flat_hash_map<uint32_t, PathData, nohash<uint32_t>> GetCallstackPaths( const MemData& mem ) const;
std::vector<CallstackFrameTree> GetCallstackFrameTree( const MemData& mem ) const;
std::vector<CallstackFrameTree> GetCallstackFrameTreeBottomUp( const MemData& mem ) const;
std::vector<CallstackFrameTree> GetCallstackFrameTreeTopDown( const MemData& mem ) const;
void DrawFrameTreeLevel( std::vector<CallstackFrameTree>& tree, int& idx );
void DrawInfoWindow();