1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Add ability to filter callstacks in memory tab by inactive allocations.

Filtering by inactive allocations helps to pin point wasteful allocations
in an app.
This commit is contained in:
thedmd
2022-06-01 08:45:26 +02:00
parent a53c8befdc
commit 9ed9e18bc8
3 changed files with 36 additions and 13 deletions
+25 -9
View File
@@ -17227,7 +17227,7 @@ static tracy_force_inline T* GetParentFrameTreeItemGroup( unordered_flat_map<uin
}
unordered_flat_map<uint32_t, View::MemPathData> View::GetCallstackPaths( const MemData& mem, bool onlyActive ) const
unordered_flat_map<uint32_t, View::MemPathData> View::GetCallstackPaths( const MemData& mem, MemRange memRange ) const
{
unordered_flat_map<uint32_t, MemPathData> pathSum;
pathSum.reserve( m_worker.GetCallstackPayloadCount() );
@@ -17238,13 +17238,13 @@ unordered_flat_map<uint32_t, View::MemPathData> View::GetCallstackPaths( const M
if( it != mem.data.end() )
{
auto end = std::lower_bound( mem.data.begin(), mem.data.end(), m_memInfo.range.max, []( const auto& lhs, const auto& rhs ) { return lhs.TimeAlloc() < rhs; } );
if( onlyActive )
if( memRange != MemRange::Full )
{
while( it != end )
{
auto& ev = *it++;
if( ev.CsAlloc() == 0 ) continue;
if( ev.TimeFree() >= 0 && ev.TimeFree() < m_memInfo.range.max ) continue;
if( ( memRange == MemRange::Inactive ) == ( ev.TimeFree() >= 0 && ev.TimeFree() < m_memInfo.range.max ) ) continue;
auto pit = pathSum.find( ev.CsAlloc() );
if( pit == pathSum.end() )
{
@@ -17279,12 +17279,12 @@ unordered_flat_map<uint32_t, View::MemPathData> View::GetCallstackPaths( const M
}
else
{
if( onlyActive )
if( memRange != MemRange::Full )
{
for( auto& ev : mem.data )
{
if( ev.CsAlloc() == 0 ) continue;
if( ev.TimeFree() >= 0 ) continue;
if( ( memRange == MemRange::Inactive ) == ( ev.TimeFree() >= 0 ) ) continue;
auto it = pathSum.find( ev.CsAlloc() );
if( it == pathSum.end() )
{
@@ -17321,7 +17321,7 @@ unordered_flat_map<uint32_t, View::MemPathData> View::GetCallstackPaths( const M
unordered_flat_map<uint64_t, MemCallstackFrameTree> View::GetCallstackFrameTreeBottomUp( const MemData& mem ) const
{
unordered_flat_map<uint64_t, MemCallstackFrameTree> root;
auto pathSum = GetCallstackPaths( mem, m_activeOnlyBottomUp );
auto pathSum = GetCallstackPaths( mem, m_memRangeBottomUp );
if( m_groupCallstackTreeByNameBottomUp )
{
for( auto& path : pathSum )
@@ -17451,7 +17451,7 @@ unordered_flat_map<uint64_t, CallstackFrameTree> View::GetParentsCallstackFrameT
unordered_flat_map<uint64_t, MemCallstackFrameTree> View::GetCallstackFrameTreeTopDown( const MemData& mem ) const
{
unordered_flat_map<uint64_t, MemCallstackFrameTree> root;
auto pathSum = GetCallstackPaths( mem, m_activeOnlyTopDown );
auto pathSum = GetCallstackPaths( mem, m_memRangeTopDown );
if( m_groupCallstackTreeByNameTopDown )
{
for( auto& path : pathSum )
@@ -18011,7 +18011,15 @@ void View::DrawMemory()
ImGui::SameLine();
ImGui::Spacing();
ImGui::SameLine();
SmallCheckbox( "Only active allocations", &m_activeOnlyBottomUp );
bool activeOnlyBottomUp = m_memRangeBottomUp == MemRange::Active;
if( SmallCheckbox( "Only active allocations", &activeOnlyBottomUp ) )
m_memRangeBottomUp = activeOnlyBottomUp ? MemRange::Active : MemRange::Full;
ImGui::SameLine();
ImGui::Spacing();
ImGui::SameLine();
bool inactiveOnlyBottomUp = m_memRangeBottomUp == MemRange::Inactive;
if( SmallCheckbox( "Only inactive allocations", &inactiveOnlyBottomUp ) )
m_memRangeBottomUp = inactiveOnlyBottomUp ? MemRange::Inactive : MemRange::Full;
auto tree = GetCallstackFrameTreeBottomUp( mem );
if( !tree.empty() )
@@ -18041,7 +18049,15 @@ void View::DrawMemory()
ImGui::SameLine();
ImGui::Spacing();
ImGui::SameLine();
SmallCheckbox( "Only active allocations", &m_activeOnlyTopDown );
bool activeOnlyTopDown = m_memRangeTopDown == MemRange::Active;
if( SmallCheckbox( "Only active allocations", &activeOnlyTopDown ) )
m_memRangeTopDown = activeOnlyTopDown ? MemRange::Active : MemRange::Full;
ImGui::SameLine();
ImGui::Spacing();
ImGui::SameLine();
bool inactiveOnlyTopDown = m_memRangeTopDown == MemRange::Inactive;
if( SmallCheckbox( "Only inactive allocations", &inactiveOnlyTopDown ) )
m_memRangeTopDown = inactiveOnlyTopDown ? MemRange::Inactive : MemRange::Full;
auto tree = GetCallstackFrameTreeTopDown( mem );
if( !tree.empty() )