Jpp
17.3.0-rc.1
the software that should make you happy
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
#include <string>
2
#include <iostream>
3
#include <iomanip>
4
#include <vector>
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
using namespace
JPP;
24
25
size_t
size_B;
26
int
debug
;
27
28
try
{
29
30
JParser<>
zap(
"Example program to show memory usage."
);
31
32
zap[
'M'
] =
make_field
(size_B) = 1<<25;
33
zap[
'd'
] =
make_field
(
debug
) = 3;
34
35
zap(argc, argv);
36
}
37
catch
(
const
exception &error) {
38
FATAL
(error.what() << endl);
39
}
40
41
typedef
long
long
int
data_type;
42
43
const
size_t
size = size_B /
sizeof
(data_type);
44
45
{
46
cout << endl;
47
cout <<
"Memory usage (start) "
<<
FIXED
(5,2) <<
getMemoryUsage
() <<
"%"
<< endl;
48
49
data_type* buffer =
new
data_type[size];
50
51
cout <<
"Memory usage (new) "
<<
FIXED
(5,2) <<
getMemoryUsage
() <<
"%"
<< endl;
52
53
for
(
size_t
i = 0; i != size; ++i) {
54
buffer[i] = i;
55
}
56
57
cout <<
"Memory usage (assign) "
<<
FIXED
(5,2) <<
getMemoryUsage
() <<
"%"
<< endl;
58
59
delete
[] buffer;
60
61
cout <<
"Memory usage (delete) "
<<
FIXED
(5,2) <<
getMemoryUsage
() <<
"%"
<< endl;
62
}
63
{
64
cout << endl;
65
cout <<
"Memory usage (start) "
<<
FIXED
(5,2) <<
getMemoryUsage
() <<
"%"
<< endl;
66
67
vector<data_type>
buffer(size);
68
69
cout <<
"Memory usage (vector) "
<<
FIXED
(5,2) <<
getMemoryUsage
() <<
"%"
<< endl;
70
71
buffer.clear();
72
73
cout <<
"Memory usage (clear) "
<<
FIXED
(5,2) <<
getMemoryUsage
() <<
"%"
<< endl;
74
75
{
76
vector<data_type>
zbuf;
77
78
buffer.swap(zbuf);
79
}
80
81
cout <<
"Memory usage (swap) "
<<
FIXED
(5,2) <<
getMemoryUsage
() <<
"%"
<< endl;
82
}
83
{
84
cout << endl;
85
cout <<
"Memory usage (start) "
<<
FIXED
(5,2) <<
getMemoryUsage
() <<
"%"
<< endl;
86
87
size_t
N
= 10;
88
89
vector< vector<data_type>
> buffer(N);
90
91
for
(
size_t
i = 0; i !=
N
; ++i) {
92
buffer[i].resize(size / N);
93
}
94
95
cout <<
"Memory usage (vector) "
<<
FIXED
(5,2) <<
getMemoryUsage
() <<
"%"
<< endl;
96
97
buffer.clear();
98
99
cout <<
"Memory usage (clear) "
<<
FIXED
(5,2) <<
getMemoryUsage
() <<
"%"
<< endl;
100
101
{
102
vector< vector<data_type>
> zbuf;
103
104
buffer.swap(zbuf);
105
}
106
107
cout <<
"Memory usage (swap) "
<<
FIXED
(5,2) <<
getMemoryUsage
() <<
"%"
<< endl;
108
}
109
}
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1517
JSYSTEM::getMemoryUsage
float getMemoryUsage(JShell &shell, const pid_t pid)
Get memory usage in percent of given process identifier.
Definition:
JSystemToolkit.hh:52
main
int main(int argc, char *argv[])
Definition:
Main.cc:15
N
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
Definition:
JShowerPostfit.sh:95
FIXED
Auxiliary data structure for floating point format specification.
Definition:
JManip.hh:446
std::vector
Definition:
JSTDTypes.hh:12
JPrint.hh
I/O formatting auxiliaries.
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1993
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 auxiliaries.
debug
int debug
debug level
Definition:
archive-put-wiki-detectors.sh:92
Generated by
1.8.5