From: Patrick Donnelly Date: Mon, 17 Apr 2017 20:03:58 +0000 (-0400) Subject: common: assoc. DecayRate with DecayCounter X-Git-Tag: v12.0.3~38^2~25 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=89e990b608f0019dc0e0226add9bb40aae20a1e0;p=ceph.git common: assoc. DecayRate with DecayCounter Signed-off-by: Patrick Donnelly --- diff --git a/src/common/DecayCounter.h b/src/common/DecayCounter.h index 357b0970ffaa..6a3ac4bcad43 100644 --- a/src/common/DecayCounter.h +++ b/src/common/DecayCounter.h @@ -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;