]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/DecayCounter.h
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 #ifndef CEPH_DECAYCOUNTER_H
16 #define CEPH_DECAYCOUNTER_H
18 #include "include/utime.h"
22 * TODO: normalize value based on some fucntion of half_life,
23 * so that it can be interpreted as an approximation of a
24 * moving average of N seconds. currently, changing half-life
25 * skews the scale of the value, even at steady state.
30 double k
; // k = ln(.5)/half_life
32 friend class DecayCounter
;
36 DecayRate(const DecayRate
&dr
) : k(dr
.k
) {}
38 // cppcheck-suppress noExplicitConstructor
39 DecayRate(double hl
) { set_halflife(hl
); }
40 void set_halflife(double hl
) {
48 double delta
; // delta since last decay
49 double vel
; // recent velocity
50 utime_t last_decay
; // time of last decay
53 void encode(bufferlist
& bl
) const;
54 void decode(const utime_t
&t
, bufferlist::iterator
& p
);
55 void dump(Formatter
*f
) const;
56 static void generate_test_instances(list
<DecayCounter
*>& ls
);
58 explicit DecayCounter(const utime_t
&now
)
59 : val(0), delta(0), vel(0), last_decay(now
)
63 explicit DecayCounter(const utime_t
&now
, const DecayRate
&rate
)
64 : val(0), delta(0), vel(0), last_decay(now
), rate(rate
)
68 // these two functions are for the use of our dencoder testing infrastructure
69 DecayCounter() : val(0), delta(0), vel(0), last_decay() {}
71 void decode(bufferlist::iterator
& p
) {
80 double get(utime_t now
, const DecayRate
& rate
) {
84 double get(utime_t now
) {
89 double get_last() const {
93 double get_last_vel() const {
97 utime_t
get_last_decay() const {
105 double hit(utime_t now
, const DecayRate
& rate
, double v
= 1.0) {
110 double hit(utime_t now
, double v
= 1.0) {
116 void adjust(double a
) {
119 void adjust(utime_t now
, const DecayRate
& rate
, double a
) {
123 void scale(double f
) {
133 void reset(utime_t now
) {
138 void decay(utime_t now
, const DecayRate
&rate
);
141 inline void encode(const DecayCounter
&c
, bufferlist
&bl
) { c
.encode(bl
); }
142 inline void decode(DecayCounter
&c
, const utime_t
&t
, bufferlist::iterator
&p
) {
146 inline void decode(DecayCounter
&c
, bufferlist::iterator
&p
) {