]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/common/perf_counters.h
update sources to v12.1.0
[ceph.git] / ceph / src / common / perf_counters.h
index 56972318571993e99bc860af460949e7d1604634..5eaa59fb699afbea32d557716443b3cc78a69b4b 100644 (file)
 #ifndef CEPH_COMMON_PERF_COUNTERS_H
 #define CEPH_COMMON_PERF_COUNTERS_H
 
-#include "common/config_obs.h"
+#include <string>
+#include <vector>
+#include <memory>
+#include <atomic>
+#include <cstdint>
+
 #include "common/perf_histogram.h"
-#include "common/Mutex.h"
 #include "include/utime.h"
-
-#include "common/config_obs.h"
 #include "common/Mutex.h"
 #include "common/ceph_time.h"
 
-#include <stdint.h>
-#include <string>
-#include <vector>
-#include <memory>
-
 class CephContext;
 class PerfCountersBuilder;
 
 enum perfcounter_type_d : uint8_t
 {
   PERFCOUNTER_NONE = 0,
-  PERFCOUNTER_TIME = 0x1,
-  PERFCOUNTER_U64 = 0x2,
-  PERFCOUNTER_LONGRUNAVG = 0x4,
-  PERFCOUNTER_COUNTER = 0x8,
-  PERFCOUNTER_HISTOGRAM = 0x10,
+  PERFCOUNTER_TIME = 0x1,       // float (measuring seconds)
+  PERFCOUNTER_U64 = 0x2,        // integer (note: either TIME or U64 *must* be set)
+  PERFCOUNTER_LONGRUNAVG = 0x4, // paired counter + sum (time)
+  PERFCOUNTER_COUNTER = 0x8,    // counter (vs guage)
+  PERFCOUNTER_HISTOGRAM = 0x10, // histogram (vector) of values
 };
 
 
@@ -79,21 +76,18 @@ public:
       : name(NULL),
         description(NULL),
         nick(NULL),
-       type(PERFCOUNTER_NONE),
-       u64(0),
-       avgcount(0),
-       avgcount2(0)
+           type(PERFCOUNTER_NONE)
     {}
     perf_counter_data_any_d(const perf_counter_data_any_d& other)
       : name(other.name),
         description(other.description),
         nick(other.nick),
        type(other.type),
-       u64(other.u64.read()) {
+       u64(other.u64.load()) {
       pair<uint64_t,uint64_t> a = other.read_avg();
-      u64.set(a.first);
-      avgcount.set(a.second);
-      avgcount2.set(a.second);
+      u64 = a.first;
+      avgcount = a.second;
+      avgcount2 = a.second;
       if (other.histogram) {
         histogram.reset(new PerfHistogram<>(*other.histogram));
       }
@@ -104,17 +98,17 @@ public:
     const char *nick;
     int prio = 0;
     enum perfcounter_type_d type;
-    atomic64_t u64;
-    atomic64_t avgcount;
-    atomic64_t avgcount2;
+    std::atomic<uint64_t> u64 = { 0 };
+    std::atomic<uint64_t> avgcount = { 0 };
+    std::atomic<uint64_t> avgcount2 = { 0 };
     std::unique_ptr<PerfHistogram<>> histogram;
 
     void reset()
     {
       if (type != PERFCOUNTER_U64) {
-       u64.set(0);
-       avgcount.set(0);
-       avgcount2.set(0);
+           u64 = 0;
+           avgcount = 0;
+           avgcount2 = 0;
       }
       if (histogram) {
         histogram->reset();
@@ -127,9 +121,9 @@ public:
     pair<uint64_t,uint64_t> read_avg() const {
       uint64_t sum, count;
       do {
-       count = avgcount2.read();
-       sum = u64.read();
-      } while (avgcount.read() != count);
+       count = avgcount;
+       sum = u64;
+      } while (avgcount2 != count);
       return make_pair(sum, count);
     }
   };
@@ -313,12 +307,14 @@ public:
                    const char *description=NULL,
                    const char *nick = NULL,
                    int prio=0);
-  void add_histogram(int key, const char* name,
-                    PerfHistogramCommon::axis_config_d x_axis_config,
-                    PerfHistogramCommon::axis_config_d y_axis_config,
-                    const char *description=NULL,
-                    const char* nick = NULL,
-                    int prio=0);
+  void add_u64_counter_histogram(
+    int key, const char* name,
+    PerfHistogramCommon::axis_config_d x_axis_config,
+    PerfHistogramCommon::axis_config_d y_axis_config,
+    const char *description=NULL,
+    const char* nick = NULL,
+    int prio=0);
+
   PerfCounters* create_perf_counters();
 private:
   PerfCountersBuilder(const PerfCountersBuilder &rhs);