Store ordered list of memory frees.

This commit is contained in:
Bartosz Taudul 2018-05-02 17:59:50 +02:00
parent ce1f56ea0f
commit b18841aa75
2 changed files with 18 additions and 33 deletions

View File

@ -236,6 +236,7 @@ struct PlotData
struct MemData struct MemData
{ {
Vector<MemEvent> data; Vector<MemEvent> data;
Vector<uint64_t> frees;
flat_hash_map<uint64_t, size_t, nohash<uint64_t>> active; flat_hash_map<uint64_t, size_t, nohash<uint64_t>> active;
uint64_t high = std::numeric_limits<uint64_t>::min(); uint64_t high = std::numeric_limits<uint64_t>::min();
uint64_t low = std::numeric_limits<uint64_t>::max(); uint64_t low = std::numeric_limits<uint64_t>::max();

View File

@ -530,6 +530,10 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
{ {
m_data.memory.active.emplace( mem->ptr, i ); m_data.memory.active.emplace( mem->ptr, i );
} }
else
{
m_data.memory.frees.push_back( i );
}
mem++; mem++;
} }
@ -1881,6 +1885,7 @@ void Worker::ProcessMemFree( const QueueMemFree& ev )
auto it = m_data.memory.active.find( ev.ptr ); auto it = m_data.memory.active.find( ev.ptr );
assert( it != m_data.memory.active.end() ); assert( it != m_data.memory.active.end() );
m_data.memory.frees.push_back( it->second );
auto& mem = m_data.memory.data[it->second]; auto& mem = m_data.memory.data[it->second];
mem.timeFree = time; mem.timeFree = time;
mem.threadFree = CompressThread( ev.thread ); mem.threadFree = CompressThread( ev.thread );
@ -1922,31 +1927,10 @@ void Worker::CreateMemAllocPlot()
void Worker::ReconstructMemAllocPlot() void Worker::ReconstructMemAllocPlot()
{ {
struct FreeData auto& mem = m_data.memory;
{ pdqsort_branchless( mem.frees.begin(), mem.frees.end(), [&mem] ( const auto& lhs, const auto& rhs ) { return mem.data[lhs].timeFree < mem.data[rhs].timeFree; } );
int64_t time;
double size;
};
Vector<FreeData> frees; const auto psz = mem.data.size() + mem.frees.size() + 1;
{
frees.reserve( m_data.memory.data.size() );
auto ptr = frees.data();
for( auto& v : m_data.memory.data )
{
if( v.timeFree >= 0 )
{
ptr->time = v.timeFree;
ptr->size = double( int64_t( v.size ) );
ptr++;
}
}
frees.set_size( ptr - frees.data() );
}
pdqsort_branchless( frees.begin(), frees.end(), [] ( const auto& lhs, const auto& rhs ) { return lhs.time < rhs.time; } );
const auto psz = m_data.memory.data.size() + frees.size() + 1;
PlotData* plot; PlotData* plot;
{ {
@ -1958,10 +1942,10 @@ void Worker::ReconstructMemAllocPlot()
plot->type = PlotType::Memory; plot->type = PlotType::Memory;
plot->data.reserve_and_use( psz ); plot->data.reserve_and_use( psz );
auto aptr = m_data.memory.data.begin(); auto aptr = mem.data.begin();
auto aend = m_data.memory.data.end(); auto aend = mem.data.end();
auto fptr = frees.begin(); auto fptr = mem.frees.begin();
auto fend = frees.end(); auto fend = mem.frees.end();
double max = 0; double max = 0;
double usage = 0; double usage = 0;
@ -1974,7 +1958,7 @@ void Worker::ReconstructMemAllocPlot()
if( aptr != aend && fptr != fend ) if( aptr != aend && fptr != fend )
{ {
auto atime = aptr->timeAlloc; auto atime = aptr->timeAlloc;
auto ftime = fptr->time; auto ftime = mem.data[*fptr].timeFree;
for(;;) for(;;)
{ {
@ -1992,7 +1976,7 @@ void Worker::ReconstructMemAllocPlot()
} }
else else
{ {
usage -= fptr->size; usage -= int64_t( mem.data[*fptr].size );
assert( usage >= 0 ); assert( usage >= 0 );
if( max < usage ) max = usage; if( max < usage ) max = usage;
ptr->time = ftime; ptr->time = ftime;
@ -2000,7 +1984,7 @@ void Worker::ReconstructMemAllocPlot()
ptr++; ptr++;
fptr++; fptr++;
if( fptr == fend ) break; if( fptr == fend ) break;
ftime = fptr->time; ftime = mem.data[*fptr].timeFree;
} }
} }
} }
@ -2019,8 +2003,8 @@ void Worker::ReconstructMemAllocPlot()
} }
while( fptr != fend ) while( fptr != fend )
{ {
int64_t time = fptr->time; int64_t time = mem.data[*fptr].timeFree;
usage -= fptr->size; usage -= int64_t( mem.data[*fptr].size );
assert( usage >= 0 ); assert( usage >= 0 );
assert( max >= usage ); assert( max >= usage );
ptr->time = time; ptr->time = time;