]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Put each ProfLogger's data into its own object
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 19 Jul 2011 18:04:45 +0000 (11:04 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 19 Jul 2011 18:04:45 +0000 (11:04 -0700)
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/common/ProfLogger.cc
src/common/ProfLogger.h
src/test/proflogger.cc

index ece016da621c71777046619e8ad0a207e7b0cd2e..c93f0d82a382401b1b1081c6653c5af890a07b3f 100644 (file)
@@ -526,12 +526,23 @@ fget(int idx) const
   return data.u.dbl;
 }
 
+static inline void append_to_vector(std::vector <char> &buffer, char *buf)
+{
+  size_t strlen_buf = strlen(buf);
+  std::vector<char>::size_type sz = buffer.size();
+  buffer.resize(sz + strlen_buf);
+  memcpy(&buffer[sz], buf, strlen_buf);
+}
+
 void ProfLogger::
 write_json_to_buf(std::vector <char> &buffer)
 {
   char buf[512];
   Mutex::Locker lck(m_lock);
 
+  snprintf(buf, sizeof(buf), "'%s':{", m_name.c_str());
+  append_to_vector(buffer, buf);
+
   prof_log_data_vec_t::const_iterator d = m_data.begin();
   prof_log_data_vec_t::const_iterator d_end = m_data.end();
   for (; d != d_end; ++d) {
@@ -568,11 +579,10 @@ write_json_to_buf(std::vector <char> &buffer)
          break;
       }
     }
-    size_t strlen_buf = strlen(buf);
-    std::vector<char>::size_type sz = buffer.size();
-    buffer.resize(sz + strlen_buf);
-    memcpy(&buffer[sz], buf, strlen_buf);
+    append_to_vector(buffer, buf);
   }
+
+  buffer.push_back('}');
 }
 
 const std::string &ProfLogger::
@@ -587,8 +597,9 @@ ProfLogger(CephContext *cct, const std::string &name,
   : m_cct(cct),
     m_lower_bound(lower_bound),
     m_upper_bound(upper_bound),
-    m_name(std::string("ProfLogger::") + name.c_str()),
-    m_lock(m_name.c_str())
+    m_name(name.c_str()),
+    m_lock_name(std::string("ProfLogger::") + name.c_str()),
+    m_lock(m_lock_name.c_str())
 {
   m_data.resize(upper_bound - lower_bound - 1);
 }
index d7db2aa8510d14608f0f485a920b7b65f8419657..9dd058b45f3b561adef88b3364ff8c70e985790c 100644 (file)
@@ -76,6 +76,7 @@ private:
   int m_lower_bound;
   int m_upper_bound;
   const std::string m_name;
+  const std::string m_lock_name;
 
   /** Protects m_data */
   mutable Mutex m_lock;
index 0bd8338e148fe4cb761aeaa997b2fdbd4d2cfc8c..4d2c856f028b29f56efd8d043119ba15a7b0b40e 100644 (file)
@@ -201,16 +201,19 @@ TEST(ProfLogger, SingleProfLogger) {
   ProfLoggerTestClient test_client(get_socket_path());
   std::string msg;
   ASSERT_EQ("", test_client.get_message(&msg));
-  ASSERT_EQ("{'element1':0,'element2':0,'element3':{'count':0,'sum':0},}", msg);
+  ASSERT_EQ("{'fake_proflogger_1':{'element1':0,"
+           "'element2':0,'element3':{'count':0,'sum':0},}}", msg);
   fake_pf->inc(FAKE_PROFLOGGER1_ELEMENT_1);
   fake_pf->fset(FAKE_PROFLOGGER1_ELEMENT_2, 0.5);
   fake_pf->finc(FAKE_PROFLOGGER1_ELEMENT_3, 100.0);
   ASSERT_EQ("", test_client.get_message(&msg));
-  ASSERT_EQ("{'element1':1,'element2':0.5,'element3':{'count':1,'sum':100},}", msg);
+  ASSERT_EQ("{'fake_proflogger_1':{'element1':1,"
+           "'element2':0.5,'element3':{'count':1,'sum':100},}}", msg);
   fake_pf->finc(FAKE_PROFLOGGER1_ELEMENT_3, 0.0);
   fake_pf->finc(FAKE_PROFLOGGER1_ELEMENT_3, 25.0);
   ASSERT_EQ("", test_client.get_message(&msg));
-  ASSERT_EQ("{'element1':1,'element2':0.5,'element3':{'count':3,'sum':125},}", msg);
+  ASSERT_EQ("{'fake_proflogger_1':{'element1':1,'element2':0.5,"
+           "'element3':{'count':3,'sum':125},}}", msg);
 }
 
 enum {
@@ -243,16 +246,19 @@ TEST(ProfLogger, MultipleProfloggers) {
   std::string msg;
 
   ASSERT_EQ("", test_client.get_message(&msg));
-  ASSERT_EQ("{'element1':0,'element2':0,'element3':{'count':0,'sum':0},'foo':0,'bar':0,}", msg);
+  ASSERT_EQ("{'fake_proflogger_1':{'element1':0,'element2':0,'element3':"
+           "{'count':0,'sum':0},}'fake_proflogger_2':{'foo':0,'bar':0,}}", msg);
 
   fake_pf1->inc(FAKE_PROFLOGGER1_ELEMENT_1);
   fake_pf1->inc(FAKE_PROFLOGGER1_ELEMENT_1, 5);
   ASSERT_EQ("", test_client.get_message(&msg));
-  ASSERT_EQ("{'element1':6,'element2':0,'element3':{'count':0,'sum':0},'foo':0,'bar':0,}", msg);
+  ASSERT_EQ("{'fake_proflogger_1':{'element1':6,'element2':0,'element3':"
+           "{'count':0,'sum':0},}'fake_proflogger_2':{'foo':0,'bar':0,}}", msg);
 
   coll->logger_remove(fake_pf2);
   ASSERT_EQ("", test_client.get_message(&msg));
-  ASSERT_EQ("{'element1':6,'element2':0,'element3':{'count':0,'sum':0},}", msg);
+  ASSERT_EQ("{'fake_proflogger_1':{'element1':6,'element2':0,"
+           "'element3':{'count':0,'sum':0},}}", msg);
 
   coll->logger_clear();
   ASSERT_EQ("", test_client.get_message(&msg));