Jpp
Functions
JMemoryUsage.cc File Reference
#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

◆ main()

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 }
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
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
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
std
Definition: jaanetDictionary.h:36
FATAL
#define FATAL(A)
Definition: JMessage.hh:67