From 78cd86dd69bb8f2721b8d6bbb659fe19b6af4f8e Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 2 Apr 2018 18:14:59 +0200 Subject: [PATCH] Memory pages bitmap calculation. --- server/TracyView.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++ server/TracyView.hpp | 2 ++ 2 files changed, 78 insertions(+) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index f2ab9915..2b419673 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -3940,6 +3940,82 @@ void View::DrawMemory() ImGui::End(); } +enum { ChunkBits = 10 }; +enum { ChunkSize = 1 << ChunkBits }; +enum { PageBits = 10 }; +enum { PageChunkBits = ChunkBits + PageBits }; +enum { PageSize = 1 << PageChunkBits }; +enum { PageMask = PageSize - 1 }; + +static tracy_force_inline void PreparePage( Vector& page ) +{ + if( page.empty() ) + { + page.reserve_and_use( ChunkSize ); + memset( page.data(), 0, ChunkSize ); + } +} + +Vector> View::GetMemoryPages() const +{ + Vector> ret; + + const auto& mem = m_worker.GetMemData(); + const auto span = mem.high - mem.low; + const auto pages = ( span / PageSize ) + 1; + + ret.reserve_and_use( pages ); + memset( ret.data(), 0, pages * sizeof( Vector ) ); + + for( auto& alloc : mem.data ) + { + const auto a0 = alloc->ptr - mem.low; + const auto a1 = a0 + alloc->size; + const auto p0 = a0 >> PageChunkBits; + const auto p1 = a1 >> PageChunkBits; + + int8_t val = alloc->timeFree < 0 ? 1 : -1; + + if( p0 == p1 ) + { + auto& page = ret[p0]; + PreparePage( page ); + const auto b0 = a0 & PageMask; + const auto b1 = a1 & PageMask; + const auto c0 = b0 >> ChunkBits; + const auto c1 = ( b1 >> ChunkBits ) + 1; + memset( page.data() + c0, val, c1 - c0 ); + } + else + { + { + auto& page = ret[p0]; + PreparePage( page ); + const auto b0 = a0 & PageMask; + const auto c0 = b0 >> ChunkBits; + memset( page.data() + c0, val, ChunkSize - c0 ); + } + + for( uint64_t i=p0+1; i> ChunkBits ) + 1; + memset( page.data(), val, c1 ); + } + } + } + + return ret; +} + uint32_t View::GetZoneColor( const ZoneEvent& ev ) { const auto& srcloc = m_worker.GetSourceLocation( ev.srcloc ); diff --git a/server/TracyView.hpp b/server/TracyView.hpp index bdec35d6..d1be0c07 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -109,6 +109,8 @@ private: void FindZones(); #endif + Vector> GetMemoryPages() const; + flat_hash_map> m_visible; flat_hash_map> m_showFull;