From: John Spray Date: Thu, 30 Jun 2016 13:06:42 +0000 (+0100) Subject: common: accessors for list of perf counters X-Git-Tag: v11.0.1~60^2~58 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3283b1e4097cf85a102d208eda5252f27b13c10b;p=ceph.git common: accessors for list of perf counters ...and store the list by a string path, for consumption by the world outside of integer perf counter/subsystem IDs. This is for consumption by MgrClient. Signed-off-by: John Spray --- diff --git a/src/common/perf_counters.cc b/src/common/perf_counters.cc index 2b80a25c029d..499ee89d59b3 100644 --- a/src/common/perf_counters.cc +++ b/src/common/perf_counters.cc @@ -55,11 +55,32 @@ void PerfCountersCollection::add(class PerfCounters *l) } m_loggers.insert(l); + + for (unsigned int i = 0; i < l->m_data.size(); ++i) { + PerfCounters::perf_counter_data_any_d &data = l->m_data[i]; + + std::string path = l->get_name(); + path += "."; + path += data.name; + + by_path[path] = &data; + } } void PerfCountersCollection::remove(class PerfCounters *l) { Mutex::Locker lck(m_lock); + + for (unsigned int i = 0; i < l->m_data.size(); ++i) { + PerfCounters::perf_counter_data_any_d &data = l->m_data[i]; + + std::string path = l->get_name(); + path += "."; + path += data.name; + + by_path.erase(path); + } + perf_counters_set_t::iterator i = m_loggers.find(l); assert(i != m_loggers.end()); m_loggers.erase(i); @@ -73,6 +94,8 @@ void PerfCountersCollection::clear() for (; i != i_end; ) { m_loggers.erase(i++); } + + by_path.clear(); } bool PerfCountersCollection::reset(const std::string &name) @@ -132,6 +155,14 @@ void PerfCountersCollection::dump_formatted( f->close_section(); } +void PerfCountersCollection::with_counters(std::function fn) const +{ + Mutex::Locker lck(m_lock); + + fn(by_path); +} + // --------------------------- PerfCounters::~PerfCounters() @@ -449,3 +480,4 @@ PerfCounters *PerfCountersBuilder::create_perf_counters() m_perf_counters = NULL; return ret; } + diff --git a/src/common/perf_counters.h b/src/common/perf_counters.h index 5a462f968d43..dc3a21a68a84 100644 --- a/src/common/perf_counters.h +++ b/src/common/perf_counters.h @@ -68,52 +68,6 @@ enum perfcounter_type_d class PerfCounters { public: - template - struct avg_tracker { - pair last; - pair cur; - avg_tracker() : last(0, 0), cur(0, 0) {} - T avg() const { - if (cur.first == last.first) - return cur.first ? - cur.second / cur.first : - 0; // no change, report avg over all time - return (cur.second - last.second) / (cur.first - last.first); - } - void consume_next(const pair &next) { - last = cur; - cur = next; - } - }; - - ~PerfCounters(); - - void inc(int idx, uint64_t v = 1); - void dec(int idx, uint64_t v = 1); - void set(int idx, uint64_t v); - uint64_t get(int idx) const; - - void tset(int idx, utime_t v); - void tinc(int idx, utime_t v); - void tinc(int idx, ceph::timespan v); - utime_t tget(int idx) const; - - void reset(); - void dump_formatted(ceph::Formatter *f, bool schema, - const std::string &counter = ""); - pair get_tavg_ms(int idx) const; - - const std::string& get_name() const; - void set_name(std::string s) { - m_name = s; - } - -private: - PerfCounters(CephContext *cct, const std::string &name, - int lower_bound, int upper_bound); - PerfCounters(const PerfCounters &rhs); - PerfCounters& operator=(const PerfCounters &rhs); - /** Represents a PerfCounters data element. */ struct perf_counter_data_any_d { perf_counter_data_any_d() @@ -176,6 +130,53 @@ private: return make_pair(sum, count); } }; + + template + struct avg_tracker { + pair last; + pair cur; + avg_tracker() : last(0, 0), cur(0, 0) {} + T avg() const { + if (cur.first == last.first) + return cur.first ? + cur.second / cur.first : + 0; // no change, report avg over all time + return (cur.second - last.second) / (cur.first - last.first); + } + void consume_next(const pair &next) { + last = cur; + cur = next; + } + }; + + ~PerfCounters(); + + void inc(int idx, uint64_t v = 1); + void dec(int idx, uint64_t v = 1); + void set(int idx, uint64_t v); + uint64_t get(int idx) const; + + void tset(int idx, utime_t v); + void tinc(int idx, utime_t v); + void tinc(int idx, ceph::timespan v); + utime_t tget(int idx) const; + + void reset(); + void dump_formatted(ceph::Formatter *f, bool schema, + const std::string &counter = ""); + pair get_tavg_ms(int idx) const; + + const std::string& get_name() const; + void set_name(std::string s) { + m_name = s; + } + +private: + PerfCounters(CephContext *cct, const std::string &name, + int lower_bound, int upper_bound); + PerfCounters(const PerfCounters &rhs); + PerfCounters& operator=(const PerfCounters &rhs); + typedef std::vector perf_counter_data_vec_t; CephContext *m_cct; @@ -190,6 +191,7 @@ private: perf_counter_data_vec_t m_data; friend class PerfCountersBuilder; + friend class PerfCountersCollection; }; class SortPerfCountersByName { @@ -218,6 +220,12 @@ public: bool schema, const std::string &logger = "", const std::string &counter = ""); + + typedef std::map CounterMap; + + void with_counters(std::function) const; + private: CephContext *m_cct; @@ -226,6 +234,8 @@ private: perf_counters_set_t m_loggers; + std::map by_path; + friend class PerfCountersCollectionTest; };