diff --git a/xo-arena/include/xo/arena/MemorySizeInfo.hpp b/xo-arena/include/xo/arena/MemorySizeInfo.hpp index 540453fd..764eae6d 100644 --- a/xo-arena/include/xo/arena/MemorySizeInfo.hpp +++ b/xo-arena/include/xo/arena/MemorySizeInfo.hpp @@ -15,15 +15,18 @@ namespace xo { struct MemorySizeInfo { using size_type = std::size_t; - MemorySizeInfo(std::string_view name, std::size_t a, std::size_t c, std::size_t r) - : resource_name_{name}, allocated_{a}, committed_{c}, reserved_{r} + MemorySizeInfo() = default; + MemorySizeInfo(std::string_view name, std::size_t u, std::size_t a, std::size_t c, std::size_t r) + : resource_name_{name}, used_{u}, allocated_{a}, committed_{c}, reserved_{r} {} - static MemorySizeInfo sentinel() { return MemorySizeInfo("", 0, 0, 0); } + static MemorySizeInfo sentinel() { return MemorySizeInfo(); } /** resource name **/ std::string_view resource_name_; - /** memory in-use **/ + /** memory used (excluding wasted space) **/ + std::size_t used_ = 0; + /** memory allocated (including wasted space e.g. empty slots in hash tables **/ std::size_t allocated_ = 0; /** memory committed (backed by physical memory) **/ std::size_t committed_ = 0; diff --git a/xo-arena/include/xo/arena/hashmap/HashMapStore.hpp b/xo-arena/include/xo/arena/hashmap/HashMapStore.hpp index 436e88ed..6393bb02 100644 --- a/xo-arena/include/xo/arena/hashmap/HashMapStore.hpp +++ b/xo-arena/include/xo/arena/hashmap/HashMapStore.hpp @@ -20,6 +20,7 @@ namespace xo { using control_vector_type = xo::mm::DArenaVector; using slot_vector_type = xo::mm::DArenaVector; using MemorySizeVisitor = xo::mm::MemorySizeVisitor; + using MemorySizeInfo = xo::mm::MemorySizeInfo; public: /** group_exp2: number of groups {x, 2^x} **/ @@ -51,8 +52,20 @@ namespace xo { float load_factor() const noexcept { return size_ / static_cast(n_slot_); } void visit_pools(const MemorySizeVisitor & visitor) const { - control_.visit_pools(visitor); - slots_.visit_pools(visitor); + // complexity here in service of HashMapStore-specific value for MemorySizeInfo.used + + MemorySizeInfo ctl_info; + MemorySizeInfo slot_info; + + control_.visit_pools([&ctl_info](const auto & x) { ctl_info = x; }); + slots_.visit_pools([&slot_info](const auto & x) { slot_info = x; }); + + // control: 1 byte per (key,value) pair + ctl_info.used_ = size_; + slot_info.used_ = size_ * sizeof(value_type); + + visitor(ctl_info); + visitor(slot_info); } void resize_from_empty(const std::pairallocated() /*used*/, this->allocated(), this->committed(), this->reserved())); diff --git a/xo-arena/src/arena/DCircularBuffer.cpp b/xo-arena/src/arena/DCircularBuffer.cpp index 372462f4..e5b1c725 100644 --- a/xo-arena/src/arena/DCircularBuffer.cpp +++ b/xo-arena/src/arena/DCircularBuffer.cpp @@ -83,6 +83,7 @@ namespace xo { DCircularBuffer::visit_pools(const MemorySizeVisitor & visitor) const { visitor(MemorySizeInfo(config_.name_, + occupied_range_.size() /*used*/, occupied_range_.size(), mapped_range_.size(), reserved_range_.size())); diff --git a/xo-interpreter2/utest/VirtualSchematikaMachine.test.cpp b/xo-interpreter2/utest/VirtualSchematikaMachine.test.cpp index a4970b72..9c70f85c 100644 --- a/xo-interpreter2/utest/VirtualSchematikaMachine.test.cpp +++ b/xo-interpreter2/utest/VirtualSchematikaMachine.test.cpp @@ -80,6 +80,7 @@ namespace xo { auto visitor = [&log](const MemorySizeInfo & info) { log && log(xtag("resource", info.resource_name_), + xtag("used", info.used_), xtag("alloc", info.allocated_), xtag("commit", info.committed_), xtag("resv", info.reserved_));