Skip to content

Commit 7895716

Browse files
authored
Merge pull request #68 from yhuang43/master
add optional 'pid' parameter to system.vmpeak()
2 parents fa990ab + f73dbff commit 7895716

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

surfa/system.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,18 @@ def hostname(short=True):
9393
return node
9494

9595

96-
def vmpeak():
96+
def vmpeak(pid=None):
9797
"""
9898
Return the peak memory usage of the process in kilobytes.
9999
100100
Note: This only works on linux machines because it requires `/proc/self/status`.
101101
"""
102102
# TODO: switch to this (portable across platforms)
103103
# return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
104-
procstatus = '/proc/self/status'
104+
if (pid is None):
105+
procstatus = '/proc/self/status'
106+
else:
107+
procstatus = os.path.join('/proc', str(pid), 'status')
105108
if os.path.exists(procstatus):
106109
with open(procstatus, 'r') as file:
107110
for line in file:

0 commit comments

Comments
 (0)