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-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::memInfo
29
30Description
31 Memory usage information for the current process, and the system memory
32 that is free.
33
34Note
35 Windows variant does nothing.
36
37SourceFiles
38 memInfo.C
39
40\*---------------------------------------------------------------------------*/
41
42#ifndef memInfo_H
43#define memInfo_H
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
49
50// Forward declaration of friend functions and operators
51class memInfo;
52class Istream;
53class Ostream;
54
55Istream& operator>>(Istream& is, memInfo& m);
56Ostream& operator<<(Ostream& os, const memInfo& m);
57
58
59/*---------------------------------------------------------------------------*\
60 Class memInfo Declaration
61\*---------------------------------------------------------------------------*/
63class 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
79public:
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// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Memory usage information for the current process, and the system memory that is free.
Definition: memInfo.H:63
bool valid() const
True if the memory information appears valid.
Definition: memInfo.C:51
~memInfo()=default
Destructor.
memInfo()
Construct and populate with values.
Definition: memInfo.C:38
int rss() const
Resident set size (VmRSS in /proc/PID/status) at last update()
Definition: memInfo.H:115
int peak() const
Peak memory (VmPeak in /proc/PID/status) at last update()
Definition: memInfo.H:103
friend Istream & operator>>(Istream &is, memInfo &m)
Read peak/size/rss from stream.
friend Ostream & operator<<(Ostream &os, const memInfo &m)
Write peak/size/rss to stream.
void clear()
Reset to zero.
Definition: memInfo.C:57
const memInfo & update()
Update according to /proc/PID/status and /proc/memory contents.
Definition: memInfo.C:64
int free() const
System memory free (MemFree in /proc/meminfo)
Definition: memInfo.H:121
int size() const
Memory size (VmSize in /proc/PID/status) at last update()
Definition: memInfo.H:109
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Istream & operator>>(Istream &, directionInfo &)
runTime write()