mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: use memInfo instead of parsing meminfo ourselves
This commit is contained in:
@ -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";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user