]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
perfcounters: tolerate multiple loggers with the same name
authorSage Weil <sage.weil@dreamhost.com>
Sun, 22 Apr 2012 21:23:52 +0000 (14:23 -0700)
committerSage Weil <sage.weil@dreamhost.com>
Sun, 22 Apr 2012 21:23:52 +0000 (14:23 -0700)
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>
src/common/perf_counters.cc
src/common/perf_counters.h

index 9936524a0c52284d9a8bf66be3920fc89e63a2cb..6e41d7238056ce46b26fa7f86165179f629c35ee 100644 (file)
@@ -40,8 +40,17 @@ PerfCountersCollection::~PerfCountersCollection()
 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);
 }
 
index 43a74f7fe1de63946610572fb63de5b18db25112..31bfce3456e34684067c2d5dbc913aa8838c5de2 100644 (file)
@@ -76,6 +76,9 @@ public:
   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,
@@ -102,7 +105,7 @@ private:
   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 */