memInfo.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::memInfo
26 
27 Description
28  Memory usage information for the process running this object.
29 
30 Note
31  Uses the information from /proc/<pid>/status
32 
33 SourceFiles
34  memInfo.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef memInfo_H
39 #define memInfo_H
40 
41 #include "OSspecific.H"
42 #include "POSIX.H"
43 #include "IFstream.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class memInfo Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class memInfo
55 {
56  // Private data
57 
58  //- Peak memory used by the process (VmPeak in /proc/<pid>/status)
59  int peak_;
60 
61  //- Memory used by the process (VmSize in /proc/<pid>/status)
62  int size_;
63 
64  //- Resident set size of the process (VmRSS in /proc/<pid>/status)
65  int rss_;
66 
67 
68 public:
69 
70  // Constructors
71 
72  //- Construct null
73  memInfo();
74 
75 
76  //- Destructor
77  ~memInfo();
78 
79 
80  // Member Functions
81 
82  //- Parse /proc/<pid>/status
83  const memInfo& update();
84 
85  // Access
86 
87  //- Access the stored peak memory (VmPeak in /proc/<pid>/status)
88  // The value is stored from the previous update()
89  int peak() const
90  {
91  return peak_;
92  }
93 
94  //- Access the stored memory size (VmSize in /proc/<pid>/status)
95  // The value is stored from the previous update()
96  int size() const
97  {
98  return size_;
99  }
100 
101  //- Access the stored rss value (VmRSS in /proc/<pid>/status)
102  // The value is stored from the previous update()
103  int rss() const
104  {
105  return rss_;
106  }
107 
108  //- True if the memory information appears valid
109  bool valid() const;
110 
111 
112  // IOstream Operators
113 
114  //- Read peak/size/rss from stream
115  friend Istream& operator>>(Istream&, memInfo&);
116 
117  //- Write peak/size/rss to stream
118  friend Ostream& operator<<(Ostream&, const memInfo&);
119 };
120 
121 
122 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
123 
124 } // End namespace Foam
125 
126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127 
128 #endif
129 
130 // ************************************************************************* //
memInfo()
Construct null.
Definition: memInfo.C:30
friend Istream & operator>>(Istream &, memInfo &)
Read peak/size/rss from stream.
bool valid() const
True if the memory information appears valid.
Definition: memInfo.C:82
int size() const
Access the stored memory size (VmSize in /proc/<pid>/status)
Definition: memInfo.H:95
Memory usage information for the process running this object.
Definition: memInfo.H:53
int rss() const
Access the stored rss value (VmRSS in /proc/<pid>/status)
Definition: memInfo.H:102
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
friend Ostream & operator<<(Ostream &, const memInfo &)
Write peak/size/rss to stream.
Namespace for OpenFOAM.
~memInfo()
Destructor.
Definition: memInfo.C:42
const memInfo & update()
Parse /proc/<pid>/status.
Definition: memInfo.C:48
int peak() const
Access the stored peak memory (VmPeak in /proc/<pid>/status)
Definition: memInfo.H:88
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53