libDwm-0.9.45
DwmRusage.hh
Go to the documentation of this file.
1//===========================================================================
2// @(#) $DwmPath$
3//===========================================================================
4// Copyright (c) Daniel W. McRobb 2006-2007, 2016, 2024
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions
9// are met:
10//
11// 1. Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// 2. Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16// 3. The names of the authors and copyright holders may not be used to
17// endorse or promote products derived from this software without
18// specific prior written permission.
19//
20// IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
21// DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
22// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
23// EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
24// DAMAGE.
25//
26// THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
27// DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
28// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
29// REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
30// IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31// WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
32// OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
33// TRADEMARK OR OTHER RIGHTS.
34//===========================================================================
35
36//---------------------------------------------------------------------------
39//---------------------------------------------------------------------------
40
41#ifndef _DWMRUSAGE_HH_
42#define _DWMRUSAGE_HH_
43
44extern "C" {
45 #include <sys/resource.h>
46}
47
48#include <cstdint>
49
50#include "DwmTimeValue.hh"
51
52namespace Dwm {
53
54 //--------------------------------------------------------------------------
56 //--------------------------------------------------------------------------
57 class Rusage
58 {
59 public:
60 //------------------------------------------------------------------------
62 //------------------------------------------------------------------------
64
65 //------------------------------------------------------------------------
67 //------------------------------------------------------------------------
68 Rusage(const struct rusage & rusage);
69
70 //------------------------------------------------------------------------
73 //------------------------------------------------------------------------
74 bool Get(int who);
75
76 //------------------------------------------------------------------------
78 //------------------------------------------------------------------------
79 const TimeValue & UserTime() const;
80
81 //------------------------------------------------------------------------
84 //------------------------------------------------------------------------
85 const TimeValue & SystemTime() const;
86
87 //------------------------------------------------------------------------
89 //------------------------------------------------------------------------
90 int64_t MaxResidentSetSize() const;
91
92 //------------------------------------------------------------------------
99 //------------------------------------------------------------------------
101
102 //------------------------------------------------------------------------
106 //------------------------------------------------------------------------
108
109 //------------------------------------------------------------------------
113 //------------------------------------------------------------------------
115
116 //------------------------------------------------------------------------
120 //------------------------------------------------------------------------
121 int32_t PageReclaims() const;
122
123 //------------------------------------------------------------------------
125 //------------------------------------------------------------------------
126 int32_t PageFaults() const;
127
128 //------------------------------------------------------------------------
130 //------------------------------------------------------------------------
131 int32_t Swaps() const;
132
133 //------------------------------------------------------------------------
135 //------------------------------------------------------------------------
136 int32_t BlockInputOperations() const;
137
138 //------------------------------------------------------------------------
140 //------------------------------------------------------------------------
141 int32_t BlockOutputOperations() const;
142
143 //------------------------------------------------------------------------
145 //------------------------------------------------------------------------
146 int32_t MessagesSent() const;
147
148 //------------------------------------------------------------------------
150 //------------------------------------------------------------------------
151 int32_t MessagesReceived() const;
152
153 //------------------------------------------------------------------------
155 //------------------------------------------------------------------------
156 int32_t SignalsReceived() const;
157
158 //------------------------------------------------------------------------
162 //------------------------------------------------------------------------
164
165 //------------------------------------------------------------------------
169 //------------------------------------------------------------------------
171
172 //------------------------------------------------------------------------
174 //------------------------------------------------------------------------
175 friend std::ostream & operator << (std::ostream & os, const Rusage & r);
176
177 //------------------------------------------------------------------------
179 //------------------------------------------------------------------------
180 std::istream & Read(std::istream & is);
181
182 //------------------------------------------------------------------------
184 //------------------------------------------------------------------------
185 std::ostream & Write(std::ostream & os) const;
186
187 //------------------------------------------------------------------------
190 //------------------------------------------------------------------------
191 int Read(gzFile gzf);
192
193 //------------------------------------------------------------------------
196 //------------------------------------------------------------------------
197 int Write(gzFile gzf) const;
198
199 //------------------------------------------------------------------------
202 //------------------------------------------------------------------------
203 ssize_t Read(int fd);
204
205 //------------------------------------------------------------------------
208 //------------------------------------------------------------------------
209 ssize_t Write(int fd) const;
210
211 //------------------------------------------------------------------------
214 //------------------------------------------------------------------------
215 uint64_t StreamedLength() const;
216
217 //------------------------------------------------------------------------
219 //------------------------------------------------------------------------
220 bool operator == (const Rusage & rusage) const;
221
222 private:
223 TimeValue _userTime;
224 TimeValue _systemTime;
225 int64_t _maxResidentSetSize;
226 int64_t _integralSharedTextMemorySize;
227 int64_t _integralUnsharedDataSize;
228 int64_t _integralUnsharedStackSize;
229 int32_t _pageReclaims;
230 int32_t _pageFaults;
231 int32_t _swaps;
232 int32_t _blockInputOperations;
233 int32_t _blockOutputOperations;
234 int32_t _messagesSent;
235 int32_t _messagesReceived;
236 int32_t _signalsReceived;
237 int32_t _voluntaryContextSwitches;
238 int32_t _involuntaryContextSwitches;
239
240 void Set(const struct rusage & rusage);
241 };
242
243} // namespace Dwm
244
245#endif // _DWMRUSAGE_HH_
246
247//---------------------------- emacs settings -----------------------------
248// Local Variables:
249// mode: C++
250// tab-width: 2
251// indent-tabs-mode: nil
252// c-basic-offset: 2
253// End:
254//-------------------------------------------------------------------------
Dwm::TimeValue class definition.
This class encapsulates struct rusage and getrusage() functionality.
Definition DwmRusage.hh:58
int32_t VoluntaryContextSwitches() const
The number of times a context switch resulted due to a process voluntarily giving up the processor be...
Rusage(const struct rusage &rusage)
Construct from a struct rusagee.
bool Get(int who)
Get the current process' rusage.
int32_t MessagesReceived() const
The number of IPC messages received.
int64_t IntegralUnsharedStackSize() const
An integral value of the amount of unshared memory residing in the stack segment of a process (expres...
int32_t InvoluntaryContextSwitches() const
The number of times a context switch resulted due to a higher priority process becoming runnable or b...
std::ostream & Write(std::ostream &os) const
Writes to an ostream. Returns the ostream.
int32_t BlockInputOperations() const
The number of times the file system had to perform input.
std::istream & Read(std::istream &is)
Reads from an istream. Returns the istream.
const TimeValue & SystemTime() const
The total amount of time spent in the system executing on behalf of the process(es).
Rusage()
Constructor.
int32_t PageReclaims() const
The number of page faults serviced without any I/O activity; here I/O activity is avoided by reclaimi...
int Write(gzFile gzf) const
Writes to a gzFile.
int64_t IntegralUnsharedDataSize() const
An integral value of the amount of unshared memory residing in the data segment of a process (express...
uint64_t StreamedLength() const
Returns the number of bytes that would be written if we called one of the Write() members.
ssize_t Read(int fd)
Reads from a file descriptor.
bool operator==(const Rusage &rusage) const
operator ==
int32_t Swaps() const
The number of times a process was `‘swapped’' out of main memory.
int32_t PageFaults() const
The number of page faults serviced that required I/O activity.
int64_t MaxResidentSetSize() const
The maximum resident set size utilized (in bytes).
friend std::ostream & operator<<(std::ostream &os, const Rusage &r)
Prints to an ostream.
int32_t MessagesSent() const
The number of IPC messages sent.
int32_t SignalsReceived() const
The number of signals delivered.
int32_t BlockOutputOperations() const
The number of times the file system had to perform output.
ssize_t Write(int fd) const
Writes to a file descriptor.
const TimeValue & UserTime() const
The total amount of time spent executing in user mode.
int Read(gzFile gzf)
Reads from a gzFile.
int64_t IntegralSharedTextMemorySize() const
An integral value indicating the amount of memory used by the text segment that was also shared among...
This class encapsulates a time value beyond the UNIX epoch, with microsecond granularity.
Definition DwmTimeValue.hh:68