mirror of
https://github.com/wolfpld/tracy.git
synced 2026-06-08 08:33:48 +00:00
Compare commits
6 Commits
e5aa8eba51
...
memsnapsho
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1fdfdb0cc1 | ||
|
|
da4d0aa1b8 | ||
|
|
c9423365e9 | ||
|
|
28ae35ed16 | ||
|
|
5f51339fc9 | ||
|
|
ab7c8684fe |
@@ -9376,7 +9376,68 @@ static tracy_force_inline void FillPages( flat_hash_map<uint64_t, MemoryPage, no
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<MemoryPage> View::GetMemoryPages() const
|
||||
enum { AllocsInSnap = 1024 * 1024 };
|
||||
|
||||
void View::CreateNextMemPageSnapshot()
|
||||
{
|
||||
const auto& memData = m_worker.GetMemData();
|
||||
const auto& mem = memData.data;
|
||||
const auto memlow = memData.low;
|
||||
|
||||
const auto snapSz = m_memInfo.pageSnap.size();
|
||||
const auto beginAlloc = AllocsInSnap * snapSz;
|
||||
const auto endAlloc = AllocsInSnap * ( snapSz + 1 );
|
||||
assert( mem.size() >= endAlloc );
|
||||
const auto tBegin = beginAlloc == 0 ? 0 : mem[beginAlloc-1].timeAlloc;
|
||||
const auto tEnd = mem[endAlloc-1].timeAlloc;
|
||||
|
||||
flat_hash_map<uint64_t, MemoryPage, nohash<uint64_t>> memmap;
|
||||
if( !m_memInfo.pageSnap.empty() )
|
||||
{
|
||||
const auto& snap = m_memInfo.pageSnap.back();
|
||||
for( auto& page : snap ) memmap.emplace( page.page, page );
|
||||
}
|
||||
|
||||
const auto begin = mem.begin() + beginAlloc;
|
||||
const auto end = mem.begin() + endAlloc;
|
||||
|
||||
for( auto it = mem.begin(); it != end; ++it )
|
||||
{
|
||||
auto& alloc = *it;
|
||||
if( it < begin && ( alloc.timeFree < tBegin || alloc.timeFree > tEnd ) ) continue;
|
||||
|
||||
const auto a0 = alloc.ptr - memlow;
|
||||
const auto a1 = a0 + alloc.size;
|
||||
int8_t val = alloc.timeFree < 0 ?
|
||||
int8_t( std::max( int64_t( 1 ), 127 - ( ( tEnd - alloc.timeAlloc ) >> 24 ) ) ) :
|
||||
int8_t( -std::max( int64_t( 1 ), 127 - ( ( tEnd - alloc.timeFree ) >> 24 ) ) );
|
||||
|
||||
const auto c0 = a0 >> ChunkBits;
|
||||
const auto c1 = a1 >> ChunkBits;
|
||||
|
||||
FillPages( memmap, c0, c1, val );
|
||||
}
|
||||
|
||||
std::vector<MemoryPage> snap;
|
||||
snap.reserve( memmap.size() );
|
||||
for( auto& page : memmap )
|
||||
{
|
||||
snap.emplace_back( page.second );
|
||||
}
|
||||
m_memInfo.pageSnap.emplace_back( std::move( snap ) );
|
||||
}
|
||||
|
||||
size_t View::GetMemoryPagesSnapshot( size_t allocNum, int64_t timeAdj, flat_hash_map<uint64_t, MemoryPage, nohash<uint64_t>>& memmap )
|
||||
{
|
||||
const auto snapNum = allocNum / AllocsInSnap;
|
||||
if( snapNum == 0 ) return 0;
|
||||
while( m_memInfo.pageSnap.size() < snapNum ) CreateNextMemPageSnapshot();
|
||||
const auto& snap = m_memInfo.pageSnap[snapNum-1];
|
||||
for( auto& page : snap ) memmap.emplace( page.page, page );
|
||||
return snapNum * AllocsInSnap;
|
||||
}
|
||||
|
||||
std::vector<MemoryPage> View::GetMemoryPages()
|
||||
{
|
||||
std::vector<MemoryPage> ret;
|
||||
|
||||
@@ -9388,11 +9449,36 @@ std::vector<MemoryPage> View::GetMemoryPages() const
|
||||
if( m_memInfo.restrictTime )
|
||||
{
|
||||
const auto zvMid = m_zvStart + ( m_zvEnd - m_zvStart ) / 2;
|
||||
auto end = std::upper_bound( mem.data.begin(), mem.data.end(), zvMid, []( const auto& lhs, const auto& rhs ) { return lhs < rhs.timeAlloc; } );
|
||||
for( auto it = mem.data.begin(); it != end; ++it )
|
||||
const auto end = std::upper_bound( mem.data.begin(), mem.data.end(), zvMid, []( const auto& lhs, const auto& rhs ) { return lhs < rhs.timeAlloc; } );
|
||||
const auto sz = std::distance( mem.data.begin(), end );
|
||||
const auto snapSz = GetMemoryPagesSnapshot( sz, zvMid, memmap );
|
||||
|
||||
const auto begin = mem.data.begin() + snapSz;
|
||||
if( snapSz != 0 )
|
||||
{
|
||||
const auto tBegin = mem.data[snapSz-1].timeAlloc;
|
||||
for( auto it = mem.data.begin(); it != begin; ++it )
|
||||
{
|
||||
if( it->timeFree < tBegin ) continue;
|
||||
|
||||
auto& alloc = *it;
|
||||
const auto a0 = alloc.ptr - memlow;
|
||||
const auto a1 = a0 + alloc.size;
|
||||
int8_t val = alloc.timeFree < 0 ?
|
||||
int8_t( std::max( int64_t( 1 ), 127 - ( ( zvMid - alloc.timeAlloc ) >> 24 ) ) ) :
|
||||
( alloc.timeFree > zvMid ?
|
||||
int8_t( std::max( int64_t( 1 ), 127 - ( ( zvMid - alloc.timeAlloc ) >> 24 ) ) ) :
|
||||
int8_t( -std::max( int64_t( 1 ), 127 - ( ( zvMid - alloc.timeFree ) >> 24 ) ) ) );
|
||||
|
||||
const auto c0 = a0 >> ChunkBits;
|
||||
const auto c1 = a1 >> ChunkBits;
|
||||
|
||||
FillPages( memmap, c0, c1, val );
|
||||
}
|
||||
}
|
||||
for( auto it = begin; it != end; ++it )
|
||||
{
|
||||
auto& alloc = *it;
|
||||
|
||||
const auto a0 = alloc.ptr - memlow;
|
||||
const auto a1 = a0 + alloc.size;
|
||||
int8_t val = alloc.timeFree < 0 ?
|
||||
@@ -9410,8 +9496,34 @@ std::vector<MemoryPage> View::GetMemoryPages() const
|
||||
else
|
||||
{
|
||||
const auto lastTime = m_worker.GetLastTime();
|
||||
for( auto& alloc : mem.data )
|
||||
const auto sz = mem.data.size();
|
||||
const auto snapSz = GetMemoryPagesSnapshot( sz, lastTime, memmap );
|
||||
const auto end = mem.data.end();
|
||||
|
||||
const auto begin = mem.data.begin() + snapSz;
|
||||
if( snapSz != 0 )
|
||||
{
|
||||
const auto tBegin = mem.data[snapSz-1].timeAlloc;
|
||||
for( auto it = mem.data.begin(); it != begin; ++it )
|
||||
{
|
||||
if( it->timeFree < tBegin ) continue;
|
||||
|
||||
auto& alloc = *it;
|
||||
const auto a0 = alloc.ptr - memlow;
|
||||
const auto a1 = a0 + alloc.size;
|
||||
const int8_t val = alloc.timeFree < 0 ?
|
||||
int8_t( std::max( int64_t( 1 ), 127 - ( ( lastTime - std::min( lastTime, alloc.timeAlloc ) ) >> 24 ) ) ) :
|
||||
int8_t( -std::max( int64_t( 1 ), 127 - ( ( lastTime - std::min( lastTime, alloc.timeFree ) ) >> 24 ) ) );
|
||||
|
||||
const auto c0 = a0 >> ChunkBits;
|
||||
const auto c1 = a1 >> ChunkBits;
|
||||
|
||||
FillPages( memmap, c0, c1, val );
|
||||
}
|
||||
}
|
||||
for( auto it = begin; it != end; ++it )
|
||||
{
|
||||
auto& alloc = *it;
|
||||
const auto a0 = alloc.ptr - memlow;
|
||||
const auto a1 = a0 + alloc.size;
|
||||
const int8_t val = alloc.timeFree < 0 ?
|
||||
|
||||
@@ -181,7 +181,10 @@ private:
|
||||
void FindZonesCompare();
|
||||
#endif
|
||||
|
||||
std::vector<MemoryPage> GetMemoryPages() const;
|
||||
std::vector<MemoryPage> GetMemoryPages();
|
||||
size_t GetMemoryPagesSnapshot( size_t allocNum, int64_t timeAdj, flat_hash_map<uint64_t, MemoryPage, nohash<uint64_t>>& memmap );
|
||||
void CreateNextMemPageSnapshot();
|
||||
|
||||
const char* GetPlotName( const PlotData* plot ) const;
|
||||
|
||||
void SmallCallstackButton( const char* name, uint32_t callstack, int& idx, bool tooltip = true );
|
||||
@@ -462,6 +465,7 @@ private:
|
||||
bool restrictTime = false;
|
||||
bool showAllocList = false;
|
||||
std::vector<size_t> allocList;
|
||||
std::vector<std::vector<MemoryPage>> pageSnap;
|
||||
} m_memInfo;
|
||||
|
||||
struct {
|
||||
|
||||
Reference in New Issue
Block a user