]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
histogram: add decay
authorSage Weil <sage@inktank.com>
Fri, 24 Jan 2014 22:56:22 +0000 (14:56 -0800)
committerSage Weil <sage@inktank.com>
Sun, 16 Feb 2014 06:07:04 +0000 (22:07 -0800)
Signed-off-by: Sage Weil <sage@inktank.com>
src/common/histogram.cc
src/common/histogram.h
src/test/common/histogram.cc

index a9431d93e136ed9189f16c0870bf35054bd48477..e1422923956ea13243cc568baaa62b356c1c3fbd 100644 (file)
@@ -48,3 +48,11 @@ void pow2_hist_t::generate_test_instances(std::list<pow2_hist_t*>& ls)
   ls.back()->h.push_back(0);
   ls.back()->h.push_back(2);
 }
+
+void pow2_hist_t::decay(int bits)
+{
+  for (std::vector<int32_t>::iterator p = h.begin(); p != h.end(); ++p) {
+    *p >>= bits;
+  }
+  _contract();
+}
index 1497bc988461da6987436bebc175a2c2b3093697..ceca6d90053ffdcf5b27e870f277fea1e0ae8905 100644 (file)
@@ -116,6 +116,9 @@ public:
     return 1 << h.size();
   }
 
+  /// decay histogram by N bits (default 1, for a halflife)
+  void decay(int bits = 1);
+
   void dump(Formatter *f) const;
   void encode(bufferlist &bl) const;
   void decode(bufferlist::iterator &bl);
index c07d6c26dba295ade8233a9a8ce694cf8144da64..6cbf648534db6d42f1f86ccf2968da019d5959f6 100644 (file)
@@ -93,3 +93,14 @@ TEST(Histogram, Position) {
     ASSERT_EQ(500000, ub);
   }
 }
+
+TEST(Histogram, Decay) {
+  pow2_hist_t h;
+  h.set_bin(0, 123);
+  h.set_bin(3, 12);
+  h.set_bin(5, 1);
+  h.decay(1);
+  ASSERT_EQ(61, h.h[0]);
+  ASSERT_EQ(6, h.h[3]);
+  ASSERT_EQ(4u, h.h.size());
+}