From 5cdc8566876d043f820f805eb3e005f13828c64d Mon Sep 17 00:00:00 2001 From: Ali Maredia Date: Thu, 3 Nov 2022 16:52:46 -0400 Subject: [PATCH] common: add base counters for perf counters cache Signed-off-by: Ali Maredia --- src/common/perf_counters_cache.h | 25 ++++++++++++++++++++++--- src/rgw/rgw_perf_counters.cc | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/common/perf_counters_cache.h b/src/common/perf_counters_cache.h index efc7c62734916..3d831f637f33d 100644 --- a/src/common/perf_counters_cache.h +++ b/src/common/perf_counters_cache.h @@ -16,6 +16,9 @@ private: std::unordered_map cache; + ceph::common::LabeledPerfCounters* base_counters; + std::string base_counters_name; + public: ceph::common::LabeledPerfCounters* get(std::string key) { @@ -51,20 +54,34 @@ public: auto labeled_counters = get(label); if(labeled_counters) { labeled_counters->inc(indx, v); + base_counters->inc(indx, v); } } void dec(std::string label, int indx, uint64_t v) { auto labeled_counters = get(label); if(labeled_counters) { - labeled_counters->inc(indx, v); + labeled_counters->dec(indx, v); + base_counters->dec(indx, v); } } void set_counter(std::string label, int indx, uint64_t val) { auto labeled_counters = get(label); if(labeled_counters) { + uint64_t old_val = labeled_counters->get(indx); labeled_counters->set(indx, val); + + // apply new value to totals in base counters + // need to make sure value of delta is positive since it is unsigned + uint64_t delta = 0; + if((old_val > val) && base_counters) { + delta = old_val - val; + base_counters->dec(indx, delta); + } else if(base_counters) { + delta = val - old_val; + base_counters->inc(indx, delta); + } } } @@ -88,9 +105,11 @@ public: } PerfCountersCache(CephContext *_cct, size_t _target_size, int _lower_bound, int _upper_bound, - std::function _lpcb_init) : cct(_cct), + std::function _lpcb_init, std::string _base_counters_name) : cct(_cct), target_size(_target_size), lower_bound(_lower_bound), upper_bound(_upper_bound), - lpcb_init(_lpcb_init) {} + lpcb_init(_lpcb_init), base_counters_name(_base_counters_name) { + base_counters = add(base_counters_name); + } ~PerfCountersCache() {} diff --git a/src/rgw/rgw_perf_counters.cc b/src/rgw/rgw_perf_counters.cc index a3c7300f901aa..c13c5cd2f37b2 100644 --- a/src/rgw/rgw_perf_counters.cc +++ b/src/rgw/rgw_perf_counters.cc @@ -70,7 +70,7 @@ int rgw_perf_start(CephContext *cct) std::function lpcb_init = add_rgw_counters; uint64_t target_size = cct->_conf.get_val("rgw_labeled_perfcounters_size"); - perf_counters_cache = new PerfCountersCache(cct, target_size, l_rgw_first, l_rgw_last, lpcb_init); + perf_counters_cache = new PerfCountersCache(cct, target_size, l_rgw_first, l_rgw_last, lpcb_init, "rgw"); return 0; } -- 2.39.5