Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 457fd94

Browse files
committed
Fix units as reported by report_memory
1 parent 7444a98 commit 457fd94

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

lib/matplotlib/cbook.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,27 +1439,18 @@ def restrict_dict(d, keys):
14391439

14401440

14411441
def report_memory(i=0): # argument may go away
1442-
'return the memory consumed by process'
1442+
'return the memory, in bytes, consumed by process'
14431443
from matplotlib.compat.subprocess import Popen, PIPE
14441444
pid = os.getpid()
1445-
if sys.platform == 'sunos5':
1446-
try:
1447-
a2 = Popen('ps -p %d -o osz' % pid, shell=True,
1448-
stdout=PIPE).stdout.readlines()
1449-
except OSError:
1450-
raise NotImplementedError(
1451-
"report_memory works on Sun OS only if "
1452-
"the 'ps' program is found")
1453-
mem = int(a2[-1].strip())
1454-
elif sys.platform.startswith('linux'):
1445+
if sys.platform.startswith('linux'):
14551446
try:
14561447
a2 = Popen('ps -p %d -o rss,sz' % pid, shell=True,
14571448
stdout=PIPE).stdout.readlines()
14581449
except OSError:
14591450
raise NotImplementedError(
14601451
"report_memory works on Linux only if "
14611452
"the 'ps' program is found")
1462-
mem = int(a2[1].split()[1])
1453+
mem = int(a2[1].split()[1]) * 1024
14631454
elif sys.platform.startswith('darwin'):
14641455
try:
14651456
a2 = Popen('ps -p %d -o rss,vsz' % pid, shell=True,
@@ -1468,7 +1459,7 @@ def report_memory(i=0): # argument may go away
14681459
raise NotImplementedError(
14691460
"report_memory works on Mac OS only if "
14701461
"the 'ps' program is found")
1471-
mem = int(a2[1].split()[0])
1462+
mem = int(a2[1].split()[0]) * 1024
14721463
elif sys.platform.startswith('win'):
14731464
try:
14741465
a2 = Popen(["tasklist", "/nh", "/fi", "pid eq %d" % pid],
@@ -1477,7 +1468,7 @@ def report_memory(i=0): # argument may go away
14771468
raise NotImplementedError(
14781469
"report_memory works on Windows only if "
14791470
"the 'tasklist' program is found")
1480-
mem = int(a2.strip().split()[-2].replace(',', ''))
1471+
mem = int(a2.strip().split()[-2].replace(',', '')) * 1024
14811472
else:
14821473
raise NotImplementedError(
14831474
"We don't have a memory monitor for %s" % sys.platform)

0 commit comments

Comments
 (0)