]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: add optional perf counter nickname
authorJohn Spray <john.spray@redhat.com>
Tue, 3 Feb 2015 16:47:32 +0000 (16:47 +0000)
committerJohn Spray <john.spray@redhat.com>
Thu, 5 Mar 2015 20:17:19 +0000 (20:17 +0000)
This has two purposes:

* Identify counters that are useful in short/summary views
  of a daemon's performance (only these have a nick set)
* Provide shortened versions of names that are suitable
  for display in a text-mode columnar view.

Signed-off-by: John Spray <john.spray@redhat.com>
src/common/perf_counters.cc
src/common/perf_counters.h
src/test/perf_counters.cc

index ecf28f2abeebea125cb842bac07b228312846d8d..0c86f130b5a29495ab95d928b6ac8668f6ed1fad 100644 (file)
@@ -292,10 +292,18 @@ void PerfCounters::dump_formatted(Formatter *f, bool schema,
     if (schema) {
       f->open_object_section(d->name);
       f->dump_int("type", d->type);
-      if (d->description)
+
+      if (d->description) {
         f->dump_string("description", d->description);
-      else 
+      } else {
         f->dump_string("description", "");
+      }
+
+      if (d->nick != NULL) {
+        f->dump_string("nick", d->nick);
+      } else {
+        f->dump_string("nick", "");
+      }
       f->close_section();
     } else {
       if (d->type & PERFCOUNTER_LONGRUNAVG) {
@@ -360,32 +368,38 @@ PerfCountersBuilder::~PerfCountersBuilder()
   m_perf_counters = NULL;
 }
 
-void PerfCountersBuilder::add_u64_counter(int idx, const char *name, const char *description)
+void PerfCountersBuilder::add_u64_counter(int idx, const char *name,
+    const char *description, const char *nick)
 {
-  add_impl(idx, name, description, PERFCOUNTER_U64 | PERFCOUNTER_COUNTER);
+  add_impl(idx, name, description, nick, PERFCOUNTER_U64 | PERFCOUNTER_COUNTER);
 }
 
-void PerfCountersBuilder::add_u64(int idx, const char *name, const char *description)
+void PerfCountersBuilder::add_u64(int idx, const char *name,
+    const char *description, const char *nick)
 {
-  add_impl(idx, name, description, PERFCOUNTER_U64);
+  add_impl(idx, name, description, nick, PERFCOUNTER_U64);
 }
 
-void PerfCountersBuilder::add_u64_avg(int idx, const char *name, const char *description)
+void PerfCountersBuilder::add_u64_avg(int idx, const char *name,
+    const char *description, const char *nick)
 {
-  add_impl(idx, name, description, PERFCOUNTER_U64 | PERFCOUNTER_LONGRUNAVG);
+  add_impl(idx, name, description, nick, PERFCOUNTER_U64 | PERFCOUNTER_LONGRUNAVG);
 }
 
-void PerfCountersBuilder::add_time(int idx, const char *name, const char *description)
+void PerfCountersBuilder::add_time(int idx, const char *name,
+    const char *description, const char *nick)
 {
-  add_impl(idx, name, description, PERFCOUNTER_TIME);
+  add_impl(idx, name, description, nick, PERFCOUNTER_TIME);
 }
 
-void PerfCountersBuilder::add_time_avg(int idx, const char *name, const char *description)
+void PerfCountersBuilder::add_time_avg(int idx, const char *name,
+    const char *description, const char *nick)
 {
-  add_impl(idx, name, description, PERFCOUNTER_TIME | PERFCOUNTER_LONGRUNAVG);
+  add_impl(idx, name, description, nick, PERFCOUNTER_TIME | PERFCOUNTER_LONGRUNAVG);
 }
 
-void PerfCountersBuilder::add_impl(int idx, const char *name, const char *description, int ty)
+void PerfCountersBuilder::add_impl(int idx, const char *name,
+    const char *description, const char *nick, int ty)
 {
   assert(idx > m_perf_counters->m_lower_bound);
   assert(idx < m_perf_counters->m_upper_bound);
@@ -395,6 +409,7 @@ void PerfCountersBuilder::add_impl(int idx, const char *name, const char *descri
   assert(data.type == PERFCOUNTER_NONE);
   data.name = name;
   data.description = description;
+  data.nick = nick;
   data.type = (enum perfcounter_type_d)ty;
 }
 
index 3e427bf2e9a60102f71ac313be439803abb2f3fc..34f406768a2b24447d8558d0f20b103cb6aa60c8 100644 (file)
@@ -115,16 +115,18 @@ private:
     perf_counter_data_any_d()
       : name(NULL),
         description(NULL),
-               type(PERFCOUNTER_NONE),
-               u64(0),
-               avgcount(0),
-               avgcount2(0)
+        nick(NULL),
+       type(PERFCOUNTER_NONE),
+       u64(0),
+       avgcount(0),
+       avgcount2(0)
     {}
     perf_counter_data_any_d(const perf_counter_data_any_d& other)
       : name(other.name),
         description(other.description),
-               type(other.type),
-               u64(other.u64.read()) {
+        nick(other.nick),
+       type(other.type),
+       u64(other.u64.read()) {
       pair<uint64_t,uint64_t> a = other.read_avg();
       u64.set(a.first);
       avgcount.set(a.second);
@@ -133,6 +135,7 @@ private:
 
     const char *name;
     const char *description;
+    const char *nick;
     enum perfcounter_type_d type;
     atomic64_t u64;
     atomic64_t avgcount;
@@ -150,6 +153,7 @@ private:
     perf_counter_data_any_d& operator=(const perf_counter_data_any_d& other) {
       name = other.name;
       description = other.description;
+      nick = other.nick;
       type = other.type;
       pair<uint64_t,uint64_t> a = other.read_avg();
       u64.set(a.first);
@@ -235,16 +239,22 @@ public:
   PerfCountersBuilder(CephContext *cct, const std::string &name,
                    int first, int last);
   ~PerfCountersBuilder();
-  void add_u64(int key, const char *name, const char *description = NULL);
-  void add_u64_counter(int key, const char *name, const char *description = NULL);
-  void add_u64_avg(int key, const char *name, const char *description = NULL);
-  void add_time(int key, const char *name, const char *description = NULL);
-  void add_time_avg(int key, const char *name, const char *description = NULL);
+  void add_u64(int key, const char *name,
+      const char *description=NULL, const char *nick = NULL);
+  void add_u64_counter(int key, const char *name,
+      const char *description=NULL, const char *nick = NULL);
+  void add_u64_avg(int key, const char *name,
+      const char *description=NULL, const char *nick = NULL);
+  void add_time(int key, const char *name,
+      const char *description=NULL, const char *nick = NULL);
+  void add_time_avg(int key, const char *name,
+      const char *description=NULL, const char *nick = NULL);
   PerfCounters* create_perf_counters();
 private:
   PerfCountersBuilder(const PerfCountersBuilder &rhs);
   PerfCountersBuilder& operator=(const PerfCountersBuilder &rhs);
-  void add_impl(int idx, const char *name, const char *description, int ty);
+  void add_impl(int idx, const char *name,
+                const char *description, const char *nick, int ty);
 
   PerfCounters *m_perf_counters;
 };
index 1468d806a163bb15e2677d1772d4de5121c216b0..4c75ee8f5c572b3caff04c3ccbfc775a9edfffc4 100644 (file)
@@ -181,10 +181,8 @@ TEST(PerfCounters, MultiplePerfCounters) {
   ASSERT_EQ(sd("{\"test_perfcounter_1\":{\"element1\":13,\"element2\":0.000000000,"
            "\"element3\":{\"avgcount\":0,\"sum\":0.000000000}}}"), msg);
   ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf schema\", \"format\": \"json\" }", &msg));
-
-  ASSERT_EQ(sd("{\"test_perfcounter_1\":{\"element1\":{\"type\":2,\"description\":\"\"},"
-              "\"element2\":{\"type\":1,\"description\":\"\"},\"element3\":{\"type\":5,\"description\":\"\"}}}"), msg);
-
+  ASSERT_EQ(sd("{\"test_perfcounter_1\":{\"element1\":{\"type\":2,\"description\":\"\",\"nick\":\"\"},"
+           "\"element2\":{\"type\":1,\"description\":\"\",\"nick\":\"\"},\"element3\":{\"type\":5,\"description\":\"\",\"nick\":\"\"}}}"), msg);
   coll->clear();
   ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf dump\", \"format\": \"json\" }", &msg));
   ASSERT_EQ("{}", msg);