From 0a19c8b043a07a435f33a4d7b3c0bf904f354fe1 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 23 Aug 2025 13:09:59 -0400 Subject: [PATCH] xo-alloc: track GC efficiency --- include/xo/alloc/GcStatistics.hpp | 11 +++++++++++ src/alloc/GcStatistics.cpp | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/xo/alloc/GcStatistics.hpp b/include/xo/alloc/GcStatistics.hpp index d0f54084..c0058b5f 100644 --- a/include/xo/alloc/GcStatistics.hpp +++ b/include/xo/alloc/GcStatistics.hpp @@ -176,6 +176,17 @@ namespace xo { dt_{dt} {} constexpr GcStatisticsHistoryItem(const GcStatisticsHistoryItem &) = default; + std::size_t garbage_z() const { return garbage0_z_ + garbage1_z_ + garbageN_z_; } + + float efficiency() const { + std::size_t gz = this->garbage_z(); + + return gz / static_cast(effort_z_ + gz); + } + + /** collection rate, in bytes/sec **/ + float collection_rate() const; + GcStatisticsHistoryItem & operator=(const GcStatisticsHistoryItem & x) { gc_seq_ = x.gc_seq_; upto_ = x.upto_; diff --git a/src/alloc/GcStatistics.cpp b/src/alloc/GcStatistics.cpp index 72624403..deb30685 100644 --- a/src/alloc/GcStatistics.cpp +++ b/src/alloc/GcStatistics.cpp @@ -103,6 +103,23 @@ namespace xo { << ">"; } + float + GcStatisticsHistoryItem::collection_rate() const { + using namespace xo::qty::qty; + + float gz = this->garbage_z(); + + auto dt_nanos = this->dt_.with_repr(); + auto dt_sec = dt_nanos.rescale_ext(); + auto rate = gz / dt_sec; + float retval = rate.scale(); + + //scope log(XO_DEBUG(true)); + //log && log(xtag("gz", gz), xtag("dt_sec", dt_sec), xtag("rate", rate), xtag("rate/sec", retval)); + + return retval; + } + void GcStatisticsHistoryItem::display(std::ostream & os) const {