Jpp  15.0.1-rc.1-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JMemoryUsage.cc File Reference

Example program to show memory usage. More...

#include <string>
#include <iostream>
#include <iomanip>
#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

int main ( int  argc,
char **  argv 
)

Definition at line 20 of file JMemoryUsage.cc.

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 }
Utility class to parse command line options.
Definition: JParser.hh:1500
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:446
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67