diff --git a/applications/test/memInfo/Make/files b/applications/test/memInfo/Make/files
index c42564e8fc..1c9d3fff8e 100644
--- a/applications/test/memInfo/Make/files
+++ b/applications/test/memInfo/Make/files
@@ -1,3 +1,3 @@
-memInfo.C
+Test-memInfo.C
-EXE = $(FOAM_USER_APPBIN)/memInfo
+EXE = $(FOAM_USER_APPBIN)/Test-memInfo
diff --git a/applications/test/memInfo/Test-memInfo.C b/applications/test/memInfo/Test-memInfo.C
new file mode 100644
index 0000000000..0eb32803c8
--- /dev/null
+++ b/applications/test/memInfo/Test-memInfo.C
@@ -0,0 +1,61 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
+ \\/ M anipulation |
+-------------------------------------------------------------------------------
+License
+ This file is part of OpenFOAM.
+
+ OpenFOAM is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with OpenFOAM. If not, see .
+
+Application
+
+Description
+
+\*---------------------------------------------------------------------------*/
+
+#include "memInfo.H"
+#include "IOstreams.H"
+#include "List.H"
+#include "vector.H"
+
+using namespace Foam;
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// Main program:
+
+int main(int argc, char *argv[])
+{
+ const int n = 10000000;
+ const char* const memTags = "peak/size/rss mem: ";
+
+ memInfo mem;
+
+ Info<< memTags << mem << endl;
+ List lst(n, vector::one);
+
+ Info<< "allocate " << n << " vectors" << nl
+ << memTags << mem.update() << endl;
+
+ lst.clear();
+ Info<< "clear" << nl
+ << memTags << mem.update() << endl;
+
+ return 0;
+}
+
+
+// ************************************************************************* //
diff --git a/applications/test/memInfo/memInfo.C b/applications/test/memInfo/memInfo.C
deleted file mode 100644
index fb20be6d8d..0000000000
--- a/applications/test/memInfo/memInfo.C
+++ /dev/null
@@ -1,19 +0,0 @@
-#include "memInfo.H"
-#include "IOstreams.H"
-#include "List.H"
-#include "vector.H"
-
-using namespace Foam;
-
-int main()
-{
- memInfo m;
-
- Info<< m << endl;
-
- List l(10000000, vector::one);
-
- Info<< m.update() << endl;
-
- return 0;
-}
diff --git a/src/OSspecific/POSIX/memInfo/memInfo.C b/src/OSspecific/POSIX/memInfo/memInfo.C
index ef76fe004f..0d593ee4df 100644
--- a/src/OSspecific/POSIX/memInfo/memInfo.C
+++ b/src/OSspecific/POSIX/memInfo/memInfo.C
@@ -47,6 +47,8 @@ Foam::memInfo::~memInfo()
const Foam::memInfo& Foam::memInfo::update()
{
+ // reset to invalid values first
+ peak_ = size_ = rss_ = -1;
IFstream is("/proc/" + name(pid()) + "/status");
while (is.good())
diff --git a/src/OSspecific/POSIX/memInfo/memInfo.H b/src/OSspecific/POSIX/memInfo/memInfo.H
index 73f614fea7..25f29b0164 100644
--- a/src/OSspecific/POSIX/memInfo/memInfo.H
+++ b/src/OSspecific/POSIX/memInfo/memInfo.H
@@ -27,6 +27,9 @@ Class
Description
Memory usage information for the process running this object.
+Note
+ Uses the information from /proc/\/status
+
SourceFiles
memInfo.C
@@ -52,13 +55,13 @@ class memInfo
{
// Private data
- //- Peak memory used by the process (VmPeak in /proc//status)
+ //- Peak memory used by the process (VmPeak in /proc/\/status)
int peak_;
- //- Memory used by the process (VmSize in /proc//status)
+ //- Memory used by the process (VmSize in /proc/\/status)
int size_;
- //- Resident set size of the process (VmRSS in /proc//status)
+ //- Resident set size of the process (VmRSS in /proc/\/status)
int rss_;
@@ -76,24 +79,27 @@ public:
// Member Functions
- //- Parse /proc//status
+ //- Parse /proc/\/status
const memInfo& update();
// Access
- //- Access the stored peak memory
+ //- Access the stored peak memory (VmPeak in /proc/\/status)
+ // The value is stored from the previous update()
int peak() const
{
return peak_;
}
- //- Access the stored memory size
+ //- Access the stored memory size (VmSize in /proc/\/status)
+ // The value is stored from the previous update()
int size() const
{
return size_;
}
- //- Access the stored rss value
+ //- Access the stored rss value (VmRSS in /proc/\/status)
+ // The value is stored from the previous update()
int rss() const
{
return rss_;
@@ -102,7 +108,10 @@ public:
// IOstream Operators
+ //- Read peak/size/rss from stream
friend Istream& operator>>(Istream&, memInfo&);
+
+ //- Write peak/size/rss to stream
friend Ostream& operator<<(Ostream&, const memInfo&);
};