Jpp
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
examples
JSystem
JMemoryUsage.cc
Go to the documentation of this file.
1
2
#include <string>
3
#include <iostream>
4
#include <iomanip>
5
6
#include "
JSystem/JShell.hh
"
7
#include "
JSystem/JSystemToolkit.hh
"
8
9
#include "
Jeep/JPrint.hh
"
10
#include "
Jeep/JParser.hh
"
11
#include "
Jeep/JMessage.hh
"
12
13
14
/**
15
* \file
16
*
17
* Example program to show memory usage.
18
* \author mdejong
19
*/
20
int
main
(
int
argc,
char
**argv)
21
{
22
using namespace
std;
23
24
int
size_B;
25
int
debug
;
26
27
try
{
28
29
JParser<>
zap(
"Example program to show memory usage."
);
30
31
zap[
'M'
] =
make_field
(size_B) = 1<<25;
32
zap[
'd'
] =
make_field
(
debug
) = 3;
33
34
zap(argc, argv);
35
}
36
catch
(
const
exception &error) {
37
FATAL
(error.what() << endl);
38
}
39
40
41
using namespace
JPP;
42
43
44
//JShell shell;
45
46
typedef
long
long
int
JType_t;
47
48
const
int
size = size_B /
sizeof
(JType_t);
49
50
cout <<
"Memory usage (start) "
<<
FIXED
(5,2) <<
getMemoryUsage
() <<
"%"
<< endl;
51
52
53
JType_t* buffer =
new
JType_t[size];
54
55
cout <<
"Memory usage (new) "
<<
FIXED
(5,2) <<
getMemoryUsage
() <<
"%"
<< endl;
56
57
58
for
(
int
i = 0; i != size; ++i) {
59
buffer[i] = i;
60
}
61
62
cout <<
"Memory usage (assign) "
<<
FIXED
(5,2) <<
getMemoryUsage
() <<
"%"
<< endl;
63
64
65
delete
[] buffer;
66
67
cout <<
"Memory usage (delete) "
<<
FIXED
(5,2) <<
getMemoryUsage
() <<
"%"
<< endl;
68
}
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1493
JSYSTEM::getMemoryUsage
float getMemoryUsage(JShell &shell, const pid_t pid)
Get memory usage in percent of given process identifier.
Definition:
JSystemToolkit.hh:50
FIXED
Auxiliary data structure for floating point format specification.
Definition:
JPrint.hh:481
JPrint.hh
I/O formatting auxiliaries.
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1954
debug
int debug
debug level
Definition:
JSirene.cc:61
JMessage.hh
General purpose messaging.
FATAL
#define FATAL(A)
Definition:
JMessage.hh:67
JParser.hh
Utility class to parse command line options.
JShell.hh
Shell interaction via I/O streams.
JSystemToolkit.hh
System calls via shell interactions.
main
int main(int argc, char *argv[])
Definition:
Main.cpp:15
Generated by
1.8.5