1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Store memory pages in a contiguous memory area.

This commit is contained in:
Bartosz Taudul 2018-04-03 19:17:32 +02:00
parent 5ce3e44c77
commit f0573d68bd
2 changed files with 32 additions and 57 deletions

View File

@ -3952,22 +3952,25 @@ void View::DrawMemory()
auto pages = GetMemoryPages(); auto pages = GetMemoryPages();
size_t lines = pages.size(); const int8_t empty[PageSize] = {};
size_t i = 0; const auto sz = pages.size() / PageSize;
while( i < pages.size() ) auto pgptr = pages.data();
const auto end = pgptr + sz * PageSize;
size_t lines = sz;
while( pgptr != end )
{ {
if( pages[i].empty() ) if( memcmp( empty, pgptr, PageSize ) == 0 )
{ {
i++; pgptr += PageSize;
while( i < pages.size() && pages[i].empty() ) while( pgptr != end && memcmp( empty, pgptr, PageSize ) == 0 )
{ {
lines--; lines--;
i++; pgptr += PageSize;
} }
} }
else else
{ {
i++; pgptr += PageSize;
} }
} }
@ -3978,44 +3981,43 @@ void View::DrawMemory()
draw->AddRectFilled( wpos, wpos + ImVec2( PageSize, lines ), 0xFF666666 ); draw->AddRectFilled( wpos, wpos + ImVec2( PageSize, lines ), 0xFF666666 );
size_t line = 0; size_t line = 0;
i = 0; pgptr = pages.data();
while( i < pages.size() ) while( pgptr != end )
{ {
auto& page = pages[i]; if( memcmp( empty, pgptr, PageSize ) == 0 )
if( page.empty() )
{ {
i++; pgptr += PageSize;
draw->AddLine( wpos + ImVec2( 0, line ), wpos + ImVec2( PageSize, line ), 0xFF555555 ); draw->AddLine( wpos + ImVec2( 0, line ), wpos + ImVec2( PageSize, line ), 0xFF555555 );
line++; line++;
while( pages[i].empty() ) i++; while( pgptr != end && memcmp( empty, pgptr, PageSize ) == 0 ) pgptr += PageSize;
} }
else else
{ {
size_t idx = 0; size_t idx = 0;
while( idx < PageSize ) while( idx < PageSize )
{ {
if( page[idx] == 0 ) if( pgptr[idx] == 0 )
{ {
do do
{ {
idx++; idx++;
} }
while( idx < PageSize && page[idx] == 0 ); while( idx < PageSize && pgptr[idx] == 0 );
} }
else else
{ {
auto val = page[idx]; auto val = pgptr[idx];
const auto i0 = idx; const auto i0 = idx;
do do
{ {
idx++; idx++;
} }
while( idx < PageSize && page[idx] == val ); while( idx < PageSize && pgptr[idx] == val );
draw->AddLine( wpos + ImVec2( i0, line ), wpos + ImVec2( idx, line ), val > 0 ? 0xFF44FF44 : 0xFF4444FF ); draw->AddLine( wpos + ImVec2( i0, line ), wpos + ImVec2( idx, line ), val > 0 ? 0xFF44FF44 : 0xFF4444FF );
} }
} }
line++; line++;
i++; pgptr += PageSize;
} }
} }
@ -4026,27 +4028,17 @@ void View::DrawMemory()
ImGui::End(); ImGui::End();
} }
static void PreparePageInit( Vector<int8_t>& page ) Vector<int8_t> View::GetMemoryPages() const
{ {
page.reserve_and_use( PageSize ); Vector<int8_t> ret;
memset( page.data(), 0, PageSize );
}
static tracy_force_inline void PreparePage( Vector<int8_t>& page )
{
if( page.empty() ) PreparePageInit( page );
}
Vector<Vector<int8_t>> View::GetMemoryPages() const
{
Vector<Vector<int8_t>> ret;
const auto& mem = m_worker.GetMemData(); const auto& mem = m_worker.GetMemData();
const auto span = mem.high - mem.low; const auto span = mem.high - mem.low;
const auto pages = ( span / PageChunkSize ) + 1; const auto pages = ( span / PageChunkSize ) + 1;
ret.reserve_and_use( pages ); ret.reserve_and_use( pages * PageSize );
memset( ret.data(), 0, pages * sizeof( Vector<int8_t> ) ); auto pgptr = ret.data();
memset( pgptr, 0, pages * PageSize );
const auto zvMid = m_zvStart + ( m_zvEnd - m_zvStart ) / 2; const auto zvMid = m_zvStart + ( m_zvEnd - m_zvStart ) / 2;
@ -4068,37 +4060,20 @@ Vector<Vector<int8_t>> View::GetMemoryPages() const
if( p0 == p1 ) if( p0 == p1 )
{ {
auto& page = ret[p0]; auto page = pgptr + p0 * PageSize;
PreparePage( page );
if( c0 == c1 ) if( c0 == c1 )
{ {
*( page.data() + c0 ) = val; page[c0] = val;
} }
else else
{ {
memset( page.data() + c0, val, c1 - c0 + 1 ); memset( page + c0, val, c1 - c0 + 1 );
} }
} }
else else
{ {
{ auto page = pgptr + p0 * PageSize;
auto& page = ret[p0]; memset( page + c0, val, ( PageSize - c0 ) + PageSize * ( p1 - p0 - 1 ) + ( c1 + 1 ) );
PreparePage( page );
memset( page.data() + c0, val, PageSize - c0 );
}
for( uint64_t i=p0+1; i<p1; i++ )
{
auto& page = ret[i];
if( page.empty() ) page.reserve_and_use( PageSize );
memset( page.data(), val, PageSize );
}
{
auto& page = ret[p1];
PreparePage( page );
memset( page.data(), val, c1 + 1 );
}
} }
} }

View File

@ -109,7 +109,7 @@ private:
void FindZones(); void FindZones();
#endif #endif
Vector<Vector<int8_t>> GetMemoryPages() const; Vector<int8_t> GetMemoryPages() const;
flat_hash_map<const void*, bool, nohash<const void*>> m_visible; flat_hash_map<const void*, bool, nohash<const void*>> m_visible;
flat_hash_map<const void*, bool, nohash<const void*>> m_showFull; flat_hash_map<const void*, bool, nohash<const void*>> m_showFull;