Commit d77d215c authored by graham's avatar graham
Browse files

ENH: memSize and memSizePeak functions, reading /proc/<pid>/status.

parent 8f0a5ff1
...@@ -36,6 +36,7 @@ Description ...@@ -36,6 +36,7 @@ Description
#include "fileName.H" #include "fileName.H"
#include "fileStat.H" #include "fileStat.H"
#include "timer.H" #include "timer.H"
#include "IFstream.H"
#include <fstream> #include <fstream>
#include <cstdlib> #include <cstdlib>
...@@ -1037,4 +1038,58 @@ int Foam::system(const string& command) ...@@ -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); ...@@ -176,6 +176,12 @@ bool ping(const word&, const label timeOut=10);
//- Execute the specified command //- Execute the specified command
int system(const string& 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 } // End namespace Foam
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment