Squid Web Cache master
Loading...
Searching...
No Matches
FadingCounter.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#ifndef SQUID_SRC_FADINGCOUNTER_H
10#define SQUID_SRC_FADINGCOUNTER_H
11
12#include <vector>
13
16{
17public:
19
21 void configure(double horizonSeconds);
22
23 void clear();
24
25 int count(int howMany);
26 int remembered() const { return total; }
27
29 double horizon;
30
31private:
32 const int precision;
33 double delta;
34
35 double lastTime;
36 std::vector<int> counters;
37 int total;
38};
39
40#endif /* SQUID_SRC_FADINGCOUNTER_H */
41
Counts events, forgetting old ones. Useful for "3 errors/minute" limits.
std::vector< int > counters
events per delta (possibly stale)
int total
number of remembered events (possibly stale)
int count(int howMany)
count fresh, return #events remembered
double horizon
read-only memory horizon in seconds; older events are forgotten
void clear()
forgets all events
double delta
sub-interval duration = horizon/precision
void configure(double horizonSeconds)
0=remember nothing; -1=forget nothing; new value triggers clear()
double lastTime
time of the last update
int remembered() const
possibly stale #events
const int precision
#counting slots, controls measur. accuracy