blob: dc5088b5db676696f335cd20becebbc5444ac009 [file] [log] [blame]
#!/usr/bin/env python
# Based on ps_mem.py:
# Licence: LGPLv2
# Author: P@draigBrady.com
# Source: http://www.pixelbeat.org/scripts/ps_mem.py
# http://github.com/pixelb/scripts/commits/master/scripts/ps_mem.py
# Note shared is always a subset of rss (trs is not always)
def get_mem_stats(pid):
""" Return memory data of pid in format (private, shared) """
fname = '/proc/{0}/{1}'.format(pid, "smaps")
lines = open(fname).readlines()
shared = 0
private = 0
pss = 0
# add 0.5KiB as this avg error due to trunctation
pss_adjust = 0.5
for line in lines:
if line.startswith("Shared"):
shared += int(line.split()[1])
if line.startswith("Private"):
private += int(line.split()[1])
if line.startswith("Pss"):
pss += float(line.split()[1]) + pss_adjust
# Note Shared + Private = Rss above
# The Rss in smaps includes video card mem etc.
if pss != 0:
shared = int(pss - private)
return (private, shared)