Skip to content

Commit 5849016

Browse files
committed
updates to memleak script
svn path=/trunk/matplotlib/; revision=3334
1 parent bd5c225 commit 5849016

File tree

1 file changed

+26
-36
lines changed

1 file changed

+26
-36
lines changed

unit/memleak_hawaii3.py

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,51 @@
11
#!/usr/bin/env python
22

3-
import os, sys, time
3+
import os, sys, time, gc
44
import matplotlib
5-
#matplotlib.interactive(True)
6-
#matplotlib.use('Cairo')
75
matplotlib.use('Agg')
8-
from pylab import *
9-
10-
11-
def report_memory(i):
12-
pid = os.getpid()
13-
a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines()
14-
print i, ' ', a2[1],
15-
return int(a2[1].split()[1])
16-
176

7+
from matplotlib.cbook import report_memory
8+
import matplotlib.numerix as nx
9+
from pylab import figure, show, close
1810

1911
# take a memory snapshot on indStart and compare it with indEnd
2012

13+
rand = nx.mlab.rand
14+
2115
indStart, indEnd = 30, 201
2216
for i in range(indEnd):
2317

24-
figure(1); clf()
18+
fig = figure(1)
19+
fig.clf()
20+
21+
22+
t1 = nx.arange(0.0, 2.0, 0.01)
23+
y1 = nx.sin(2*nx.pi*t1)
24+
y2 = rand(len(t1))
25+
X = rand(50,50)
2526

26-
subplot(221)
27-
t1 = arange(0.0, 2.0, 0.01)
28-
y = sin(2*pi*t1)
29-
plot(t1,y,'-')
30-
plot(t1, rand(len(t1)), 's', hold=True)
27+
ax = fig.add_subplot(221)
28+
ax.plot(t1, y1, '-')
29+
ax.plot(t1, y2, 's')
3130

3231

33-
subplot(222)
34-
X = rand(50,50)
32+
ax = fig.add_subplot(222)
33+
ax.imshow(X)
3534

36-
imshow(X)
37-
subplot(223)
38-
scatter(rand(50), rand(50), s=100*rand(50), c=rand(50))
39-
subplot(224)
40-
pcolor(10*rand(50,50))
41-
#ion()
42-
#draw()
35+
ax = fig.add_subplot(223)
36+
ax.scatter(rand(50), rand(50), s=100*rand(50), c=rand(50))
4337

44-
#ioff()
38+
ax = fig.add_subplot(224)
39+
ax.pcolor(10*rand(50,50))
4540

46-
#fd = file('tmp%d' % i, 'wb')
47-
#savefig(fd, dpi = 75)
48-
#fd.close()
49-
savefig('tmp%d' % i, dpi = 75)
41+
fig.savefig('tmp%d' % i, dpi = 75)
5042
close(1)
51-
#break
5243

44+
gc.collect()
5345
val = report_memory(i)
46+
print i, val
5447
if i==indStart: start = val # wait a few cycles for memory usage to stabilize
5548

5649
end = val
5750
print 'Average memory consumed per loop: %1.4fk bytes\n' % ((end-start)/float(indEnd-indStart))
5851

59-
"""
60-
Average memory consumed per loop: 0.0053k bytes
61-
"""

0 commit comments

Comments
 (0)