libDwm-0.6.0
DwmRusage.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/libDwm/tags/libDwm-0.6.0/include/DwmRusage.hh 8401 $
3 // @(#) $Id: DwmRusage.hh 8401 2016-04-17 06:44:31Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2006-2007, 2016
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // 1. Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // 3. The names of the authors and copyright holders may not be used to
18 // endorse or promote products derived from this software without
19 // specific prior written permission.
20 //
21 // IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
22 // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
23 // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
24 // EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
25 // DAMAGE.
26 //
27 // THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
28 // DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
29 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
30 // REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
31 // IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
33 // OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
34 // TRADEMARK OR OTHER RIGHTS.
35 //===========================================================================
36 
37 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 #ifndef _DWMRUSAGE_HH_
43 #define _DWMRUSAGE_HH_
44 
45 extern "C" {
46  #include <sys/types.h>
47  #include <sys/time.h>
48  #include <sys/resource.h>
49  #include <inttypes.h>
50 }
51 
52 #include <iostream>
53 
54 #include "DwmGZReadable.hh"
55 #include "DwmGZWritable.hh"
56 #include "DwmReadable.hh"
57 #include "DwmTimeValue.hh"
58 #include "DwmWritable.hh"
59 
60 namespace Dwm {
61 
62  //--------------------------------------------------------------------------
64  //--------------------------------------------------------------------------
65  class Rusage
66  : public Readable, public Writable,
67  public GZReadable, public GZWritable
68  {
69  public:
70  //------------------------------------------------------------------------
72  //------------------------------------------------------------------------
73  Rusage();
74 
75  //------------------------------------------------------------------------
77  //------------------------------------------------------------------------
78  Rusage(const struct rusage & rusage);
79 
80  //------------------------------------------------------------------------
83  //------------------------------------------------------------------------
84  bool Get(int who);
85 
86  //------------------------------------------------------------------------
88  //------------------------------------------------------------------------
89  const TimeValue & UserTime() const;
90 
91  //------------------------------------------------------------------------
94  //------------------------------------------------------------------------
95  const TimeValue & SystemTime() const;
96 
97  //------------------------------------------------------------------------
99  //------------------------------------------------------------------------
100  int64_t MaxResidentSetSize() const;
101 
102  //------------------------------------------------------------------------
109  //------------------------------------------------------------------------
110  int64_t IntegralSharedTextMemorySize() const;
111 
112  //------------------------------------------------------------------------
116  //------------------------------------------------------------------------
117  int64_t IntegralUnsharedDataSize() const;
118 
119  //------------------------------------------------------------------------
123  //------------------------------------------------------------------------
124  int64_t IntegralUnsharedStackSize() const;
125 
126  //------------------------------------------------------------------------
130  //------------------------------------------------------------------------
131  int32_t PageReclaims() const;
132 
133  //------------------------------------------------------------------------
135  //------------------------------------------------------------------------
136  int32_t PageFaults() const;
137 
138  //------------------------------------------------------------------------
140  //------------------------------------------------------------------------
141  int32_t Swaps() const;
142 
143  //------------------------------------------------------------------------
145  //------------------------------------------------------------------------
146  int32_t BlockInputOperations() const;
147 
148  //------------------------------------------------------------------------
150  //------------------------------------------------------------------------
151  int32_t BlockOutputOperations() const;
152 
153  //------------------------------------------------------------------------
155  //------------------------------------------------------------------------
156  int32_t MessagesSent() const;
157 
158  //------------------------------------------------------------------------
160  //------------------------------------------------------------------------
161  int32_t MessagesReceived() const;
162 
163  //------------------------------------------------------------------------
165  //------------------------------------------------------------------------
166  int32_t SignalsReceived() const;
167 
168  //------------------------------------------------------------------------
172  //------------------------------------------------------------------------
173  int32_t VoluntaryContextSwitches() const;
174 
175  //------------------------------------------------------------------------
179  //------------------------------------------------------------------------
180  int32_t InvoluntaryContextSwitches() const;
181 
182  //------------------------------------------------------------------------
184  //------------------------------------------------------------------------
185  friend std::ostream & operator << (std::ostream & os, const Rusage & r);
186 
187  //------------------------------------------------------------------------
189  //------------------------------------------------------------------------
190  std::istream & Read(std::istream & is);
191 
192  //------------------------------------------------------------------------
194  //------------------------------------------------------------------------
195  std::ostream & Write(std::ostream & os) const;
196 
197  //------------------------------------------------------------------------
200  //------------------------------------------------------------------------
201  int Read(gzFile gzf);
202 
203  //------------------------------------------------------------------------
206  //------------------------------------------------------------------------
207  int Write(gzFile gzf) const;
208 
209  //------------------------------------------------------------------------
212  //------------------------------------------------------------------------
213  ssize_t Read(int fd);
214 
215  //------------------------------------------------------------------------
218  //------------------------------------------------------------------------
219  ssize_t Write(int fd) const;
220 
221  //------------------------------------------------------------------------
223  //------------------------------------------------------------------------
224  size_t Read(FILE * f);
225 
226  //------------------------------------------------------------------------
228  //------------------------------------------------------------------------
229  size_t Write(FILE *f) const;
230 
231  //------------------------------------------------------------------------
234  //------------------------------------------------------------------------
235  uint32_t StreamedLength() const;
236 
237  //------------------------------------------------------------------------
239  //------------------------------------------------------------------------
240  bool operator == (const Rusage & rusage) const;
241 
242  private:
243  TimeValue _userTime;
244  TimeValue _systemTime;
245  int64_t _maxResidentSetSize;
246  int64_t _integralSharedTextMemorySize;
247  int64_t _integralUnsharedDataSize;
248  int64_t _integralUnsharedStackSize;
249  int32_t _pageReclaims;
250  int32_t _pageFaults;
251  int32_t _swaps;
252  int32_t _blockInputOperations;
253  int32_t _blockOutputOperations;
254  int32_t _messagesSent;
255  int32_t _messagesReceived;
256  int32_t _signalsReceived;
257  int32_t _voluntaryContextSwitches;
258  int32_t _involuntaryContextSwitches;
259 
260  void Set(const struct rusage & rusage);
261  };
262 
263 } // namespace Dwm
264 
265 #endif // _DWMRUSAGE_HH_
266 
267 //---------------------------- emacs settings -----------------------------
268 // Local Variables:
269 // mode: C++/la
270 // tab-width: 2
271 // indent-tabs-mode: nil
272 // c-basic-offset: 2
273 // End:
274 //-------------------------------------------------------------------------
int64_t IntegralUnsharedDataSize() const
An integral value of the amount of unshared memory residing in the data segment of a process (express...
int32_t VoluntaryContextSwitches() const
The number of times a context switch resulted due to a process voluntarily giving up the processor be...
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmGZWritable.hh:57
This class encapsulates a time value beyond the UNIX epoch, with microsecond granularity.
Definition: DwmTimeValue.hh:72
Dwm::Writable pure virtual class definition.
const TimeValue & SystemTime() const
The total amount of time spent in the system executing on behalf of the process(es).
std::ostream & Write(std::ostream &os) const
Writes to an ostream. Returns the ostream.
Dwm::GZReadable pure virtual class definition.
Dwm::Readable pure virtual class definition.
This class encapsulates struct rusage and getrusage() functionality.
Definition: DwmRusage.hh:65
Rusage()
Constructor.
int64_t IntegralUnsharedStackSize() const
An integral value of the amount of unshared memory residing in the stack segment of a process (expres...
int32_t SignalsReceived() const
The number of signals delivered.
int64_t IntegralSharedTextMemorySize() const
An integral value indicating the amount of memory used by the text segment that was also shared among...
int32_t PageFaults() const
The number of page faults serviced that required I/O activity.
std::istream & Read(std::istream &is)
Reads from an istream. Returns the istream.
Dwm::TimeValue class definition.
int32_t Swaps() const
The number of times a process was ``swapped&#39;&#39; out of main memory.
Definition: DwmBZ2IO.hh:67
int32_t InvoluntaryContextSwitches() const
The number of times a context switch resulted due to a higher priority process becoming runnable or b...
uint32_t StreamedLength() const
Returns the number of bytes that would be written if we called one of the Write() members...
int32_t PageReclaims() const
The number of page faults serviced without any I/O activity; here I/O activity is avoided by reclaimi...
int32_t BlockOutputOperations() const
The number of times the file system had to perform output.
This class is a pure virtual class, defining an interface for classes that can read their contents fr...
Definition: DwmGZReadable.hh:57
int32_t MessagesSent() const
The number of IPC messages sent.
int32_t BlockInputOperations() const
The number of times the file system had to perform input.
bool operator==(const Rusage &rusage) const
operator ==
This class defines an interface for classes that can write their contents to an ostream, file descriptor or FILE pointer.
Definition: DwmWritable.hh:58
Dwm::GZWritable pure virtual class definition.
friend std::ostream & operator<<(std::ostream &os, const Rusage &r)
Prints to an ostream.
This class defines an interface for classes that can read their contents from an istream, file descriptor or FILE pointer.
Definition: DwmReadable.hh:58
int32_t MessagesReceived() const
The number of IPC messages received.
bool Get(int who)
Get the current process&#39; rusage.
int64_t MaxResidentSetSize() const
The maximum resident set size utilized (in bytes).
const TimeValue & UserTime() const
The total amount of time spent executing in user mode.