Create memory plot based on memory alloc/free events.

This commit is contained in:
Bartosz Taudul 2018-04-28 15:49:12 +02:00
parent cd34ed6968
commit d8bfe7de2e
3 changed files with 40 additions and 1 deletions

View File

@ -236,6 +236,7 @@ struct MemData
uint64_t high = std::numeric_limits<uint64_t>::min();
uint64_t low = std::numeric_limits<uint64_t>::max();
uint64_t usage = 0;
PlotData* plot = nullptr;
};
struct StringLocation

View File

@ -1853,17 +1853,52 @@ void Worker::ProcessMemAlloc( const QueueMemAlloc& ev )
m_data.memory.low = std::min( low, ptr );
m_data.memory.high = std::max( high, ptrend );
m_data.memory.usage += size;
MemAllocChanged( time );
}
void Worker::ProcessMemFree( const QueueMemFree& ev )
{
const auto time = TscTime( ev.time );
auto it = m_data.memory.active.find( ev.ptr );
assert( it != m_data.memory.active.end() );
auto& mem = m_data.memory.data[it->second];
mem.timeFree = TscTime( ev.time );
mem.timeFree = time;
mem.threadFree = CompressThread( ev.thread );
m_data.memory.usage -= mem.size;
m_data.memory.active.erase( it );
MemAllocChanged( time );
}
void Worker::MemAllocChanged( int64_t time )
{
const auto val = (double)m_data.memory.usage;
if( !m_data.memory.plot )
{
CreateMemAllocPlot();
m_data.memory.plot->min = val;
m_data.memory.plot->max = val;
m_data.memory.plot->data.push_back( { time, val } );
}
else
{
assert( !m_data.memory.plot->data.empty() );
assert( m_data.memory.plot->data.back().time <= time );
if( m_data.memory.plot->min > val ) m_data.memory.plot->min = val;
else if( m_data.memory.plot->max < val ) m_data.memory.plot->max = val;
m_data.memory.plot->data.push_back_non_empty( { time, val } );
}
}
void Worker::CreateMemAllocPlot()
{
assert( !m_data.memory.plot );
m_data.memory.plot = m_slab.AllocInit<PlotData>();
m_data.memory.plot->name = 0;
m_data.memory.plot->type = PlotType::Memory;
m_data.plots.push_back( m_data.memory.plot );
}
void Worker::ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t thread )

View File

@ -208,6 +208,9 @@ private:
tracy_force_inline uint32_t ShrinkSourceLocation( uint64_t srcloc );
uint32_t NewShrinkedSourceLocation( uint64_t srcloc );
tracy_force_inline void MemAllocChanged( int64_t time );
void CreateMemAllocPlot();
void InsertMessageData( MessageData* msg, uint64_t thread );
ThreadData* NewThread( uint64_t thread );