Loading...
Searching...
No Matches
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 OpenFOAM Foundation
9 Copyright (C) 2016-2025 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 Uses the information from /proc/PID/status and from /proc/meminfo
36
37SourceFiles
38 memInfo.C
39
40\*---------------------------------------------------------------------------*/
41
42#ifndef Foam_memInfo_H
43#define Foam_memInfo_H
44
45#include <cstdint>
46
47// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48
49namespace Foam
50{
51
52// Forward Declarations
53class memInfo;
54class word;
55class Ostream;
56
59/*---------------------------------------------------------------------------*\
60 Class memInfo Declaration
61\*---------------------------------------------------------------------------*/
62
63class memInfo
64{
65 // Private Data
66
67 //- Peak memory used by the process (VmPeak in /proc/PID/status)
68 int64_t peak_;
69
70 //- Memory used by the process (VmSize in /proc/PID/status)
71 int64_t size_;
72
73 //- Resident set size of the process (VmRSS in /proc/PID/status)
74 int64_t rss_;
75
76 //- System memory free (MemFree in /proc/meminfo)
77 int64_t free_;
78
79
80 // Private Member Functions
81
82 //- Populate entries
83 void populate();
84
85
86public:
87
88 // Constructors
89
90 //- Construct and populate with values
91 memInfo();
92
93
94 // Member Functions
95
96 //- True if memory information appears to be supported
97 static bool supported();
98
99
100 // Access
101
102 //- True if the memory information appears valid
103 bool good() const noexcept;
104
105 //- Peak memory at last update - (VmPeak in /proc/PID/status)
106 int64_t peak() const noexcept { return peak_; }
107
108 //- Memory size at last update - (VmSize in /proc/PID/status)
109 int64_t size() const noexcept { return size_; }
110
111 //- Resident set size at last update - (VmRSS in /proc/PID/status)
112 int64_t rss() const noexcept { return rss_; }
113
114 //- System memory free (MemFree in /proc/meminfo)
115 int64_t free() const noexcept { return free_; }
116
117
118 // Edit
120 //- Reset to zero
121 void clear() noexcept;
122
123 //- Update according to /proc/PID/status and /proc/memory contents
124 const memInfo& update();
125
126
127 // IOstream Operators
128
129 //- Write peak/size/rss to stream
130 friend Ostream& operator<<(Ostream& os, const memInfo& m);
131
132
133 // Write
135 //- Write mem-info as dictionary entries
136 void writeEntries(Ostream& os) const;
137
138 //- Write mem-info as dictionary
139 void writeEntry(const word& keyword, Ostream& os) const;
140};
141
142
143// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144
145} // End namespace Foam
146
147// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148
149#endif
150
151// ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Memory usage information for the current process, and the system memory that is free.
Definition memInfo.H:59
void clear() noexcept
Reset to zero.
Definition memInfo.C:77
int64_t peak() const noexcept
Peak memory at last update - (VmPeak in /proc/PID/status).
Definition memInfo.H:119
bool good() const noexcept
True if the memory information appears valid.
Definition memInfo.C:71
memInfo()
Construct and populate with values.
Definition memInfo.C:58
int64_t size() const noexcept
Memory size at last update - (VmSize in /proc/PID/status).
Definition memInfo.H:124
void writeEntries(Ostream &os) const
Write mem-info as dictionary entries.
Definition memInfo.C:230
void writeEntry(const word &keyword, Ostream &os) const
Write mem-info as dictionary.
Definition memInfo.C:240
int64_t rss() const noexcept
Resident set size at last update - (VmRSS in /proc/PID/status).
Definition memInfo.H:129
int64_t free() const noexcept
System memory free (MemFree in /proc/meminfo).
Definition memInfo.H:134
static bool supported()
True if memory information appears to be supported.
Definition memInfo.C:43
const memInfo & update()
Update according to /proc/PID/status and /proc/memory contents.
Definition memInfo.C:222
A class for handling words, derived from Foam::string.
Definition word.H:66
mesh update()
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
const direction noexcept
Definition scalarImpl.H:265