@@ -1423,6 +1423,52 @@ def restrict_dict(d, keys):
1423
1423
return dict ([(k , v ) for (k , v ) in six .iteritems (d ) if k in keys ])
1424
1424
1425
1425
1426
+ def report_memory (i = 0 ): # argument may go away
1427
+ 'return the memory consumed by process'
1428
+ from matplotlib .compat .subprocess import Popen , PIPE
1429
+ pid = os .getpid ()
1430
+ if sys .platform == 'sunos5' :
1431
+ try :
1432
+ a2 = Popen ('ps -p %d -o osz' % pid , shell = True ,
1433
+ stdout = PIPE ).stdout .readlines ()
1434
+ except OSError :
1435
+ raise NotImplementedError (
1436
+ "report_memory works on Sun OS only if "
1437
+ "the 'ps' program is found" )
1438
+ mem = int (a2 [- 1 ].strip ())
1439
+ elif sys .platform .startswith ('linux' ):
1440
+ try :
1441
+ a2 = Popen ('ps -p %d -o rss,sz' % pid , shell = True ,
1442
+ stdout = PIPE ).stdout .readlines ()
1443
+ except OSError :
1444
+ raise NotImplementedError (
1445
+ "report_memory works on Linux only if "
1446
+ "the 'ps' program is found" )
1447
+ mem = int (a2 [1 ].split ()[1 ])
1448
+ elif sys .platform .startswith ('darwin' ):
1449
+ try :
1450
+ a2 = Popen ('ps -p %d -o rss,vsz' % pid , shell = True ,
1451
+ stdout = PIPE ).stdout .readlines ()
1452
+ except OSError :
1453
+ raise NotImplementedError (
1454
+ "report_memory works on Mac OS only if "
1455
+ "the 'ps' program is found" )
1456
+ mem = int (a2 [1 ].split ()[0 ])
1457
+ elif sys .platform .startswith ('win' ):
1458
+ try :
1459
+ a2 = Popen (["tasklist" , "/nh" , "/fi" , "pid eq %d" % pid ],
1460
+ stdout = PIPE ).stdout .read ()
1461
+ except OSError :
1462
+ raise NotImplementedError (
1463
+ "report_memory works on Windows only if "
1464
+ "the 'tasklist' program is found" )
1465
+ mem = int (a2 .strip ().split ()[- 2 ].replace (',' , '' ))
1466
+ else :
1467
+ raise NotImplementedError (
1468
+ "We don't have a memory monitor for %s" % sys .platform )
1469
+ return mem
1470
+
1471
+
1426
1472
_safezip_msg = 'In safezip, len(args[0])=%d but len(args[%d])=%d'
1427
1473
1428
1474
0 commit comments