1
0
mirror of https://github.com/wolfpld/tracy synced 2025-05-03 14:03:52 +00:00

Add waiting dots to memory data in zone info window.

This commit is contained in:
Bartosz Taudul 2019-03-07 00:57:32 +01:00
parent d547700e50
commit 6e4bc7d9c5

View File

@ -4330,104 +4330,112 @@ void View::DrawZoneInfoWindow()
ImGui::TextDisabled( "(%.2f%%)", 100.f * selftime / ztime ); ImGui::TextDisabled( "(%.2f%%)", 100.f * selftime / ztime );
auto& mem = m_worker.GetMemData(); auto& mem = m_worker.GetMemData();
if( mem.plot ) if( !mem.data.empty() )
{ {
ImGui::Separator(); ImGui::Separator();
const auto thread = m_worker.CompressThread( tid ); if( !mem.plot )
auto ait = std::lower_bound( mem.data.begin(), mem.data.end(), ev.start, [] ( const auto& l, const auto& r ) { return l.timeAlloc < r; } );
const auto aend = std::upper_bound( mem.data.begin(), mem.data.end(), end, [] ( const auto& l, const auto& r ) { return l < r.timeAlloc; } );
auto fit = std::lower_bound( mem.frees.begin(), mem.frees.end(), ev.start, [&mem] ( const auto& l, const auto& r ) { return mem.data[l].timeFree < r; } );
const auto fend = std::upper_bound( mem.frees.begin(), mem.frees.end(), end, [&mem] ( const auto& l, const auto& r ) { return l < mem.data[r].timeFree; } );
const auto aDist = std::distance( ait, aend );
const auto fDist = std::distance( fit, fend );
if( aDist == 0 && fDist == 0 )
{ {
ImGui::TextUnformatted( "No memory events." ); ImGui::Text( "Please wait, computing data..." );
DrawWaitingDots( s_time );
} }
else else
{ {
int64_t cAlloc = 0; const auto thread = m_worker.CompressThread( tid );
int64_t cFree = 0;
int64_t nAlloc = 0;
int64_t nFree = 0;
auto ait2 = ait; auto ait = std::lower_bound( mem.data.begin(), mem.data.end(), ev.start, [] ( const auto& l, const auto& r ) { return l.timeAlloc < r; } );
auto fit2 = fit; const auto aend = std::upper_bound( mem.data.begin(), mem.data.end(), end, [] ( const auto& l, const auto& r ) { return l < r.timeAlloc; } );
while( ait != aend ) auto fit = std::lower_bound( mem.frees.begin(), mem.frees.end(), ev.start, [&mem] ( const auto& l, const auto& r ) { return mem.data[l].timeFree < r; } );
{ const auto fend = std::upper_bound( mem.frees.begin(), mem.frees.end(), end, [&mem] ( const auto& l, const auto& r ) { return l < mem.data[r].timeFree; } );
if( ait->threadAlloc == thread )
{
cAlloc += ait->size;
nAlloc++;
}
ait++;
}
while( fit != fend )
{
if( mem.data[*fit].threadFree == thread )
{
cFree += mem.data[*fit].size;
nFree++;
}
fit++;
}
if( nAlloc == 0 && nFree == 0 ) const auto aDist = std::distance( ait, aend );
const auto fDist = std::distance( fit, fend );
if( aDist == 0 && fDist == 0 )
{ {
ImGui::TextUnformatted( "No memory events." ); ImGui::TextUnformatted( "No memory events." );
} }
else else
{ {
ImGui::TextUnformatted( RealToString( nAlloc + nFree, true ) ); int64_t cAlloc = 0;
ImGui::SameLine(); int64_t cFree = 0;
TextDisabledUnformatted( "memory events." ); int64_t nAlloc = 0;
ImGui::TextUnformatted( RealToString( nAlloc, true ) ); int64_t nFree = 0;
ImGui::SameLine();
TextDisabledUnformatted( "allocs," );
ImGui::SameLine();
ImGui::TextUnformatted( RealToString( nFree, true ) );
ImGui::SameLine();
TextDisabledUnformatted( "frees." );
TextFocused( "Memory allocated:", MemSizeToString( cAlloc ) );
TextFocused( "Memory freed:", MemSizeToString( cFree ) );
TextFocused( "Overall change:", MemSizeToString( cAlloc - cFree ) );
if( ImGui::TreeNode( "Allocations list" ) ) auto ait2 = ait;
auto fit2 = fit;
while( ait != aend )
{ {
std::vector<const MemEvent*> v; if( ait->threadAlloc == thread )
v.reserve( nAlloc + nFree );
auto it = ait2;
while( it != aend )
{ {
if( it->threadAlloc == thread ) cAlloc += ait->size;
{ nAlloc++;
v.emplace_back( it );
}
it++;
} }
while( fit2 != fend ) ait++;
}
while( fit != fend )
{
if( mem.data[*fit].threadFree == thread )
{ {
const auto ptr = &mem.data[*fit2++]; cFree += mem.data[*fit].size;
if( ptr->threadFree == thread ) nFree++;
}
fit++;
}
if( nAlloc == 0 && nFree == 0 )
{
ImGui::TextUnformatted( "No memory events." );
}
else
{
ImGui::TextUnformatted( RealToString( nAlloc + nFree, true ) );
ImGui::SameLine();
TextDisabledUnformatted( "memory events." );
ImGui::TextUnformatted( RealToString( nAlloc, true ) );
ImGui::SameLine();
TextDisabledUnformatted( "allocs," );
ImGui::SameLine();
ImGui::TextUnformatted( RealToString( nFree, true ) );
ImGui::SameLine();
TextDisabledUnformatted( "frees." );
TextFocused( "Memory allocated:", MemSizeToString( cAlloc ) );
TextFocused( "Memory freed:", MemSizeToString( cFree ) );
TextFocused( "Overall change:", MemSizeToString( cAlloc - cFree ) );
if( ImGui::TreeNode( "Allocations list" ) )
{
std::vector<const MemEvent*> v;
v.reserve( nAlloc + nFree );
auto it = ait2;
while( it != aend )
{ {
if( ptr < ait2 || ptr >= aend ) if( it->threadAlloc == thread )
{ {
v.emplace_back( ptr ); v.emplace_back( it );
}
it++;
}
while( fit2 != fend )
{
const auto ptr = &mem.data[*fit2++];
if( ptr->threadFree == thread )
{
if( ptr < ait2 || ptr >= aend )
{
v.emplace_back( ptr );
}
} }
} }
} 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 );
} ); } );
ImGui::TreePop(); ImGui::TreePop();
}
} }
} }
} }