memInfo.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 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 // Forward declaration of friend functions and operators
51 
52 class memInfo;
53 
54 Istream& operator>>(Istream&, memInfo&);
55 Ostream& operator<<(Ostream&, const memInfo&);
56 
57 
58 /*---------------------------------------------------------------------------*\
59  Class memInfo Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 class memInfo
63 {
64  // Private Data
65 
66  //- Peak memory used by the process (VmPeak in /proc/<pid>/status)
67  int peak_;
68 
69  //- Memory used by the process (VmSize in /proc/<pid>/status)
70  int size_;
71 
72  //- Resident set size of the process (VmRSS in /proc/<pid>/status)
73  int rss_;
74 
75 
76 public:
77 
78  // Constructors
79 
80  //- Construct null
81  memInfo();
82 
83 
84  //- Destructor
85  ~memInfo();
86 
87 
88  // Member Functions
89 
90  //- Parse /proc/<pid>/status
91  const memInfo& update();
92 
93  // Access
94 
95  //- Access the stored peak memory (VmPeak in /proc/<pid>/status)
96  // The value is stored from the previous update()
97  int peak() const
98  {
99  return peak_;
100  }
101 
102  //- Access the stored memory size (VmSize in /proc/<pid>/status)
103  // The value is stored from the previous update()
104  int size() const
105  {
106  return size_;
107  }
108 
109  //- Access the stored rss value (VmRSS in /proc/<pid>/status)
110  // The value is stored from the previous update()
111  int rss() const
112  {
113  return rss_;
114  }
115 
116  //- True if the memory information appears valid
117  bool valid() const;
118 
119 
120  // IOstream Operators
121 
122  //- Read peak/size/rss from stream
123  friend Istream& operator>>(Istream&, memInfo&);
124 
125  //- Write peak/size/rss to stream
126  friend Ostream& operator<<(Ostream&, const memInfo&);
127 };
128 
129 
130 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 
132 } // End namespace Foam
133 
134 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
135 
136 #endif
137 
138 // ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Memory usage information for the process running this object.
Definition: memInfo.H:62
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
memInfo()
Construct null.
Definition: memInfo.C:30
int rss() const
Access the stored rss value (VmRSS in /proc/<pid>/status)
Definition: memInfo.H:110
int peak() const
Access the stored peak memory (VmPeak in /proc/<pid>/status)
Definition: memInfo.H:96
friend Ostream & operator<<(Ostream &, const memInfo &)
Write peak/size/rss to stream.
const memInfo & update()
Parse /proc/<pid>/status.
Definition: memInfo.C:48
~memInfo()
Destructor.
Definition: memInfo.C:42
int size() const
Access the stored memory size (VmSize in /proc/<pid>/status)
Definition: memInfo.H:103
Namespace for OpenFOAM.
Istream & operator>>(Istream &, pistonPointEdgeData &)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)