1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #include "DecayCounter.h"
16 #include "Formatter.h"
18 void DecayCounter::encode(bufferlist& bl) const
20 ENCODE_START(4, 4, bl);
27 void DecayCounter::decode(const utime_t &t, bufferlist::iterator &p)
29 DECODE_START_LEGACY_COMPAT_LEN(4, 4, 4, p);
32 ::decode(half_life, p);
44 void DecayCounter::dump(Formatter *f) const
46 f->dump_float("value", val);
47 f->dump_float("delta", delta);
48 f->dump_float("velocity", vel);
51 void DecayCounter::generate_test_instances(list<DecayCounter*>& ls)
54 DecayCounter *counter = new DecayCounter(fake_time);
58 ls.push_back(counter);
59 counter = new DecayCounter(fake_time);
60 ls.push_back(counter);
63 void DecayCounter::decay(utime_t now, const DecayRate &rate)
69 // calculate new value
70 double newval = (val+delta) * exp((double)el * rate.k);
74 // calculate velocity approx
75 vel += (newval - val) * (double)el;
76 vel *= exp((double)el * rate.k);