Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
wire-cell-build
util
test
test_memusage.cxx
Go to the documentation of this file.
1
#include "
WireCellUtil/MemUsage.h
"
2
3
#include <iostream>
4
#include <sstream>
5
#include <vector>
6
//#include <unistd.h>
7
8
using namespace
std
;
9
using namespace
WireCell
;
10
11
int
*
suck
(
MemUsage
& mu,
long
siz)
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
}
32
33
void
blow
(
MemUsage
& mu,
int
siz,
int
* buf)
34
{
35
delete
[] buf;
36
//sleep(1);
37
stringstream ss;
38
ss <<
"freed "
<< siz <<
"K"
;
39
cout << ss.str() <<
" "
<< mu(ss.str()) <<
endl
;
40
}
41
42
int
main
()
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
}
WireCell::memusage_size
double memusage_size()
Definition:
MemUsage.cxx:57
std
STL namespace.
blow
void blow(MemUsage &mu, int siz, int *buf)
Definition:
test_memusage.cxx:33
WireCell::memusage_resident
double memusage_resident()
Definition:
MemUsage.cxx:43
MemUsage.h
WireCell
Definition:
Main.h:22
WireCell::MemUsage
Definition:
MemUsage.h:19
WireCell::MemUsage::summary
std::string summary() const
Return summary up to now.
Definition:
MemUsage.cxx:101
suck
int * suck(MemUsage &mu, long siz)
Definition:
test_memusage.cxx:11
main
int main()
Definition:
test_memusage.cxx:42
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
WireCell::memusage_shared
double memusage_shared()
Definition:
MemUsage.cxx:50
Generated by
1.8.11