Skip to content

Commit a2cf4f9

Browse files
authored
Merge pull request #17500 from tacaswell/tst_improve_memleak
Tst improve memleak
2 parents eeadff3 + dcdd8a1 commit a2cf4f9

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

tools/memleak.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def run_memleak_test(bench, iterations, report):
4141
print("{0: 4d}: pymalloc {1: 10d}, rss {2: 10d}, nobjs {3: 10d}, "
4242
"garbage {4: 4d}, files: {5: 4d}".format(
4343
i, malloc, rss, nobjs, garbage, open_files))
44-
44+
if i == starti:
45+
print('{:-^86s}'.format(' warmup done '))
4546
malloc_arr[i] = malloc
4647
rss_arr[i] = rss
4748
if rss > rss_peak:
@@ -55,18 +56,25 @@ def run_memleak_test(bench, iterations, report):
5556
np.sum(rss_peaks[starti+1:] - rss_peaks[starti:-1]) / (endi - starti)))
5657

5758
from matplotlib import pyplot as plt
59+
from matplotlib.ticker import EngFormatter
60+
bytes_formatter = EngFormatter(unit='B')
5861
fig, (ax1, ax2, ax3) = plt.subplots(3)
62+
for ax in (ax1, ax2, ax3):
63+
ax.axvline(starti, linestyle='--', color='k')
5964
ax1b = ax1.twinx()
60-
ax1.plot(malloc_arr, 'r')
61-
ax1b.plot(rss_arr, 'b')
62-
ax1.set_ylabel('pymalloc', color='r')
63-
ax1b.set_ylabel('rss', color='b')
65+
ax1b.yaxis.set_major_formatter(bytes_formatter)
66+
ax1.plot(malloc_arr, 'C0')
67+
ax1b.plot(rss_arr, 'C1', label='rss')
68+
ax1b.plot(rss_peaks, 'C1', linestyle='--', label='rss max')
69+
ax1.set_ylabel('pymalloc', color='C0')
70+
ax1b.set_ylabel('rss', color='C1')
71+
ax1b.legend()
6472

6573
ax2b = ax2.twinx()
66-
ax2.plot(nobjs_arr, 'r')
67-
ax2b.plot(garbage_arr, 'b')
68-
ax2.set_ylabel('total objects', color='r')
69-
ax2b.set_ylabel('garbage objects', color='b')
74+
ax2.plot(nobjs_arr, 'C0')
75+
ax2b.plot(garbage_arr, 'C1')
76+
ax2.set_ylabel('total objects', color='C0')
77+
ax2b.set_ylabel('garbage objects', color='C1')
7078

7179
ax3.plot(open_files_arr)
7280
ax3.set_ylabel('open file handles')
@@ -107,6 +115,7 @@ def __call__(self):
107115
ax.pcolor(10 * np.random.rand(50, 50))
108116

109117
fig.savefig(BytesIO(), dpi=75)
118+
fig.canvas.flush_events()
110119
plt.close(1)
111120

112121

0 commit comments

Comments
 (0)