Make them unique by appending -<ptr>, so that the json we dump will remain
valid.
We may also want to allow people to share counters of the same type.
Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
void PerfCountersCollection::add(class PerfCounters *l)
{
Mutex::Locker lck(m_lock);
- perf_counters_set_t::iterator i = m_loggers.find(l);
- assert(i == m_loggers.end());
+
+ // make sure the name is unique
+ perf_counters_set_t::iterator i;
+ i = m_loggers.find(l);
+ while (i != m_loggers.end()) {
+ ostringstream ss;
+ ss << l->get_name() << "-" << (void*)l;
+ l->set_name(ss.str());
+ i = m_loggers.find(l);
+ }
+
m_loggers.insert(l);
}
void write_json_to_buf(std::vector <char> &buffer, bool schema);
const std::string& get_name() const;
+ void set_name(std::string s) {
+ m_name = s;
+ }
private:
PerfCounters(CephContext *cct, const std::string &name,
CephContext *m_cct;
int m_lower_bound;
int m_upper_bound;
- const std::string m_name;
+ std::string m_name;
const std::string m_lock_name;
/** Protects m_data */