Skip to content

Commit 6c3d283

Browse files
committed
TST: add report plot to memleak_hawaii3.py
1 parent 88f9a66 commit 6c3d283

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

unit/memleak_hawaii3.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88

99
from matplotlib.cbook import report_memory
1010
import numpy as np
11-
from pylab import figure, show, close
12-
11+
import matplotlib.pyplot as plt
1312
# take a memory snapshot on indStart and compare it with indEnd
1413

1514
rand = np.random.rand
1615

1716
indStart, indEnd = 200, 401
17+
mem_size, coll_count = [], []
1818
for i in range(indEnd):
1919

20-
fig = figure(1)
20+
fig = plt.figure(1)
2121
fig.clf()
2222

2323
t1 = np.arange(0.0, 2.0, 0.01)
@@ -39,13 +39,23 @@
3939
ax.pcolor(10 * rand(50, 50))
4040

4141
fig.savefig('tmp%d' % i, dpi=75)
42-
close(1)
42+
plt.close(1)
4343

44-
gc.collect()
44+
coll = gc.collect()
4545
val = report_memory(i)
4646
print(i, val)
4747
if i == indStart:
4848
start = val # wait a few cycles for memory usage to stabilize
49+
mem_size.append(val)
50+
coll_count.append(coll)
4951

5052
end = val
51-
print('Average memory consumed per loop: %1.4fk bytes\n' % ((end - start) / float(indEnd - indStart)))
53+
print('Average memory consumed per loop: %1.4fk bytes\n' %
54+
((end - start) / float(indEnd - indStart)))
55+
fig, ax = plt.subplots()
56+
ax2 = ax.twinx()
57+
ax.plot(mem_size, 'r')
58+
ax.set_ylabel('memory size', color='r')
59+
ax2.plot(coll_count, 'k')
60+
ax2.set_ylabel('collect count', color='k')
61+
fig.savefig('report')

0 commit comments

Comments
 (0)