From 0eefbfa3ccec3faada8a2fc2f0a82c8fb16ec633 Mon Sep 17 00:00:00 2001 From: Michael Livshin Date: Sun, 15 May 2022 22:30:12 +0300 Subject: [PATCH] utils: logalloc: add arithmetic operations to segment_pool::stats Signed-off-by: Michael Livshin --- utils/logalloc.cc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/utils/logalloc.cc b/utils/logalloc.cc index f908fe999e..f0da1cf612 100644 --- a/utils/logalloc.cc +++ b/utils/logalloc.cc @@ -866,6 +866,35 @@ public: uint64_t memory_freed; uint64_t memory_compacted; uint64_t memory_evicted; + + friend stats operator+(const stats& s1, const stats& s2) { + stats result(s1); + result += s2; + return result; + } + friend stats operator-(const stats& s1, const stats& s2) { + stats result(s1); + result -= s2; + return result; + } + stats& operator+=(const stats& other) { + segments_compacted += other.segments_compacted; + lsa_buffer_segments += other.lsa_buffer_segments; + memory_allocated += other.memory_allocated; + memory_freed += other.memory_freed; + memory_compacted += other.memory_compacted; + memory_evicted += other.memory_evicted; + return *this; + } + stats& operator-=(const stats& other) { + segments_compacted -= other.segments_compacted; + lsa_buffer_segments -= other.lsa_buffer_segments; + memory_allocated -= other.memory_allocated; + memory_freed -= other.memory_freed; + memory_compacted -= other.memory_compacted; + memory_evicted -= other.memory_evicted; + return *this; + } }; private: stats _stats{};