Allow restricting call stack frame tree to active allocations.

This commit is contained in:
Bartosz Taudul 2019-05-09 13:37:28 +02:00
parent 98eaacec90
commit 54c8a882c9
2 changed files with 43 additions and 14 deletions

View File

@ -9042,17 +9042,20 @@ static tracy_force_inline CallstackFrameTree* GetFrameTreeItemGroup( flat_hash_m
return &it->second; return &it->second;
} }
flat_hash_map<uint32_t, View::PathData, nohash<uint32_t>> View::GetCallstackPaths( const MemData& mem ) const flat_hash_map<uint32_t, View::PathData, nohash<uint32_t>> View::GetCallstackPaths( const MemData& mem, bool onlyActive ) const
{ {
flat_hash_map<uint32_t, PathData, nohash<uint32_t>> pathSum; flat_hash_map<uint32_t, PathData, nohash<uint32_t>> pathSum;
pathSum.reserve( m_worker.GetCallstackPayloadCount() ); pathSum.reserve( m_worker.GetCallstackPayloadCount() );
const auto zvMid = m_zvStart + ( m_zvEnd - m_zvStart ) / 2; const auto zvMid = m_zvStart + ( m_zvEnd - m_zvStart ) / 2;
if( m_memInfo.restrictTime )
{
for( auto& ev : mem.data ) for( auto& ev : mem.data )
{ {
if( ev.csAlloc == 0 ) continue; if( ev.csAlloc == 0 ) continue;
if( m_memInfo.restrictTime && ev.timeAlloc >= zvMid ) continue; if( ev.timeAlloc >= zvMid ) continue;
if( onlyActive && ev.timeFree >= 0 && ev.timeFree < zvMid ) continue;
auto it = pathSum.find( ev.csAlloc ); auto it = pathSum.find( ev.csAlloc );
if( it == pathSum.end() ) if( it == pathSum.end() )
@ -9065,13 +9068,33 @@ flat_hash_map<uint32_t, View::PathData, nohash<uint32_t>> View::GetCallstackPath
it->second.mem += ev.size; it->second.mem += ev.size;
} }
} }
}
else
{
for( auto& ev : mem.data )
{
if( ev.csAlloc == 0 ) continue;
if( onlyActive && ev.timeFree >= 0 ) continue;
auto it = pathSum.find( ev.csAlloc );
if( it == pathSum.end() )
{
pathSum.emplace( ev.csAlloc, PathData { 1, ev.size } );
}
else
{
it->second.cnt++;
it->second.mem += ev.size;
}
}
}
return pathSum; return pathSum;
} }
flat_hash_map<uint64_t, CallstackFrameTree, nohash<uint64_t>> View::GetCallstackFrameTreeBottomUp( const MemData& mem ) const flat_hash_map<uint64_t, CallstackFrameTree, nohash<uint64_t>> View::GetCallstackFrameTreeBottomUp( const MemData& mem ) const
{ {
flat_hash_map<uint64_t, CallstackFrameTree, nohash<uint64_t>> root; flat_hash_map<uint64_t, CallstackFrameTree, nohash<uint64_t>> root;
auto pathSum = GetCallstackPaths( mem ); auto pathSum = GetCallstackPaths( mem, m_activeOnlyBottomUp );
if( m_groupCallstackTreeByNameBottomUp ) if( m_groupCallstackTreeByNameBottomUp )
{ {
for( auto& path : pathSum ) for( auto& path : pathSum )
@ -9121,7 +9144,7 @@ flat_hash_map<uint64_t, CallstackFrameTree, nohash<uint64_t>> View::GetCallstack
flat_hash_map<uint64_t, CallstackFrameTree, nohash<uint64_t>> View::GetCallstackFrameTreeTopDown( const MemData& mem ) const flat_hash_map<uint64_t, CallstackFrameTree, nohash<uint64_t>> View::GetCallstackFrameTreeTopDown( const MemData& mem ) const
{ {
flat_hash_map<uint64_t, CallstackFrameTree, nohash<uint64_t>> root; flat_hash_map<uint64_t, CallstackFrameTree, nohash<uint64_t>> root;
auto pathSum = GetCallstackPaths( mem ); auto pathSum = GetCallstackPaths( mem, m_activeOnlyTopDown );
if( m_groupCallstackTreeByNameTopDown ) if( m_groupCallstackTreeByNameTopDown )
{ {
for( auto& path : pathSum ) for( auto& path : pathSum )
@ -9452,6 +9475,8 @@ void View::DrawMemory()
ImGui::Checkbox( "Group by function name", &m_groupCallstackTreeByNameBottomUp ); ImGui::Checkbox( "Group by function name", &m_groupCallstackTreeByNameBottomUp );
ImGui::SameLine(); ImGui::SameLine();
DrawHelpMarker( "If enabled, only one source location will be displayed (which may be incorrect)." ); DrawHelpMarker( "If enabled, only one source location will be displayed (which may be incorrect)." );
ImGui::SameLine();
ImGui::Checkbox( "Only active allocations", &m_activeOnlyBottomUp );
TextDisabledUnformatted( "Press ctrl key to display allocation info tooltip." ); TextDisabledUnformatted( "Press ctrl key to display allocation info tooltip." );
TextDisabledUnformatted( "Right click on function name to display allocations list. Right click on file name to open source file." ); TextDisabledUnformatted( "Right click on function name to display allocations list. Right click on file name to open source file." );
@ -9474,6 +9499,8 @@ void View::DrawMemory()
ImGui::Checkbox( "Group by function name", &m_groupCallstackTreeByNameTopDown ); ImGui::Checkbox( "Group by function name", &m_groupCallstackTreeByNameTopDown );
ImGui::SameLine(); ImGui::SameLine();
DrawHelpMarker( "If enabled, only one source location will be displayed (which may be incorrect)." ); DrawHelpMarker( "If enabled, only one source location will be displayed (which may be incorrect)." );
ImGui::SameLine();
ImGui::Checkbox( "Only active allocations", &m_activeOnlyTopDown );
TextDisabledUnformatted( "Press ctrl key to display allocation info tooltip." ); TextDisabledUnformatted( "Press ctrl key to display allocation info tooltip." );
TextDisabledUnformatted( "Right click on function name to display allocations list. Right click on file name to open source file." ); TextDisabledUnformatted( "Right click on function name to display allocations list. Right click on file name to open source file." );

View File

@ -133,7 +133,7 @@ private:
template<class T> template<class T>
void ListMemData( T ptr, T end, std::function<void(T&)> DrawAddress, const char* id = nullptr, int64_t startTime = -1 ); void ListMemData( T ptr, T end, std::function<void(T&)> DrawAddress, const char* id = nullptr, int64_t startTime = -1 );
flat_hash_map<uint32_t, PathData, nohash<uint32_t>> GetCallstackPaths( const MemData& mem ) const; flat_hash_map<uint32_t, PathData, nohash<uint32_t>> GetCallstackPaths( const MemData& mem, bool onlyActive ) const;
flat_hash_map<uint64_t, CallstackFrameTree, nohash<uint64_t>> GetCallstackFrameTreeBottomUp( const MemData& mem ) const; flat_hash_map<uint64_t, CallstackFrameTree, nohash<uint64_t>> GetCallstackFrameTreeBottomUp( const MemData& mem ) const;
flat_hash_map<uint64_t, CallstackFrameTree, nohash<uint64_t>> GetCallstackFrameTreeTopDown( const MemData& mem ) const; flat_hash_map<uint64_t, CallstackFrameTree, nohash<uint64_t>> GetCallstackFrameTreeTopDown( const MemData& mem ) const;
void DrawFrameTreeLevel( const flat_hash_map<uint64_t, CallstackFrameTree, nohash<uint64_t>>& tree, int& idx ); void DrawFrameTreeLevel( const flat_hash_map<uint64_t, CallstackFrameTree, nohash<uint64_t>>& tree, int& idx );
@ -312,6 +312,8 @@ private:
bool m_groupCallstackTreeByNameBottomUp = true; bool m_groupCallstackTreeByNameBottomUp = true;
bool m_groupCallstackTreeByNameTopDown = true; bool m_groupCallstackTreeByNameTopDown = true;
bool m_activeOnlyBottomUp = false;
bool m_activeOnlyTopDown = false;
struct FindZone { struct FindZone {
enum : uint64_t { Unselected = std::numeric_limits<uint64_t>::max() - 1 }; enum : uint64_t { Unselected = std::numeric_limits<uint64_t>::max() - 1 };