]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/DecayCounter.cc
26a552d439c8e71b4356676e591525896dfe2665
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
)
65 if (now
>= last_decay
) {
66 double el
= (double)(now
- last_decay
);
68 // calculate new value
69 double newval
= (val
+delta
) * exp(el
* rate
.k
);
73 // calculate velocity approx
74 vel
+= (newval
- val
) * el
;
75 vel
*= exp(el
* rate
.k
);