]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 The Squid Software Foundation and contributors |
bbc27441 AJ |
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 | ||
ff9d9458 FC |
9 | #ifndef SQUID_SRC_FADINGCOUNTER_H |
10 | #define SQUID_SRC_FADINGCOUNTER_H | |
8277060a | 11 | |
c8ea3cc0 | 12 | #include <vector> |
8277060a | 13 | |
2f8abb64 | 14 | /// Counts events, forgetting old ones. Useful for "3 errors/minute" limits. |
a459e80a A |
15 | class FadingCounter |
16 | { | |
17 | public: | |
18 | FadingCounter(); | |
8277060a | 19 | |
a459e80a A |
20 | /// 0=remember nothing; -1=forget nothing; new value triggers clear() |
21 | void configure(double horizonSeconds); | |
8277060a | 22 | |
a459e80a | 23 | void clear(); ///< forgets all events |
8277060a | 24 | |
a459e80a A |
25 | int count(int howMany); ///< count fresh, return #events remembered |
26 | int remembered() const { return total; } ///< possibly stale #events | |
8277060a | 27 | |
a459e80a A |
28 | /// read-only memory horizon in seconds; older events are forgotten |
29 | double horizon; | |
8277060a | 30 | |
a459e80a | 31 | private: |
2f8abb64 | 32 | const int precision; ///< #counting slots, controls measur. accuracy |
a459e80a | 33 | double delta; ///< sub-interval duration = horizon/precision |
8277060a | 34 | |
a459e80a | 35 | double lastTime; ///< time of the last update |
c8ea3cc0 | 36 | std::vector<int> counters; ///< events per delta (possibly stale) |
a459e80a | 37 | int total; ///< number of remembered events (possibly stale) |
8277060a CT |
38 | }; |
39 | ||
ff9d9458 | 40 | #endif /* SQUID_SRC_FADINGCOUNTER_H */ |
f53969cc | 41 |