Move memory allocations table drawing to a separate function.

This commit is contained in:
Bartosz Taudul 2018-04-02 02:19:46 +02:00
parent 1fa943d109
commit c4a36398f6
2 changed files with 104 additions and 89 deletions

View File

@ -3650,50 +3650,8 @@ void View::DrawStatistics()
ImGui::End();
}
void View::DrawMemory()
{
auto& mem = m_worker.GetMemData();
ImGui::Begin( "Memory", &m_memInfo.show );
ImGui::Text( "Total allocations: %-10s Active allocations: %-10s Memory usage: %s bytes", RealToString( mem.data.size(), true ), RealToString( mem.active.size(), true ), RealToString( mem.usage, true ) );
ImGui::InputText( "", m_memInfo.pattern, 1024 );
ImGui::SameLine();
if( ImGui::Button( "Find" ) )
{
m_memInfo.ptrFind = strtoull( m_memInfo.pattern, nullptr, 0 );
}
ImGui::SameLine();
if( ImGui::Button( "Clear" ) )
{
m_memInfo.ptrFind = 0;
m_memInfo.pattern[0] = '\0';
}
if( m_memInfo.ptrFind != 0 )
{
std::vector<MemEvent*> match;
for( auto& v : mem.data )
{
if( v->ptr <= m_memInfo.ptrFind && v->ptr + v->size > m_memInfo.ptrFind )
{
match.emplace_back( v );
}
}
ImGui::Separator();
if( match.empty() )
{
ImGui::Text( "Found no allocations at given address" );
}
else
{
bool expand = ImGui::TreeNodeEx( "Allocations", ImGuiTreeNodeFlags_DefaultOpen );
ImGui::SameLine();
ImGui::TextDisabled( "(%s)", RealToString( match.size(), true ) );
if( expand )
template<class T>
void View::ListMemData( T ptr, T end, std::function<MemEvent*(T&)> DrawAddress )
{
ImGui::Columns( 6 );
ImGui::Text( "Address" );
@ -3728,16 +3686,9 @@ void View::DrawMemory()
ImGui::NextColumn();
ImGui::Separator();
int idx = 0;
for( auto& v : match )
while( ptr != end )
{
if( v->ptr == m_memInfo.ptrFind )
{
ImGui::Text( "0x%" PRIx64, m_memInfo.ptrFind );
}
else
{
ImGui::Text( "0x%" PRIx64 "+%" PRIu64, v->ptr, m_memInfo.ptrFind - v->ptr );
}
auto v = DrawAddress( ptr );
ImGui::NextColumn();
ImGui::Text( "%s", RealToString( v->size, true ) );
ImGui::NextColumn();
@ -3790,8 +3741,68 @@ void View::DrawMemory()
}
}
ImGui::NextColumn();
ptr++;
}
ImGui::EndColumns();
}
void View::DrawMemory()
{
auto& mem = m_worker.GetMemData();
ImGui::Begin( "Memory", &m_memInfo.show );
ImGui::Text( "Total allocations: %-10s Active allocations: %-10s Memory usage: %s bytes", RealToString( mem.data.size(), true ), RealToString( mem.active.size(), true ), RealToString( mem.usage, true ) );
ImGui::InputText( "", m_memInfo.pattern, 1024 );
ImGui::SameLine();
if( ImGui::Button( "Find" ) )
{
m_memInfo.ptrFind = strtoull( m_memInfo.pattern, nullptr, 0 );
}
ImGui::SameLine();
if( ImGui::Button( "Clear" ) )
{
m_memInfo.ptrFind = 0;
m_memInfo.pattern[0] = '\0';
}
if( m_memInfo.ptrFind != 0 )
{
std::vector<MemEvent*> match;
for( auto& v : mem.data )
{
if( v->ptr <= m_memInfo.ptrFind && v->ptr + v->size > m_memInfo.ptrFind )
{
match.emplace_back( v );
}
}
ImGui::Separator();
if( match.empty() )
{
ImGui::Text( "Found no allocations at given address" );
}
else
{
bool expand = ImGui::TreeNodeEx( "Allocations", ImGuiTreeNodeFlags_DefaultOpen );
ImGui::SameLine();
ImGui::TextDisabled( "(%s)", RealToString( match.size(), true ) );
if( expand )
{
ListMemData<decltype( match.begin() )>( match.begin(), match.end(), [this]( auto& it ) {
auto& v = *it;
if( v->ptr == m_memInfo.ptrFind )
{
ImGui::Text( "0x%" PRIx64, m_memInfo.ptrFind );
}
else
{
ImGui::Text( "0x%" PRIx64 "+%" PRIu64, v->ptr, m_memInfo.ptrFind - v->ptr );
}
return v;
} );
ImGui::TreePop();
}
}

View File

@ -2,6 +2,7 @@
#define __TRACYVIEW_HPP__
#include <atomic>
#include <functional>
#include <map>
#include <string>
#include <thread>
@ -76,6 +77,9 @@ private:
void DrawStatistics();
void DrawMemory();
template<class T>
void ListMemData( T ptr, T end, std::function<MemEvent*(T&)> DrawAddress );
void DrawInfoWindow();
void DrawZoneInfoWindow();
void DrawGpuInfoWindow();