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-------------------------------------------------------------------------------
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
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
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_
104
106 return os;
107}
108
109
110// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition: Istream.C:129
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: Istream.C:111
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:239
virtual bool write()
Write the output fields.
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()
Construct and populate with values.
Definition: memInfo.C:38
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
@ BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155
@ END_LIST
End list [isseparator].
Definition: token.H:156
@ SPACE
Space [isspace].
Definition: token.H:125
patchWriters clear()
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Istream & operator>>(Istream &, directionInfo &)