Jpp master_rocky-44-g75b7c4f75
the software that should make you happy
Loading...
Searching...
No Matches
JMemoryUsage.cc File Reference

Example program to show memory usage. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include "JSystem/JShell.hh"
#include "JSystem/JSystemToolkit.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to show memory usage.

Author
mdejong

Definition in file JMemoryUsage.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 20 of file JMemoryUsage.cc.

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 {
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 {
103
104 buffer.swap(zbuf);
105 }
106
107 cout << "Memory usage (swap) " << FIXED(5,2) << getMemoryUsage() << "%" << endl;
108 }
109}
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
float getMemoryUsage(JShell &shell, const pid_t pid)
Get memory usage in percent of given process identifier.
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Data structure for measured coincidence rates of all pairs of PMTs in optical module.
Definition JFitK40.hh:103