}
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);
for (; i != i_end; ) {
m_loggers.erase(i++);
}
+
+ by_path.clear();
}
bool PerfCountersCollection::reset(const std::string &name)
f->close_section();
}
+void PerfCountersCollection::with_counters(std::function<void(
+ const PerfCountersCollection::CounterMap &)> fn) const
+{
+ Mutex::Locker lck(m_lock);
+
+ fn(by_path);
+}
+
// ---------------------------
PerfCounters::~PerfCounters()
m_perf_counters = NULL;
return ret;
}
+
class PerfCounters
{
public:
- template <typename T>
- struct avg_tracker {
- pair<uint64_t, T> last;
- pair<uint64_t, T> 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<uint64_t, T> &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<uint64_t, uint64_t> 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()
return make_pair(sum, count);
}
};
+
+ template <typename T>
+ struct avg_tracker {
+ pair<uint64_t, T> last;
+ pair<uint64_t, T> 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<uint64_t, T> &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<uint64_t, uint64_t> 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_any_d> perf_counter_data_vec_t;
CephContext *m_cct;
perf_counter_data_vec_t m_data;
friend class PerfCountersBuilder;
+ friend class PerfCountersCollection;
};
class SortPerfCountersByName {
bool schema,
const std::string &logger = "",
const std::string &counter = "");
+
+ typedef std::map<std::string,
+ PerfCounters::perf_counter_data_any_d *> CounterMap;
+
+ void with_counters(std::function<void(const CounterMap &)>) const;
+
private:
CephContext *m_cct;
perf_counters_set_t m_loggers;
+ std::map<std::string, PerfCounters::perf_counter_data_any_d *> by_path;
+
friend class PerfCountersCollectionTest;
};