]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/DecayCounter.cc
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 #include "include/encoding.h"
20 void DecayCounter::encode(ceph::buffer::list
& bl
) const
23 ENCODE_START(5, 4, bl
);
28 void DecayCounter::decode(ceph::buffer::list::const_iterator
&p
)
30 DECODE_START_LEGACY_COMPAT_LEN(5, 4, 4, p
);
44 decode(_
, p
); /* velocity */
46 last_decay
= clock::now();
50 void DecayCounter::dump(ceph::Formatter
*f
) const
53 f
->dump_float("value", val
);
54 f
->dump_float("halflife", rate
.get_halflife());
57 void DecayCounter::generate_test_instances(std::list
<DecayCounter
*>& ls
)
59 DecayCounter
*counter
= new DecayCounter();
61 ls
.push_back(counter
);
62 counter
= new DecayCounter();
63 ls
.push_back(counter
);
66 void DecayCounter::decay(double delta
) const
68 auto now
= clock::now();
69 double el
= std::chrono::duration
<double>(now
- last_decay
).count();
71 // calculate new value
72 double newval
= val
* exp(el
* rate
.k
) + delta
;