mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: reset parameters in memInfo::update()
- avoids old values if the read from /proc/.../status somehow failed
This commit is contained in:
@ -1,3 +1,3 @@
|
||||
memInfo.C
|
||||
Test-memInfo.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/memInfo
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-memInfo
|
||||
|
||||
61
applications/test/memInfo/Test-memInfo.C
Normal file
61
applications/test/memInfo/Test-memInfo.C
Normal file
@ -0,0 +1,61 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Application
|
||||
|
||||
Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "memInfo.H"
|
||||
#include "IOstreams.H"
|
||||
#include "List.H"
|
||||
#include "vector.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const int n = 10000000;
|
||||
const char* const memTags = "peak/size/rss mem: ";
|
||||
|
||||
memInfo mem;
|
||||
|
||||
Info<< memTags << mem << endl;
|
||||
List<vector> lst(n, vector::one);
|
||||
|
||||
Info<< "allocate " << n << " vectors" << nl
|
||||
<< memTags << mem.update() << endl;
|
||||
|
||||
lst.clear();
|
||||
Info<< "clear" << nl
|
||||
<< memTags << mem.update() << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,19 +0,0 @@
|
||||
#include "memInfo.H"
|
||||
#include "IOstreams.H"
|
||||
#include "List.H"
|
||||
#include "vector.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
int main()
|
||||
{
|
||||
memInfo m;
|
||||
|
||||
Info<< m << endl;
|
||||
|
||||
List<vector> l(10000000, vector::one);
|
||||
|
||||
Info<< m.update() << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -47,6 +47,8 @@ Foam::memInfo::~memInfo()
|
||||
|
||||
const Foam::memInfo& Foam::memInfo::update()
|
||||
{
|
||||
// reset to invalid values first
|
||||
peak_ = size_ = rss_ = -1;
|
||||
IFstream is("/proc/" + name(pid()) + "/status");
|
||||
|
||||
while (is.good())
|
||||
|
||||
@ -27,6 +27,9 @@ Class
|
||||
Description
|
||||
Memory usage information for the process running this object.
|
||||
|
||||
Note
|
||||
Uses the information from /proc/\<pid\>/status
|
||||
|
||||
SourceFiles
|
||||
memInfo.C
|
||||
|
||||
@ -52,13 +55,13 @@ class memInfo
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Peak memory used by the process (VmPeak in /proc/<pid>/status)
|
||||
//- Peak memory used by the process (VmPeak in /proc/\<pid\>/status)
|
||||
int peak_;
|
||||
|
||||
//- Memory used by the process (VmSize in /proc/<pid>/status)
|
||||
//- Memory used by the process (VmSize in /proc/\<pid\>/status)
|
||||
int size_;
|
||||
|
||||
//- Resident set size of the process (VmRSS in /proc/<pid>/status)
|
||||
//- Resident set size of the process (VmRSS in /proc/\<pid\>/status)
|
||||
int rss_;
|
||||
|
||||
|
||||
@ -76,24 +79,27 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Parse /proc/<pid>/status
|
||||
//- Parse /proc/\<pid\>/status
|
||||
const memInfo& update();
|
||||
|
||||
// Access
|
||||
|
||||
//- Access the stored peak memory
|
||||
//- Access the stored peak memory (VmPeak in /proc/\<pid\>/status)
|
||||
// The value is stored from the previous update()
|
||||
int peak() const
|
||||
{
|
||||
return peak_;
|
||||
}
|
||||
|
||||
//- Access the stored memory size
|
||||
//- Access the stored memory size (VmSize in /proc/\<pid\>/status)
|
||||
// The value is stored from the previous update()
|
||||
int size() const
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
|
||||
//- Access the stored rss value
|
||||
//- Access the stored rss value (VmRSS in /proc/\<pid\>/status)
|
||||
// The value is stored from the previous update()
|
||||
int rss() const
|
||||
{
|
||||
return rss_;
|
||||
@ -102,7 +108,10 @@ public:
|
||||
|
||||
// IOstream Operators
|
||||
|
||||
//- Read peak/size/rss from stream
|
||||
friend Istream& operator>>(Istream&, memInfo&);
|
||||
|
||||
//- Write peak/size/rss to stream
|
||||
friend Ostream& operator<<(Ostream&, const memInfo&);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user