]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
perf_counters: add dec()
authorSamuel Just <sam.just@inktank.com>
Mon, 22 Oct 2012 17:46:57 +0000 (10:46 -0700)
committerSamuel Just <sam.just@inktank.com>
Tue, 30 Oct 2012 20:31:09 +0000 (13:31 -0700)
Signed-off-by: Samuel Just <sam.just@inktank.com>
src/common/perf_counters.cc
src/common/perf_counters.h

index e60c0750088f203f62970e328f1f2c2af55e78a9..4166343adb48403a448fe33d3762eb90c5655d40 100644 (file)
@@ -108,6 +108,19 @@ void PerfCounters::inc(int idx, uint64_t amt)
     data.avgcount++;
 }
 
+void PerfCounters::dec(int idx, uint64_t amt)
+{
+  Mutex::Locker lck(m_lock);
+  assert(idx > m_lower_bound);
+  assert(idx < m_upper_bound);
+  perf_counter_data_any_d& data(m_data[idx - m_lower_bound - 1]);
+  assert(!(data.type & PERFCOUNTER_LONGRUNAVG));
+  if (!(data.type & PERFCOUNTER_U64))
+    return;
+  assert(data.u.u64 >= amt);
+  data.u.u64 -= amt;
+}
+
 void PerfCounters::set(int idx, uint64_t amt)
 {
   Mutex::Locker lck(m_lock);
index 2d795bf33ee48aeccaa9762525242e51e22f730f..d36736218526dfa5eb2111dfc2796c71ae19d306 100644 (file)
@@ -67,6 +67,7 @@ public:
   ~PerfCounters();
 
   void inc(int idx, uint64_t v = 1);
+  void dec(int idx, uint64_t v = 1);
   void set(int idx, uint64_t v);
   uint64_t get(int idx) const;