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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2017 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::memInfo
29 
30 Description
31  Memory usage information for the current process, and the system memory
32  that is free.
33 
34 Note
35  Uses the information from /proc/PID/status and from /proc/meminfo
36 
37 SourceFiles
38  memInfo.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef memInfo_H
43 #define memInfo_H
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // Forward declaration of friend functions and operators
51 class memInfo;
52 class Istream;
53 class Ostream;
54 
55 Istream& operator>>(Istream& is, memInfo& m);
56 Ostream& operator<<(Ostream& os, const memInfo& m);
57 
58 
59 /*---------------------------------------------------------------------------*\
60  Class memInfo Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 class memInfo
64 {
65  // Private data
66 
67  //- Peak memory used by the process (VmPeak in /proc/PID/status)
68  int peak_;
69 
70  //- Memory used by the process (VmSize in /proc/PID/status)
71  int size_;
72 
73  //- Resident set size of the process (VmRSS in /proc/PID/status)
74  int rss_;
75 
76  //- System memory free (MemFree in /proc/meminfo)
77  int free_;
78 
79 public:
80 
81  // Constructors
82 
83  //- Construct and populate with values
84  memInfo();
85 
86 
87  //- Destructor
88  ~memInfo() = default;
89 
90 
91  // Member Functions
92 
93  //- True if the memory information appears valid
94  bool valid() const;
95 
96  //- Reset to zero
97  void clear();
98 
99  //- Update according to /proc/PID/status and /proc/memory contents
100  const memInfo& update();
101 
102 
103  //- Peak memory (VmPeak in /proc/PID/status) at last update()
104  inline int peak() const
105  {
106  return peak_;
107  }
108 
109  //- Memory size (VmSize in /proc/PID/status) at last update()
110  inline int size() const
111  {
112  return size_;
113  }
114 
115  //- Resident set size (VmRSS in /proc/PID/status) at last update()
116  inline int rss() const
117  {
118  return rss_;
119  }
120 
121  //- System memory free (MemFree in /proc/meminfo)
122  inline int free() const
123  {
124  return free_;
125  }
126 
127 
128  // Write
129 
130  //- Write content as dictionary entries
131  void write(Ostream& os) const;
132 
133 
134  // IOstream Operators
135 
136  //- Read peak/size/rss from stream
137  friend Istream& operator>>(Istream& is, memInfo& m);
138 
139  //- Write peak/size/rss to stream
140  friend Ostream& operator<<(Ostream& os, const memInfo& m);
141 };
142 
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 } // End namespace Foam
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 #endif
151 
152 // ************************************************************************* //
Foam::memInfo::rss
int rss() const
Resident set size (VmRSS in /proc/PID/status) at last update()
Definition: memInfo.H:115
Foam::memInfo::valid
bool valid() const
True if the memory information appears valid.
Definition: memInfo.C:51
Foam::memInfo::memInfo
memInfo()
Construct and populate with values.
Definition: memInfo.C:38
Foam::memInfo::peak
int peak() const
Peak memory (VmPeak in /proc/PID/status) at last update()
Definition: memInfo.H:103
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::memInfo::operator<<
friend Ostream & operator<<(Ostream &os, const memInfo &m)
Write peak/size/rss to stream.
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::memInfo::update
const memInfo & update()
Update according to /proc/PID/status and /proc/memory contents.
Definition: memInfo.C:64
Foam::memInfo::operator>>
friend Istream & operator>>(Istream &is, memInfo &m)
Read peak/size/rss from stream.
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::memInfo::free
int free() const
System memory free (MemFree in /proc/meminfo)
Definition: memInfo.H:121
Foam::memInfo::~memInfo
~memInfo()=default
Destructor.
os
OBJstream os(runTime.globalPath()/outputName)
Foam::memInfo
Memory usage information for the current process, and the system memory that is free.
Definition: memInfo.H:62
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::memInfo::clear
void clear()
Reset to zero.
Definition: memInfo.C:57
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::memInfo::size
int size() const
Memory size (VmSize in /proc/PID/status) at last update()
Definition: memInfo.H:109
Foam::memInfo::write
void write(Ostream &os) const
Write content as dictionary entries.
Definition: memInfo.C:74