mirror of
https://github.com/ceph/ceph
synced 2025-02-20 17:37:29 +00:00
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 <john.spray@redhat.com>
This commit is contained in:
parent
ac30e6cee2
commit
3283b1e409
@ -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<void(
|
||||
const PerfCountersCollection::CounterMap &)> 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;
|
||||
}
|
||||
|
||||
|
@ -68,52 +68,6 @@ enum perfcounter_type_d
|
||||
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()
|
||||
@ -176,6 +130,53 @@ private:
|
||||
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;
|
||||
@ -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<std::string,
|
||||
PerfCounters::perf_counter_data_any_d *> CounterMap;
|
||||
|
||||
void with_counters(std::function<void(const CounterMap &)>) const;
|
||||
|
||||
private:
|
||||
CephContext *m_cct;
|
||||
|
||||
@ -226,6 +234,8 @@ private:
|
||||
|
||||
perf_counters_set_t m_loggers;
|
||||
|
||||
std::map<std::string, PerfCounters::perf_counter_data_any_d *> by_path;
|
||||
|
||||
friend class PerfCountersCollectionTest;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user