Skip to content

Commit 208c8f0

Browse files
committed
More command-line options for memleak_gui.py
svn path=/trunk/matplotlib/; revision=3442
1 parent 7b3c56b commit 208c8f0

File tree

1 file changed

+44
-11
lines changed

1 file changed

+44
-11
lines changed

unit/memleak_gui.py

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,71 @@
55
66
> python memleak_gui.py -dGTKAgg # or TkAgg, etc..
77
8+
use --help option to see all options
9+
10+
The default number of loops typically will not yield a stable
11+
estimate--for that you may need many hundreds of loops and some patience.
12+
813
You may need to edit cbook.report_memory to support your platform
914
1015
'''
1116
import os, sys, time
1217
import gc
18+
from optparse import OptionParser
1319
import matplotlib
14-
15-
#matplotlib.use('TkAgg') # or TkAgg or WxAgg or QtAgg or Gtk
16-
#matplotlib.rcParams['toolbar'] = 'toolbar2' # None, classic, toolbar2
17-
matplotlib.rcParams['toolbar'] = None # None, classic, toolbar2
18-
1920
import pylab
2021
from matplotlib import _pylab_helpers as ph
2122
import matplotlib.cbook as cbook
2223

23-
indStart, indEnd = 30, 50
24-
for i in range(indEnd):
24+
parser = OptionParser()
25+
parser.add_option("-q", "--quiet", default=True,
26+
action="store_false", dest="verbose")
27+
parser.add_option("-s", "--start", dest="start",
28+
default="30",
29+
help="first index of averaging interval")
30+
parser.add_option("-e", "--end", dest="end",
31+
default="100",
32+
help="last index of averaging interval")
33+
parser.add_option("-t", "--toolbar", dest="toolbar",
34+
default="toolbar2",
35+
help="toolbar: None, classic, toolbar2")
36+
# The following overrides matplotlib's version of the -d option
37+
# uses it if found
38+
parser.add_option("-d", "--backend", dest="backend",
39+
default=matplotlib.rcParams['backend'],
40+
help="backend")
41+
42+
43+
options, args = parser.parse_args()
44+
45+
indStart = int(options.start)
46+
indEnd = int(options.end)
47+
matplotlib.rcParams['toolbar'] = matplotlib.validate_toolbar(options.toolbar)
48+
matplotlib.rcParams['backend'] = matplotlib.validate_backend(options.backend)
49+
50+
for i in range(indEnd+1):
2551

2652
fig = pylab.figure()
27-
fig.savefig('test')
53+
#fig.savefig('test') # This seems to just slow down the testing.
2854
fig.clf()
2955
pylab.close(fig)
30-
val = cbook.report_memory(i)
31-
print i, val
3256
gc.collect()
57+
val = cbook.report_memory(i)
58+
if options.verbose:
59+
if i % 10 == 0:
60+
print i, val
3361
if i==indStart: start = val # wait a few cycles for memory usage to stabilize
3462

3563
gc.collect()
64+
end = val
65+
3666
print
3767
print 'uncollectable list:', gc.garbage
3868
print
39-
end = val
69+
4070
if i > indStart:
71+
print 'Backend %(backend)s, toolbar %(toolbar)s' % matplotlib.rcParams
72+
print 'Averaging over loops %d to %d' % (indStart, indEnd)
73+
print 'Memory went from %dk to %dk' % (start, end)
4174
print 'Average memory consumed per loop: %1.4fk bytes\n' % ((end-start)/float(indEnd-indStart))
4275

0 commit comments

Comments
 (0)