Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3dbd343

Browse filesBrowse files
committed
Restore cbook.report_memory, which was deleted in d063dee.
There was no deprecation process, and having something like this available as an import is very valuable to users suspecting a memory leak, or simply needing to track memory usage.
1 parent 9f0d770 commit 3dbd343
Copy full SHA for 3dbd343

File tree

Expand file treeCollapse file tree

1 file changed

+46
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+46
-0
lines changed

‎lib/matplotlib/cbook.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook.py
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,52 @@ def restrict_dict(d, keys):
14231423
return dict([(k, v) for (k, v) in six.iteritems(d) if k in keys])
14241424

14251425

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+
14261472
_safezip_msg = 'In safezip, len(args[0])=%d but len(args[%d])=%d'
14271473

14281474

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.