Clip memory allocation lists.

This commit is contained in:
Bartosz Taudul 2020-01-31 19:18:20 +01:00
parent a84eec1aef
commit d680fa6cd6
2 changed files with 143 additions and 140 deletions

View File

@ -6200,7 +6200,7 @@ void View::DrawZoneInfoWindow()
} }
pdqsort_branchless( v.begin(), v.end(), [] ( const auto& l, const auto& r ) { return l->TimeAlloc() < r->TimeAlloc(); } ); pdqsort_branchless( v.begin(), v.end(), [] ( const auto& l, const auto& r ) { return l->TimeAlloc() < r->TimeAlloc(); } );
ListMemData<decltype( v.begin() )>( v.begin(), v.end(), []( auto& v ) { ListMemData<decltype( v.begin() )>( v.begin(), v.end(), []( auto v ) {
ImGui::Text( "0x%" PRIx64, (*v)->Ptr() ); ImGui::Text( "0x%" PRIx64, (*v)->Ptr() );
}, nullptr, m_allocTimeRelativeToZone ? ev.Start() : -1 ); }, nullptr, m_allocTimeRelativeToZone ? ev.Start() : -1 );
ImGui::TreePop(); ImGui::TreePop();
@ -12572,7 +12572,7 @@ void View::DrawAnnotationList()
} }
template<class T> template<class T>
void View::ListMemData( T ptr, T end, std::function<void(T&)> DrawAddress, const char* id, int64_t startTime ) void View::ListMemData( T ptr, T end, std::function<void(T)> DrawAddress, const char* id, int64_t startTime )
{ {
if( startTime == -1 ) startTime = 0; if( startTime == -1 ) startTime = 0;
@ -12613,20 +12613,23 @@ void View::ListMemData( T ptr, T end, std::function<void(T&)> DrawAddress, const
const auto& mem = m_worker.GetMemData(); const auto& mem = m_worker.GetMemData();
int idx = 0; int idx = 0;
while( ptr != end ) ImGuiListClipper clipper( end - ptr );
while( clipper.Step() )
{ {
auto v = *ptr; for( auto i=clipper.DisplayStart; i<clipper.DisplayEnd; i++ )
{
auto v = ptr[i];
const auto arrIdx = std::distance( mem.data.begin(), v ); const auto arrIdx = std::distance( mem.data.begin(), v );
if( m_memoryAllocInfoWindow == arrIdx ) if( m_memoryAllocInfoWindow == arrIdx )
{ {
ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 1.f, 0.f, 0.f, 1.f ) ); ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 1.f, 0.f, 0.f, 1.f ) );
DrawAddress( ptr ); DrawAddress( ptr+i );
ImGui::PopStyleColor(); ImGui::PopStyleColor();
} }
else else
{ {
DrawAddress( ptr ); DrawAddress( ptr+i );
if( ImGui::IsItemClicked() ) if( ImGui::IsItemClicked() )
{ {
m_memoryAllocInfoWindow = arrIdx; m_memoryAllocInfoWindow = arrIdx;
@ -12785,7 +12788,7 @@ void View::ListMemData( T ptr, T end, std::function<void(T&)> DrawAddress, const
SmallCallstackButton( "free", v->csFree.Val(), idx ); SmallCallstackButton( "free", v->csFree.Val(), idx );
} }
ImGui::NextColumn(); ImGui::NextColumn();
ptr++; }
} }
ImGui::EndColumns(); ImGui::EndColumns();
ImGui::EndChild(); ImGui::EndChild();
@ -13232,7 +13235,7 @@ void View::DrawMemory()
} }
else else
{ {
ListMemData<decltype( match.begin() )>( match.begin(), match.end(), [this]( auto& it ) { ListMemData<decltype( match.begin() )>( match.begin(), match.end(), [this]( auto it ) {
auto& v = *it; auto& v = *it;
if( v->Ptr() == m_memInfo.ptrFind ) if( v->Ptr() == m_memInfo.ptrFind )
{ {
@ -13289,7 +13292,7 @@ void View::DrawMemory()
if( !items.empty() ) if( !items.empty() )
{ {
ListMemData<decltype( items.begin() )>( items.begin(), items.end(), []( auto& v ) { ListMemData<decltype( items.begin() )>( items.begin(), items.end(), []( auto v ) {
ImGui::Text( "0x%" PRIx64, (*v)->Ptr() ); ImGui::Text( "0x%" PRIx64, (*v)->Ptr() );
}, "##activeMem" ); }, "##activeMem" );
} }
@ -13559,7 +13562,7 @@ void View::DrawAllocList()
ImGui::SetNextWindowSize( ImVec2( 1100, 500 ), ImGuiCond_FirstUseEver ); ImGui::SetNextWindowSize( ImVec2( 1100, 500 ), ImGuiCond_FirstUseEver );
ImGui::Begin( "Allocations list", &m_memInfo.showAllocList ); ImGui::Begin( "Allocations list", &m_memInfo.showAllocList );
TextFocused( "Number of allocations:", RealToString( m_memInfo.allocList.size() ) ); TextFocused( "Number of allocations:", RealToString( m_memInfo.allocList.size() ) );
ListMemData<decltype( data.begin() )>( data.begin(), data.end(), []( auto& v ) { ListMemData<decltype( data.begin() )>( data.begin(), data.end(), []( auto v ) {
ImGui::Text( "0x%" PRIx64, (*v)->Ptr() ); ImGui::Text( "0x%" PRIx64, (*v)->Ptr() );
}, "##allocations" ); }, "##allocations" );
ImGui::End(); ImGui::End();

View File

@ -154,7 +154,7 @@ private:
void DrawAnnotationList(); void DrawAnnotationList();
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 );
unordered_flat_map<uint32_t, PathData> GetCallstackPaths( const MemData& mem, bool onlyActive ) const; unordered_flat_map<uint32_t, PathData> GetCallstackPaths( const MemData& mem, bool onlyActive ) const;
unordered_flat_map<uint64_t, CallstackFrameTree> GetCallstackFrameTreeBottomUp( const MemData& mem ) const; unordered_flat_map<uint64_t, CallstackFrameTree> GetCallstackFrameTreeBottomUp( const MemData& mem ) const;