mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: memSize and memSizePeak functions, reading /proc/<pid>/status.
This commit is contained in:
@ -36,6 +36,7 @@ Description
|
||||
#include "fileName.H"
|
||||
#include "fileStat.H"
|
||||
#include "timer.H"
|
||||
#include "IFstream.H"
|
||||
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
@ -1037,4 +1038,58 @@ int Foam::system(const string& command)
|
||||
}
|
||||
|
||||
|
||||
int Foam::memSize()
|
||||
{
|
||||
IFstream is("/proc/" + name(pid()) + "/status");
|
||||
|
||||
int VmSize = 0;
|
||||
|
||||
while (is.good())
|
||||
{
|
||||
string line;
|
||||
is.getLine(line);
|
||||
char tag[32];
|
||||
int value;
|
||||
|
||||
if (sscanf(line.c_str(), "%30s %d", tag, &value) == 2)
|
||||
{
|
||||
if (!strcmp(tag, "VmSize:"))
|
||||
{
|
||||
VmSize = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return VmSize;
|
||||
}
|
||||
|
||||
|
||||
int Foam::memPeakSize()
|
||||
{
|
||||
IFstream is("/proc/" + name(pid()) + "/status");
|
||||
|
||||
int VmPeak = 0;
|
||||
|
||||
while (is.good())
|
||||
{
|
||||
string line;
|
||||
is.getLine(line);
|
||||
char tag[32];
|
||||
int value;
|
||||
|
||||
if (sscanf(line.c_str(), "%30s %d", tag, &value) == 2)
|
||||
{
|
||||
if (!strcmp(tag, "VmPeak:"))
|
||||
{
|
||||
VmPeak = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return VmPeak;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -176,6 +176,12 @@ bool ping(const word&, const label timeOut=10);
|
||||
//- Execute the specified command
|
||||
int system(const string& command);
|
||||
|
||||
//- Return the size in memory of the current process
|
||||
int memSize();
|
||||
|
||||
//- Return the peak size in memory of the current process
|
||||
int memPeakSize();
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
Reference in New Issue
Block a user