]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mem/Meter.h
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_SRC_MEM_METER_H
10 #define SQUID_SRC_MEM_METER_H
12 #include "time/gadgets.h"
18 * object to track per-action memory usage (e.g. #idle objects)
23 /// flush the meter level back to 0, but leave peak records
24 void flush() {level
=0;}
26 ssize_t
currentLevel() const {return level
;}
27 ssize_t
peak() const {return hwater_level
;}
28 time_t peakTime() const {return hwater_stamp
;}
30 Meter
&operator ++() {++level
; checkHighWater(); return *this;}
31 Meter
&operator --() {--level
; return *this;}
33 Meter
&operator +=(ssize_t n
) { level
+= n
; checkHighWater(); return *this;}
34 Meter
&operator -=(ssize_t n
) { level
-= n
; return *this;}
37 /// check the high-water level of this meter and raise if necessary
38 /// recording the timestamp of last high-water peak change
39 void checkHighWater() {
40 if (hwater_level
< level
) {
42 hwater_stamp
= squid_curtime
? squid_curtime
: time(nullptr);
46 ssize_t level
= 0; ///< current level (count or volume)
47 ssize_t hwater_level
= 0; ///< high water mark
48 time_t hwater_stamp
= 0; ///< timestamp of last high water mark change
52 * Object to track per-pool memory usage (alloc = inuse+idle)
57 /// Object to track per-pool cumulative counters
63 /// flush counters back to 0, but leave historic peak records
68 gb_allocated
= mgb_t();
69 gb_oallocated
= mgb_t();
78 /** history Allocations */
82 /** account Saved Allocations */
85 /** account Free calls */
91 #endif /* SQUID_SRC_MEM_METER_H */