|
5 | 5 |
|
6 | 6 | > python memleak_gui.py -dGTKAgg # or TkAgg, etc.. |
7 | 7 |
|
| 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 | +
|
8 | 13 | You may need to edit cbook.report_memory to support your platform |
9 | 14 |
|
10 | 15 | ''' |
11 | 16 | import os, sys, time |
12 | 17 | import gc |
| 18 | +from optparse import OptionParser |
13 | 19 | 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 | | - |
19 | 20 | import pylab |
20 | 21 | from matplotlib import _pylab_helpers as ph |
21 | 22 | import matplotlib.cbook as cbook |
22 | 23 |
|
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): |
25 | 51 |
|
26 | 52 | fig = pylab.figure() |
27 | | - fig.savefig('test') |
| 53 | + #fig.savefig('test') # This seems to just slow down the testing. |
28 | 54 | fig.clf() |
29 | 55 | pylab.close(fig) |
30 | | - val = cbook.report_memory(i) |
31 | | - print i, val |
32 | 56 | gc.collect() |
| 57 | + val = cbook.report_memory(i) |
| 58 | + if options.verbose: |
| 59 | + if i % 10 == 0: |
| 60 | + print i, val |
33 | 61 | if i==indStart: start = val # wait a few cycles for memory usage to stabilize |
34 | 62 |
|
35 | 63 | gc.collect() |
| 64 | +end = val |
| 65 | + |
36 | 66 | print |
37 | 67 | print 'uncollectable list:', gc.garbage |
38 | 68 | print |
39 | | -end = val |
| 69 | + |
40 | 70 | 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) |
41 | 74 | print 'Average memory consumed per loop: %1.4fk bytes\n' % ((end-start)/float(indEnd-indStart)) |
42 | 75 |
|
0 commit comments