diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index 8f068f4dba..69d035733e 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -36,6 +36,7 @@ Description #include "fileName.H" #include "fileStat.H" #include "timer.H" +#include "IFstream.H" #include #include @@ -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; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/include/OSspecific.H b/src/OpenFOAM/include/OSspecific.H index 7b4c3a5320..bc747b907c 100644 --- a/src/OpenFOAM/include/OSspecific.H +++ b/src/OpenFOAM/include/OSspecific.H @@ -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