]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: assoc. DecayRate with DecayCounter
authorPatrick Donnelly <pdonnell@redhat.com>
Mon, 17 Apr 2017 20:03:58 +0000 (16:03 -0400)
committerPatrick Donnelly <pdonnell@redhat.com>
Tue, 18 Apr 2017 02:58:22 +0000 (22:58 -0400)
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/common/DecayCounter.h

index 357b0970ffaaa102f7efaba15ce8cc2c192750b2..6a3ac4bcad431da8a533bde6b278648db57ee474 100644 (file)
@@ -35,6 +35,8 @@ class DecayRate {
 
 public:
   DecayRate() : k(0) {}
+  DecayRate(const DecayRate &dr) : k(dr.k) {}
+
   // cppcheck-suppress noExplicitConstructor
   DecayRate(double hl) { set_halflife(hl); }
   void set_halflife(double hl) {
@@ -48,6 +50,7 @@ public:
   double delta;         // delta since last decay
   double vel;           // recent velocity
   utime_t last_decay;   // time of last decay
+  DecayRate rate;
 
   void encode(bufferlist& bl) const;
   void decode(const utime_t &t, bufferlist::iterator& p);
@@ -59,6 +62,11 @@ public:
   {
   }
 
+  explicit DecayCounter(const utime_t &now, const DecayRate &rate)
+    : val(0), delta(0), vel(0), last_decay(now), rate(rate)
+  {
+  }
+
   // these two functions are for the use of our dencoder testing infrastructure
   DecayCounter() : val(0), delta(0), vel(0), last_decay() {}
 
@@ -75,6 +83,10 @@ public:
     decay(now, rate);
     return val+delta;
   }
+  double get(utime_t now) {
+    decay(now, rate);
+    return val+delta;
+  }
 
   double get_last() {
     return val;
@@ -97,6 +109,11 @@ public:
     delta += v;
     return val+delta;
   }
+  double hit(utime_t now, double v = 1.0) {
+    decay(now, rate);
+    delta += v;
+    return val+delta;
+  }
 
   void adjust(double a) {
     val += a;