@@ -1438,42 +1438,6 @@ def restrict_dict(d, keys):
14381438 return dict ([(k , v ) for (k , v ) in six .iteritems (d ) if k in keys ])
14391439
14401440
1441- def report_memory (i = 0 ): # argument may go away
1442- 'return the memory, in bytes, consumed by process'
1443- from matplotlib .compat .subprocess import Popen , PIPE
1444- pid = os .getpid ()
1445- if sys .platform .startswith ('linux' ):
1446- try :
1447- a2 = Popen ('ps -p %d -o rss,sz' % pid , shell = True ,
1448- stdout = PIPE ).stdout .readlines ()
1449- except OSError :
1450- raise NotImplementedError (
1451- "report_memory works on Linux only if "
1452- "the 'ps' program is found" )
1453- mem = int (a2 [1 ].split ()[1 ]) * 1024
1454- elif sys .platform .startswith ('darwin' ):
1455- try :
1456- a2 = Popen ('ps -p %d -o rss,vsz' % pid , shell = True ,
1457- stdout = PIPE ).stdout .readlines ()
1458- except OSError :
1459- raise NotImplementedError (
1460- "report_memory works on Mac OS only if "
1461- "the 'ps' program is found" )
1462- mem = int (a2 [1 ].split ()[0 ]) * 1024
1463- elif sys .platform .startswith ('win' ):
1464- try :
1465- a2 = Popen (["tasklist" , "/nh" , "/fi" , "pid eq %d" % pid ],
1466- stdout = PIPE ).stdout .read ()
1467- except OSError :
1468- raise NotImplementedError (
1469- "report_memory works on Windows only if "
1470- "the 'tasklist' program is found" )
1471- mem = int (a2 .strip ().split ()[- 2 ].replace (',' , '' )) * 1024
1472- else :
1473- raise NotImplementedError (
1474- "We don't have a memory monitor for %s" % sys .platform )
1475- return mem
1476-
14771441_safezip_msg = 'In safezip, len(args[0])=%d but len(args[%d])=%d'
14781442
14791443
@@ -1505,58 +1469,6 @@ def safe_masked_invalid(x):
15051469 return xm
15061470
15071471
1508- class MemoryMonitor (object ):
1509- def __init__ (self , nmax = 20000 ):
1510- self ._nmax = nmax
1511- self ._mem = np .zeros ((self ._nmax ,), np .int32 )
1512- self .clear ()
1513-
1514- def clear (self ):
1515- self ._n = 0
1516- self ._overflow = False
1517-
1518- def __call__ (self ):
1519- mem = report_memory ()
1520- if self ._n < self ._nmax :
1521- self ._mem [self ._n ] = mem
1522- self ._n += 1
1523- else :
1524- self ._overflow = True
1525- return mem
1526-
1527- def report (self , segments = 4 ):
1528- n = self ._n
1529- segments = min (n , segments )
1530- dn = int (n / segments )
1531- ii = list (xrange (0 , n , dn ))
1532- ii [- 1 ] = n - 1
1533- print ()
1534- print ('memory report: i, mem, dmem, dmem/nloops' )
1535- print (0 , self ._mem [0 ])
1536- for i in range (1 , len (ii )):
1537- di = ii [i ] - ii [i - 1 ]
1538- if di == 0 :
1539- continue
1540- dm = self ._mem [ii [i ]] - self ._mem [ii [i - 1 ]]
1541- print ('%5d %5d %3d %8.3f' % (ii [i ], self ._mem [ii [i ]],
1542- dm , dm / float (di )))
1543- if self ._overflow :
1544- print ("Warning: array size was too small for the number of calls." )
1545-
1546- def xy (self , i0 = 0 , isub = 1 ):
1547- x = np .arange (i0 , self ._n , isub )
1548- return x , self ._mem [i0 :self ._n :isub ]
1549-
1550- def plot (self , i0 = 0 , isub = 1 , fig = None ):
1551- if fig is None :
1552- from .pylab import figure
1553- fig = figure ()
1554-
1555- ax = fig .add_subplot (111 )
1556- ax .plot (* self .xy (i0 , isub ))
1557- fig .canvas .draw ()
1558-
1559-
15601472def print_cycles (objects , outstream = sys .stdout , show_progress = False ):
15611473 """
15621474 *objects*
0 commit comments