Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
9f1d94bd
Commit
9f1d94bd
authored
Nov 18, 2010
by
graham
Browse files
ENH: memInfo class.
parent
d77d215c
Changes
8
Hide whitespace changes
Inline
Side-by-side
applications/test/memInfo/Make/files
0 → 100644
View file @
9f1d94bd
memInfo.C
EXE = $(FOAM_USER_APPBIN)/memInfo
applications/test/memInfo/Make/options
0 → 100644
View file @
9f1d94bd
applications/test/memInfo/memInfo.C
0 → 100644
View file @
9f1d94bd
#include
"memInfo.H"
#include
"IOstreams.H"
#include
"List.H"
#include
"vector.H"
using
namespace
Foam
;
int
main
()
{
memInfo
m
;
Info
<<
m
<<
endl
;
List
<
vector
>
l
(
10000000
,
vector
::
one
);
Info
<<
m
.
update
()
<<
endl
;
return
0
;
}
src/OSspecific/POSIX/Make/files
View file @
9f1d94bd
...
...
@@ -8,6 +8,7 @@ fileStat.C
POSIX.C
cpuTime/cpuTime.C
clockTime/clockTime.C
memInfo/memInfo.C
/*
* Note: fileMonitor assumes inotify by default. Compile with -DFOAM_USE_STAT
...
...
src/OSspecific/POSIX/POSIX.C
View file @
9f1d94bd
...
...
@@ -1038,58 +1038,4 @@ 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
;
}
// ************************************************************************* //
src/OSspecific/POSIX/memInfo/memInfo.C
0 → 100644
View file @
9f1d94bd
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include
"memInfo.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam
::
memInfo
::
memInfo
()
:
peak_
(
-
1
),
size_
(
-
1
),
rss_
(
-
1
)
{
update
();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam
::
memInfo
::~
memInfo
()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const
Foam
::
memInfo
&
Foam
::
memInfo
::
update
()
{
IFstream
is
(
"/proc/"
+
name
(
pid
())
+
"/status"
);
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:"
))
{
peak_
=
value
;
}
else
if
(
!
strcmp
(
tag
,
"VmSize:"
))
{
size_
=
value
;
}
else
if
(
!
strcmp
(
tag
,
"VmRSS:"
))
{
rss_
=
value
;
}
}
}
return
*
this
;
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam
::
Istream
&
Foam
::
operator
>>
(
Istream
&
is
,
memInfo
&
m
)
{
is
.
readBegin
(
"memInfo"
);
is
>>
m
.
peak_
>>
m
.
size_
>>
m
.
rss_
;
is
.
readEnd
(
"memInfo"
);
// Check state of Istream
is
.
check
(
"Foam::Istream& Foam::operator>>(Foam::Istream&, Foam::memInfo&)"
);
return
is
;
}
Foam
::
Ostream
&
Foam
::
operator
<<
(
Ostream
&
os
,
const
memInfo
&
m
)
{
os
<<
token
::
BEGIN_LIST
<<
m
.
peak_
<<
token
::
SPACE
<<
m
.
size_
<<
token
::
SPACE
<<
m
.
rss_
<<
token
::
END_LIST
;
// Check state of Ostream
os
.
check
(
"Foam::Ostream& Foam::operator<<(Foam::Ostream&, "
"const Foam::memInfo&)"
);
return
os
;
}
// ************************************************************************* //
src/OSspecific/POSIX/memInfo/memInfo.H
0 → 100644
View file @
9f1d94bd
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
Class
Foam::memInfo
Description
Memory usage information for the process running this object.
SourceFiles
memInfo.C
\*---------------------------------------------------------------------------*/
#ifndef memInfo_H
#define memInfo_H
#include
"OSspecific.H"
#include
"POSIX.H"
#include
"IFstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace
Foam
{
/*---------------------------------------------------------------------------*\
Class memInfo Declaration
\*---------------------------------------------------------------------------*/
class
memInfo
{
// Private data
//- Peak memory used by the process (VmPeak in /proc/<pid>/status)
int
peak_
;
//- Memory used by the process (VmSize in /proc/<pid>/status)
int
size_
;
//- Resident set size of the process (VmRSS in /proc/<pid>/status)
int
rss_
;
public:
// Constructors
//- Construct null
memInfo
();
//- Destructor
~
memInfo
();
// Member Functions
//- Parse /proc/<pid>/status
const
memInfo
&
update
();
// Access
//- Access the stored peak memory
int
peak
()
const
{
return
peak_
;
}
//- Access the stored memory size
int
size
()
const
{
return
size_
;
}
//- Access the stored rss value
int
rss
()
const
{
return
rss_
;
}
// IOstream Operators
friend
Istream
&
operator
>>
(
Istream
&
,
memInfo
&
);
friend
Ostream
&
operator
<<
(
Ostream
&
,
const
memInfo
&
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
}
// End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
src/OpenFOAM/include/OSspecific.H
View file @
9f1d94bd
...
...
@@ -176,12 +176,6 @@ 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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment