Functions
test_memusage.cxx File Reference
#include "WireCellUtil/MemUsage.h"
#include <iostream>
#include <sstream>
#include <vector>

Go to the source code of this file.

Functions

int * suck (MemUsage &mu, long siz)
 
void blow (MemUsage &mu, int siz, int *buf)
 
int main ()
 

Function Documentation

void blow ( MemUsage mu,
int  siz,
int *  buf 
)

Definition at line 33 of file test_memusage.cxx.

34 {
35  delete [] buf;
36  //sleep(1);
37  stringstream ss;
38  ss << "freed " << siz << "K";
39  cout << ss.str() << " " << mu(ss.str()) << endl;
40 }
QTextStream & endl(QTextStream &s)
int main ( void  )

Definition at line 42 of file test_memusage.cxx.

43 {
44  cout << "current size " << memusage_size() << endl;
45  cout << "current resident " << memusage_resident() << endl;
46  cout << "current shared " << memusage_shared() << endl;
47 
48  MemUsage mu;
49 
50  long sizes[] = {10, 100, 1000, 10000, 100000, 1000000, -1};
51  vector<int*> bufs;
52 
53  int ind = 0;
54  for (; sizes[ind] > 0; ++ind) {
55  int* buf = suck(mu, sizes[ind]);
56  bufs.push_back(buf);
57  }
58 
59  for (--ind; ind >= 0; --ind) {
60  blow(mu, sizes[ind], bufs[ind]);
61  }
62 
63  cout << "Summary:" << endl;
64  cout << mu.summary() << endl;
65 
66 }
double memusage_size()
Definition: MemUsage.cxx:57
void blow(MemUsage &mu, int siz, int *buf)
double memusage_resident()
Definition: MemUsage.cxx:43
std::string summary() const
Return summary up to now.
Definition: MemUsage.cxx:101
int * suck(MemUsage &mu, long siz)
QTextStream & endl(QTextStream &s)
double memusage_shared()
Definition: MemUsage.cxx:50
int* suck ( MemUsage mu,
long  siz 
)

Definition at line 11 of file test_memusage.cxx.

12 {
13  int *buf = new int[siz * 1024];
14  //sleep(1);
15  {
16  stringstream ss;
17  ss << "newed " << siz << "K";
18  cout << ss.str() << " " << mu(ss.str()) << endl;
19  }
20 
21  for (int ind=0; ind<siz; ++ind) {
22  buf[ind] = 0;
23  }
24  {
25  stringstream ss;
26  ss << "accessed " << siz << "K";
27  cout << ss.str() << " " << mu(ss.str()) << endl;
28  }
29 
30  return buf;
31 }
QTextStream & endl(QTextStream &s)