Jpp
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"
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 }
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
JMessage.hh
JPrint.hh
main
int main(int argc, char **argv)
Definition: JMemoryUsage.cc:20
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
debug
int debug
debug level
Definition: JSirene.cc:59
JParser.hh
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
std
Definition: jaanetDictionary.h:36
JShell.hh
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
JSystemToolkit.hh