]>
Commit | Line | Data |
---|---|---|
9663db1c | 1 | /* |
5b74111a | 2 | * Copyright (C) 1996-2018 The Squid Software Foundation and contributors |
9663db1c 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 | ||
9 | #ifndef SQUID_SRC_MEM_METER_H | |
10 | #define SQUID_SRC_MEM_METER_H | |
11 | ||
12 | #include "SquidTime.h" | |
13 | ||
14 | namespace Mem | |
15 | { | |
16 | ||
17 | /** | |
18 | * object to track per-action memory usage (e.g. #idle objects) | |
19 | */ | |
20 | class Meter | |
21 | { | |
22 | public: | |
23 | Meter() : level(0), hwater_level(0), hwater_stamp(0) {} | |
24 | ||
25 | /// flush the meter level back to 0, but leave peak records | |
26 | void flush() {level=0;} | |
27 | ||
28 | ssize_t currentLevel() const {return level;} | |
29 | ssize_t peak() const {return hwater_level;} | |
30 | time_t peakTime() const {return hwater_stamp;} | |
31 | ||
32 | Meter &operator ++() {++level; checkHighWater(); return *this;} | |
33 | Meter &operator --() {--level; return *this;} | |
34 | ||
35 | Meter &operator +=(ssize_t n) { level += n; checkHighWater(); return *this;} | |
36 | Meter &operator -=(ssize_t n) { level -= n; return *this;} | |
37 | ||
38 | private: | |
39 | /// check the high-water level of this meter and raise if necessary | |
40 | /// recording the timestamp of last high-water peak change | |
41 | void checkHighWater() { | |
42 | if (hwater_level < level) { | |
43 | hwater_level = level; | |
44 | hwater_stamp = squid_curtime ? squid_curtime : time(NULL); | |
45 | } | |
46 | } | |
47 | ||
48 | ssize_t level; ///< current level (count or volume) | |
49 | ssize_t hwater_level; ///< high water mark | |
50 | time_t hwater_stamp; ///< timestamp of last high water mark change | |
51 | }; | |
52 | ||
53 | } // namespace Mem | |
54 | ||
55 | #endif /* SQUID_SRC_MEM_METER_H */ | |
56 |