mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: provide basic cpu-information
- can be useful later when trying to interpret run-times etc. Contains only the most basic information.
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -24,14 +24,29 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "memInfo.H"
|
||||
#include "IFstream.H"
|
||||
#include "IOstreams.H"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
// file-scope function
|
||||
template<class T>
|
||||
inline static void writeEntry
|
||||
(
|
||||
Foam::Ostream& os, const Foam::word& key, const T& value
|
||||
)
|
||||
{
|
||||
os.writeKeyword(key) << value << Foam::token::END_STATEMENT << '\n';
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::memInfo::memInfo()
|
||||
:
|
||||
peak_(-1),
|
||||
size_(-1),
|
||||
rss_(-1)
|
||||
peak_(0),
|
||||
size_(0),
|
||||
rss_(0)
|
||||
{
|
||||
update();
|
||||
}
|
||||
@ -48,7 +63,7 @@ Foam::memInfo::~memInfo()
|
||||
const Foam::memInfo& Foam::memInfo::update()
|
||||
{
|
||||
// reset to invalid values first
|
||||
peak_ = size_ = rss_ = -1;
|
||||
peak_ = size_ = rss_ = 0;
|
||||
IFstream is("/proc/" + name(pid()) + "/status");
|
||||
|
||||
while (is.good())
|
||||
@ -81,7 +96,15 @@ const Foam::memInfo& Foam::memInfo::update()
|
||||
|
||||
bool Foam::memInfo::valid() const
|
||||
{
|
||||
return peak_ != -1;
|
||||
return peak_ > 0;
|
||||
}
|
||||
|
||||
|
||||
void Foam::memInfo::write(Ostream& os) const
|
||||
{
|
||||
writeEntry(os, "size", size_);
|
||||
writeEntry(os, "peak", peak_);
|
||||
writeEntry(os, "rss", rss_);
|
||||
}
|
||||
|
||||
|
||||
@ -108,14 +131,15 @@ Foam::Istream& Foam::operator>>(Istream& is, memInfo& m)
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const memInfo& m)
|
||||
{
|
||||
os << token::BEGIN_LIST
|
||||
<< m.peak_ << token::SPACE << m.size_ << token::SPACE << m.rss_
|
||||
<< m.peak_ << token::SPACE
|
||||
<< m.size_ << token::SPACE
|
||||
<< m.rss_
|
||||
<< token::END_LIST;
|
||||
|
||||
// Check state of Ostream
|
||||
os.check
|
||||
(
|
||||
"Foam::Ostream& Foam::operator<<(Foam::Ostream&, "
|
||||
"const Foam::memInfo&)"
|
||||
"Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::memInfo&)"
|
||||
);
|
||||
|
||||
return os;
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -28,7 +28,7 @@ Description
|
||||
Memory usage information for the process running this object.
|
||||
|
||||
Note
|
||||
Uses the information from /proc/\<pid\>/status
|
||||
Uses the information from /proc/PID/status
|
||||
|
||||
SourceFiles
|
||||
memInfo.C
|
||||
@ -47,6 +47,10 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// forward declarations
|
||||
class Istream;
|
||||
class Ostream;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class memInfo Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -55,15 +59,20 @@ 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_;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const memInfo&) = delete;
|
||||
|
||||
//- Disallow default copy constructor
|
||||
memInfo(const memInfo&) = delete;
|
||||
|
||||
public:
|
||||
|
||||
@ -79,27 +88,24 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Parse /proc/\<pid\>/status
|
||||
//- Parse /proc/PID/status and update accordingly
|
||||
const memInfo& update();
|
||||
|
||||
// Access
|
||||
|
||||
//- Access the stored peak memory (VmPeak in /proc/\<pid\>/status)
|
||||
// The value is stored from the previous update()
|
||||
//- Peak memory (VmPeak in /proc/PID/status) at last update()
|
||||
int peak() const
|
||||
{
|
||||
return peak_;
|
||||
}
|
||||
|
||||
//- Access the stored memory size (VmSize in /proc/\<pid\>/status)
|
||||
// The value is stored from the previous update()
|
||||
//- Memory size (VmSize in /proc/PID/status) at last update()
|
||||
int size() const
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
|
||||
//- Access the stored rss value (VmRSS in /proc/\<pid\>/status)
|
||||
// The value is stored from the previous update()
|
||||
//- Resident set size (VmRSS in /proc/PID/status) at last update()
|
||||
int rss() const
|
||||
{
|
||||
return rss_;
|
||||
@ -109,6 +115,10 @@ public:
|
||||
bool valid() const;
|
||||
|
||||
|
||||
//- Write content as dictionary entries
|
||||
void write(Ostream&) const;
|
||||
|
||||
|
||||
// IOstream Operators
|
||||
|
||||
//- Read peak/size/rss from stream
|
||||
|
||||
Reference in New Issue
Block a user