Meter.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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_MEM_METER_H
10#define SQUID_SRC_MEM_METER_H
11
12#include "time/gadgets.h"
13
14namespace Mem
15{
16
20class Meter
21{
22public:
24 void flush() {level=0;}
25
26 ssize_t currentLevel() const {return level;}
27 ssize_t peak() const {return hwater_level;}
28 time_t peakTime() const {return hwater_stamp;}
29
30 Meter &operator ++() {++level; checkHighWater(); return *this;}
31 Meter &operator --() {--level; return *this;}
32
33 Meter &operator +=(ssize_t n) { level += n; checkHighWater(); return *this;}
34 Meter &operator -=(ssize_t n) { level -= n; return *this;}
35
36private:
40 if (hwater_level < level) {
42 hwater_stamp = squid_curtime ? squid_curtime : time(nullptr);
43 }
44 }
45
46 ssize_t level = 0;
47 ssize_t hwater_level = 0;
48 time_t hwater_stamp = 0;
49};
50
55{
56public:
58 class mgb_t
59 {
60 public:
61 mgb_t &operator +=(const mgb_t &o) {
62 count += o.count;
63 bytes += o.bytes;
64 return *this;
65 }
66
68 void update(size_t items, size_t itemSize) {
69 count += items;
70 bytes += (items * itemSize);
71 }
72
73 public:
74 double count = 0.0;
75 double bytes = 0.0;
76 };
77
79 void flush() {
80 alloc.flush();
81 inuse.flush();
82 idle.flush();
85 gb_saved = mgb_t();
86 gb_freed = mgb_t();
87 }
88
92
96
99
102};
103
104} // namespace Mem
105
106#endif /* SQUID_SRC_MEM_METER_H */
107
time_t squid_curtime
Definition: stub_libtime.cc:20
ssize_t hwater_level
high water mark
Definition: Meter.h:47
time_t hwater_stamp
timestamp of last high water mark change
Definition: Meter.h:48
ssize_t currentLevel() const
Definition: Meter.h:26
void checkHighWater()
Definition: Meter.h:39
time_t peakTime() const
Definition: Meter.h:28
ssize_t level
current level (count or volume)
Definition: Meter.h:46
Meter & operator--()
Definition: Meter.h:31
Meter & operator-=(ssize_t n)
Definition: Meter.h:34
Meter & operator+=(ssize_t n)
Definition: Meter.h:33
ssize_t peak() const
Definition: Meter.h:27
Meter & operator++()
Definition: Meter.h:30
void flush()
flush the meter level back to 0, but leave peak records
Definition: Meter.h:24
Object to track per-pool cumulative counters.
Definition: Meter.h:59
void update(size_t items, size_t itemSize)
account for memory actions taking place
Definition: Meter.h:68
mgb_t & operator+=(const mgb_t &o)
Definition: Meter.h:61
Meter idle
Definition: Meter.h:91
void flush()
flush counters back to 0, but leave historic peak records
Definition: Meter.h:79
mgb_t gb_allocated
Definition: Meter.h:94
Meter alloc
Definition: Meter.h:89
Meter inuse
Definition: Meter.h:90
mgb_t gb_oallocated
Definition: Meter.h:95
mgb_t gb_saved
Definition: Meter.h:98
mgb_t gb_freed
Definition: Meter.h:101
Memory Management.
Definition: Allocator.h:17

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors