memInfo.C
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-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 \*---------------------------------------------------------------------------*/
28 
29 #include "memInfo.H"
30 #include "OSspecific.H"
31 #include "IOstreams.H"
32 
33 #include <fstream>
34 #include <string>
35 
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 
39 :
40  peak_(0),
41  size_(0),
42  rss_(0),
43  free_(0)
44 {
45  update();
46 }
47 
48 
49 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
50 
52 {
53  return peak_ > 0;
54 }
55 
56 
58 {
59  peak_ = size_ = rss_ = 0;
60  free_ = 0;
61 }
62 
63 
65 {
66  clear();
67 
68  // Not supported under Windows
69 
70  return *this;
71 }
72 
73 
75 {
76  os.writeEntry("size", size_);
77  os.writeEntry("peak", peak_);
78  os.writeEntry("rss", rss_);
79  os.writeEntry("free", free_);
80 }
81 
82 
83 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
84 
86 {
87  is.readBegin("memInfo");
88  is >> m.peak_ >> m.size_ >> m.rss_ >> m.free_;
89  is.readEnd("memInfo");
90 
91  is.check(FUNCTION_NAME);
92  return is;
93 }
94 
95 
97 {
99  << m.peak_ << token::SPACE
100  << m.size_ << token::SPACE
101  << m.rss_ << token::SPACE
102  << m.free_
103  << token::END_LIST;
104 
106  return os;
107 }
108 
109 
110 // ************************************************************************* //
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
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::Istream::readEnd
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition: Istream.C:129
memInfo.H
Foam::Istream::readBegin
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: Istream.C:111
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::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
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::memInfo::clear
void clear()
Reset to zero.
Definition: memInfo.C:57
clear
patchWriters clear()
Foam::token::SPACE
Space [isspace].
Definition: token.H:125
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:236
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:156
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155
Foam::memInfo::write
void write(Ostream &os) const
Write content as dictionary entries.
Definition: memInfo.C:74