From 1164ef2f32d81d4f35623c3f6a77af2b6871f962 Mon Sep 17 00:00:00 2001 From: Boris Ranto Date: Tue, 15 May 2018 10:27:53 +0200 Subject: [PATCH] mgr: Expose avgcount for long running avgs This provides a basic interface to export avg count for long running averages. Signed-off-by: Boris Ranto --- src/mgr/ActivePyModules.cc | 25 ++++++++++++++++++------- src/mgr/DaemonState.cc | 12 ++++++++++-- src/mgr/DaemonState.h | 28 ++++++++++++++++++++++++++-- 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index 99a2fa12a6405..cbd9b9571558f 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -589,13 +589,24 @@ PyObject* ActivePyModules::get_counter_python( Mutex::Locker l2(metadata->lock); if (metadata->perf_counters.instances.count(path)) { auto counter_instance = metadata->perf_counters.instances.at(path); - const auto &data = counter_instance.get_data(); - for (const auto &datapoint : data) { - f.open_array_section("datapoint"); - f.dump_unsigned("t", datapoint.t.sec()); - f.dump_unsigned("v", datapoint.v); - f.close_section(); - + auto counter_type = metadata->perf_counters.types.at(path); + if (counter_type.type & PERFCOUNTER_LONGRUNAVG) { + const auto &data = counter_instance.get_data(); + for (const auto &datapoint : data) { + f.open_array_section("datapoint"); + f.dump_unsigned("t", datapoint.t.sec()); + f.dump_unsigned("v", datapoint.v); + f.close_section(); + } + } else { + const auto &avg_data = counter_instance.get_data_avg(); + for (const auto &datapoint : avg_data) { + f.open_array_section("datapoint"); + f.dump_unsigned("t", datapoint.t.sec()); + f.dump_unsigned("s", datapoint.s); + f.dump_unsigned("c", datapoint.c); + f.close_section(); + } } } else { dout(4) << "Missing counter: '" << path << "' (" diff --git a/src/mgr/DaemonState.cc b/src/mgr/DaemonState.cc index 57c3cf64a647b..e2f0922079f23 100644 --- a/src/mgr/DaemonState.cc +++ b/src/mgr/DaemonState.cc @@ -141,6 +141,8 @@ void DaemonPerfCounters::update(MMgrReport *report) for (const auto &t : report->declare_types) { types.insert(std::make_pair(t.path, t)); session->declared_types.insert(t.path); + instances.insert(std::pair( + t.path, PerfCounterInstance(t.type))); } // Remove any old types for (const auto &t : report->undeclare_types) { @@ -162,9 +164,10 @@ void DaemonPerfCounters::update(MMgrReport *report) if (t.type & PERFCOUNTER_LONGRUNAVG) { decode(avgcount, p); decode(avgcount2, p); + instances.at(t_path).push_avg(now, val, avgcount); + } else { + instances.at(t_path).push(now, val); } - // TODO: interface for insertion of avgs - instances[t_path].push(now, val); } DECODE_FINISH(p); } @@ -179,3 +182,8 @@ void PerfCounterInstance::push(utime_t t, uint64_t const &v) buffer.push_back({t, v}); } +void PerfCounterInstance::push_avg(utime_t t, uint64_t const &s, + uint64_t const &c) +{ + avg_buffer.push_back({t, s, c}); +} diff --git a/src/mgr/DaemonState.h b/src/mgr/DaemonState.h index 7124965264d2a..9a9d9ab3aabca 100644 --- a/src/mgr/DaemonState.h +++ b/src/mgr/DaemonState.h @@ -45,7 +45,20 @@ class PerfCounterInstance {} }; + class AvgDataPoint + { + public: + utime_t t; + uint64_t s; + uint64_t c; + AvgDataPoint(utime_t t_, uint64_t s_, uint64_t c_) + : t(t_), s(s_), c(c_) + {} + }; + boost::circular_buffer buffer; + boost::circular_buffer avg_buffer; + uint64_t get_current() const; public: @@ -53,9 +66,20 @@ class PerfCounterInstance { return buffer; } + const boost::circular_buffer & get_data_avg() const + { + return avg_buffer; + } void push(utime_t t, uint64_t const &v); - PerfCounterInstance() - : buffer(20) {} + void push_avg(utime_t t, uint64_t const &s, uint64_t const &c); + + PerfCounterInstance(enum perfcounter_type_d type) + { + if (type & PERFCOUNTER_LONGRUNAVG) + avg_buffer = boost::circular_buffer(20); + else + buffer = boost::circular_buffer(20); + }; }; -- 2.39.5