ENH: use memInfo instead of parsing meminfo ourselves

This commit is contained in:
Mark Olesen
2010-11-26 13:29:34 +01:00
parent 90eb6623c5
commit 0a17e0719d

View File

@ -33,6 +33,7 @@ Description
#include "fvMesh.H" #include "fvMesh.H"
#include "Time.H" #include "Time.H"
#include "IFstream.H" #include "IFstream.H"
#include "memInfo.H"
// VTK includes // VTK includes
#include "vtkDataArraySelection.h" #include "vtkDataArraySelection.h"
@ -325,44 +326,13 @@ void Foam::vtkPV3Foam::setSelectedArrayEntries
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// parse these bits of info from /proc/meminfo (Linux)
//
// MemTotal: 2062660 kB
// MemFree: 1124400 kB
//
// used = MemTotal - MemFree is what the free(1) uses.
//
void Foam::vtkPV3Foam::printMemory() void Foam::vtkPV3Foam::printMemory()
{ {
const char* meminfo = "/proc/meminfo"; memInfo mem;
if (exists(meminfo)) if (mem.valid())
{ {
IFstream is(meminfo); Info<< "mem peak/size/rss: " << mem << "\n";
label memTotal = 0;
label memFree = 0;
string line;
while (is.getLine(line).good())
{
char tag[32];
int value;
if (sscanf(line.c_str(), "%30s %d", tag, &value) == 2)
{
if (!strcmp(tag, "MemTotal:"))
{
memTotal = value;
}
else if (!strcmp(tag, "MemFree:"))
{
memFree = value;
}
}
}
Info<< "memUsed: " << (memTotal - memFree) << " kB\n";
} }
} }