mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
Use tables to list memory entries.
This commit is contained in:
parent
6bb77d55a1
commit
325bcc035a
@ -15634,65 +15634,58 @@ void View::DrawRangeEntry( Range& range, const char* label, uint32_t color, cons
|
|||||||
void View::ListMemData( std::vector<const MemEvent*>& vec, std::function<void(const MemEvent*)> DrawAddress, const char* id, int64_t startTime, uint64_t pool )
|
void View::ListMemData( std::vector<const MemEvent*>& vec, std::function<void(const MemEvent*)> DrawAddress, const char* id, int64_t startTime, uint64_t pool )
|
||||||
{
|
{
|
||||||
if( startTime == -1 ) startTime = 0;
|
if( startTime == -1 ) startTime = 0;
|
||||||
|
if( ImGui::BeginTable( "##mem", 8, ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Sortable | ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_ScrollY, ImVec2( 0, ImGui::GetTextLineHeightWithSpacing() * std::min<int64_t>( 1+vec.size(), 15 ) ) ) )
|
||||||
const auto& style = ImGui::GetStyle();
|
|
||||||
const auto dist = vec.size() + 1;
|
|
||||||
const auto ty = ImGui::GetTextLineHeight() + style.ItemSpacing.y;
|
|
||||||
|
|
||||||
enum class SortBy
|
|
||||||
{
|
{
|
||||||
Address,
|
ImGui::TableSetupScrollFreeze( 0, 1 );
|
||||||
Size,
|
ImGui::TableSetupColumn( "Address", ImGuiTableColumnFlags_NoHide );
|
||||||
AllocTime,
|
ImGui::TableSetupColumn( "Size", ImGuiTableColumnFlags_PreferSortDescending );
|
||||||
Duration
|
ImGui::TableSetupColumn( "Appeared at", ImGuiTableColumnFlags_DefaultSort );
|
||||||
};
|
ImGui::TableSetupColumn( "Duration", ImGuiTableColumnFlags_PreferSortDescending );
|
||||||
|
ImGui::TableSetupColumn( "Thread", ImGuiTableColumnFlags_NoSort );
|
||||||
static SortBy sortBy = SortBy::AllocTime;
|
ImGui::TableSetupColumn( "Zone alloc", ImGuiTableColumnFlags_NoSort );
|
||||||
|
ImGui::TableSetupColumn( "Zone free", ImGuiTableColumnFlags_NoSort );
|
||||||
ImGui::BeginChild( id ? id : "##memScroll", ImVec2( 0, std::max( ty * std::min<int64_t>( dist, 5 ), std::min( ty * dist, ImGui::GetContentRegionAvail().y ) ) ) );
|
ImGui::TableSetupColumn( "Call stack", ImGuiTableColumnFlags_NoSort );
|
||||||
ImGui::Columns( 8 );
|
ImGui::TableHeadersRow();
|
||||||
if( ImGui::SmallButton( "Address" ) ) sortBy = SortBy::Address;
|
|
||||||
ImGui::SameLine();
|
|
||||||
DrawHelpMarker( "Click on address to display memory allocation info window.\nMiddle click to zoom to allocation range." );
|
|
||||||
ImGui::NextColumn();
|
|
||||||
if( ImGui::SmallButton( "Size" ) ) sortBy = SortBy::Size;
|
|
||||||
ImGui::NextColumn();
|
|
||||||
if( ImGui::SmallButton( "Appeared at" ) ) sortBy = SortBy::AllocTime;
|
|
||||||
ImGui::SameLine();
|
|
||||||
DrawHelpMarker( "Click on entry to center timeline at the memory allocation time." );
|
|
||||||
ImGui::NextColumn();
|
|
||||||
if( ImGui::SmallButton( "Duration" ) ) sortBy = SortBy::Duration;
|
|
||||||
ImGui::SameLine();
|
|
||||||
DrawHelpMarker( "Active allocations are displayed using green color.\nClick on entry to center timeline at the memory release time." );
|
|
||||||
ImGui::NextColumn();
|
|
||||||
ImGui::TextUnformatted( "Thread" );
|
|
||||||
ImGui::SameLine();
|
|
||||||
DrawHelpMarker( "Shows one thread if alloc and free was performed on the same thread.\nOtherwise two threads are displayed in order: alloc, free." );
|
|
||||||
ImGui::NextColumn();
|
|
||||||
ImGui::TextUnformatted( "Zone alloc" );
|
|
||||||
ImGui::NextColumn();
|
|
||||||
ImGui::TextUnformatted( "Zone free" );
|
|
||||||
ImGui::SameLine();
|
|
||||||
DrawHelpMarker( "If alloc and free is performed in the same zone, it is displayed in yellow color." );
|
|
||||||
ImGui::NextColumn();
|
|
||||||
ImGui::TextUnformatted( "Call stack" );
|
|
||||||
ImGui::NextColumn();
|
|
||||||
ImGui::Separator();
|
|
||||||
|
|
||||||
const auto& mem = m_worker.GetMemoryNamed( pool );
|
const auto& mem = m_worker.GetMemoryNamed( pool );
|
||||||
|
const auto& sortspec = *ImGui::TableGetSortSpecs()->Specs;
|
||||||
switch( sortBy )
|
switch( sortspec.ColumnIndex )
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
if( sortspec.SortDirection == ImGuiSortDirection_Ascending )
|
||||||
{
|
{
|
||||||
case SortBy::Address:
|
|
||||||
pdqsort_branchless( vec.begin(), vec.end(), []( const auto& l, const auto& r ) { return l->Ptr() < r->Ptr(); } );
|
pdqsort_branchless( vec.begin(), vec.end(), []( const auto& l, const auto& r ) { return l->Ptr() < r->Ptr(); } );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pdqsort_branchless( vec.begin(), vec.end(), []( const auto& l, const auto& r ) { return l->Ptr() > r->Ptr(); } );
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SortBy::AllocTime:
|
case 1:
|
||||||
break;
|
if( sortspec.SortDirection == ImGuiSortDirection_Ascending )
|
||||||
case SortBy::Duration:
|
{
|
||||||
pdqsort_branchless( vec.begin(), vec.end(), []( const auto& l, const auto& r ) { return ( l->TimeFree() - l->TimeAlloc() ) < ( r->TimeFree() - r->TimeAlloc() ); } );
|
|
||||||
break;
|
|
||||||
case SortBy::Size:
|
|
||||||
pdqsort_branchless( vec.begin(), vec.end(), []( const auto& l, const auto& r ) { return l->Size() < r->Size(); } );
|
pdqsort_branchless( vec.begin(), vec.end(), []( const auto& l, const auto& r ) { return l->Size() < r->Size(); } );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pdqsort_branchless( vec.begin(), vec.end(), []( const auto& l, const auto& r ) { return l->Size() > r->Size(); } );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if( sortspec.SortDirection == ImGuiSortDirection_Descending )
|
||||||
|
{
|
||||||
|
std::reverse( vec.begin(), vec.end() );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
if( sortspec.SortDirection == ImGuiSortDirection_Ascending )
|
||||||
|
{
|
||||||
|
pdqsort_branchless( vec.begin(), vec.end(), []( const auto& l, const auto& r ) { return ( l->TimeFree() - l->TimeAlloc() ) < ( r->TimeFree() - r->TimeAlloc() ); } );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pdqsort_branchless( vec.begin(), vec.end(), []( const auto& l, const auto& r ) { return ( l->TimeFree() - l->TimeAlloc() ) > ( r->TimeFree() - r->TimeAlloc() ); } );
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert( false );
|
assert( false );
|
||||||
@ -15706,6 +15699,9 @@ void View::ListMemData( std::vector<const MemEvent*>& vec, std::function<void(co
|
|||||||
{
|
{
|
||||||
for( auto i=clipper.DisplayStart; i<clipper.DisplayEnd; i++ )
|
for( auto i=clipper.DisplayStart; i<clipper.DisplayEnd; i++ )
|
||||||
{
|
{
|
||||||
|
ImGui::TableNextRow();
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
|
||||||
auto v = vec[i];
|
auto v = vec[i];
|
||||||
const auto arrIdx = std::distance( mem.data.begin(), v );
|
const auto arrIdx = std::distance( mem.data.begin(), v );
|
||||||
|
|
||||||
@ -15734,20 +15730,20 @@ void View::ListMemData( std::vector<const MemEvent*>& vec, std::function<void(co
|
|||||||
m_memoryAllocHoverWait = 2;
|
m_memoryAllocHoverWait = 2;
|
||||||
m_memoryAllocHoverPool = pool;
|
m_memoryAllocHoverPool = pool;
|
||||||
}
|
}
|
||||||
ImGui::NextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::TextUnformatted( MemSizeToString( v->Size() ) );
|
ImGui::TextUnformatted( MemSizeToString( v->Size() ) );
|
||||||
ImGui::NextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::PushID( idx++ );
|
ImGui::PushID( idx++ );
|
||||||
if( ImGui::Selectable( TimeToStringExact( v->TimeAlloc() - startTime ) ) )
|
if( ImGui::Selectable( TimeToStringExact( v->TimeAlloc() - startTime ) ) )
|
||||||
{
|
{
|
||||||
CenterAtTime( v->TimeAlloc() );
|
CenterAtTime( v->TimeAlloc() );
|
||||||
}
|
}
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
ImGui::NextColumn();
|
ImGui::TableNextColumn();
|
||||||
if( v->TimeFree() < 0 )
|
if( v->TimeFree() < 0 )
|
||||||
{
|
{
|
||||||
TextColoredUnformatted( ImVec4( 0.6f, 1.f, 0.6f, 1.f ), TimeToString( m_worker.GetLastTime() - v->TimeAlloc() ) );
|
TextColoredUnformatted( ImVec4( 0.6f, 1.f, 0.6f, 1.f ), TimeToString( m_worker.GetLastTime() - v->TimeAlloc() ) );
|
||||||
ImGui::NextColumn();
|
ImGui::TableNextColumn();
|
||||||
const auto tid = m_worker.DecompressThread( v->ThreadAlloc() );
|
const auto tid = m_worker.DecompressThread( v->ThreadAlloc() );
|
||||||
SmallColorBox( GetThreadColor( tid, 0 ) );
|
SmallColorBox( GetThreadColor( tid, 0 ) );
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
@ -15761,7 +15757,7 @@ void View::ListMemData( std::vector<const MemEvent*>& vec, std::function<void(co
|
|||||||
CenterAtTime( v->TimeFree() );
|
CenterAtTime( v->TimeFree() );
|
||||||
}
|
}
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
ImGui::NextColumn();
|
ImGui::TableNextColumn();
|
||||||
if( v->ThreadAlloc() == v->ThreadFree() )
|
if( v->ThreadAlloc() == v->ThreadFree() )
|
||||||
{
|
{
|
||||||
const auto tid = m_worker.DecompressThread( v->ThreadAlloc() );
|
const auto tid = m_worker.DecompressThread( v->ThreadAlloc() );
|
||||||
@ -15784,7 +15780,7 @@ void View::ListMemData( std::vector<const MemEvent*>& vec, std::function<void(co
|
|||||||
ImGui::TextUnformatted( m_worker.GetThreadName( tidFree ) );
|
ImGui::TextUnformatted( m_worker.GetThreadName( tidFree ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::NextColumn();
|
ImGui::TableNextColumn();
|
||||||
auto zone = FindZoneAtTime( m_worker.DecompressThread( v->ThreadAlloc() ), v->TimeAlloc() );
|
auto zone = FindZoneAtTime( m_worker.DecompressThread( v->ThreadAlloc() ), v->TimeAlloc() );
|
||||||
if( !zone )
|
if( !zone )
|
||||||
{
|
{
|
||||||
@ -15812,7 +15808,7 @@ void View::ListMemData( std::vector<const MemEvent*>& vec, std::function<void(co
|
|||||||
ZoneTooltip( *zone );
|
ZoneTooltip( *zone );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::NextColumn();
|
ImGui::TableNextColumn();
|
||||||
if( v->TimeFree() < 0 )
|
if( v->TimeFree() < 0 )
|
||||||
{
|
{
|
||||||
TextColoredUnformatted( ImVec4( 0.6f, 1.f, 0.6f, 1.f ), "active" );
|
TextColoredUnformatted( ImVec4( 0.6f, 1.f, 0.6f, 1.f ), "active" );
|
||||||
@ -15857,7 +15853,7 @@ void View::ListMemData( std::vector<const MemEvent*>& vec, std::function<void(co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::NextColumn();
|
ImGui::TableNextColumn();
|
||||||
if( v->CsAlloc() == 0 )
|
if( v->CsAlloc() == 0 )
|
||||||
{
|
{
|
||||||
TextDisabledUnformatted( "[alloc]" );
|
TextDisabledUnformatted( "[alloc]" );
|
||||||
@ -15877,11 +15873,10 @@ void View::ListMemData( std::vector<const MemEvent*>& vec, std::function<void(co
|
|||||||
{
|
{
|
||||||
SmallCallstackButton( "free", v->csFree.Val(), idx );
|
SmallCallstackButton( "free", v->csFree.Val(), idx );
|
||||||
}
|
}
|
||||||
ImGui::NextColumn();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::EndColumns();
|
ImGui::EndTable();
|
||||||
ImGui::EndChild();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static tracy_force_inline CallstackFrameTree* GetFrameTreeItemNoGroup( unordered_flat_map<uint64_t, CallstackFrameTree>& tree, CallstackFrameId idx, const Worker& worker )
|
static tracy_force_inline CallstackFrameTree* GetFrameTreeItemNoGroup( unordered_flat_map<uint64_t, CallstackFrameTree>& tree, CallstackFrameId idx, const Worker& worker )
|
||||||
@ -16276,6 +16271,14 @@ void View::DrawMemory()
|
|||||||
ImGui::Text( "%-15s", MemSizeToString( mem.usage ) );
|
ImGui::Text( "%-15s", MemSizeToString( mem.usage ) );
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
TextFocused( "Memory span:", MemSizeToString( mem.high - mem.low ) );
|
TextFocused( "Memory span:", MemSizeToString( mem.high - mem.low ) );
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Spacing();
|
||||||
|
ImGui::SameLine();
|
||||||
|
DrawHelpMarker(
|
||||||
|
"Click on address to display memory allocation info window. Middle click to zoom to allocation range.\n"
|
||||||
|
"Active allocations are displayed using green color.\n"
|
||||||
|
"A single thread is displayed if alloc and free was performed on the same thread. Otherwise two threads are displayed in order: alloc, free.\n"
|
||||||
|
"If alloc and free is performed in the same zone, the free zone is displayed in yellow color." );
|
||||||
|
|
||||||
const auto zvMid = m_vd.zvStart + ( m_vd.zvEnd - m_vd.zvStart ) / 2;
|
const auto zvMid = m_vd.zvStart + ( m_vd.zvEnd - m_vd.zvStart ) / 2;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user