Created
February 11, 2019 15:36
-
-
Save holly/2580a662c2eb66e8988b3c731b15d222 to your computer and use it in GitHub Desktop.
read /proc/$pid/smaps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
def read_smaps(pidlist): | |
try: | |
print("PID\tRSS\tSHARED\t\tNONE_SHARED") | |
mem = lambda t, f: int(f[1]) if f[0] == '%s:' % t else 0.0 | |
for pid in pidlist: | |
filename = "/proc/%s/smaps" % pid | |
with open(filename) as f: | |
rss = 0.0 | |
shared = 0.0 | |
for line in f: | |
fields = line.split() | |
rss += mem('Rss', fields) | |
shared += mem('Shared_Clean', fields) | |
shared += mem('Shared_Dirty', fields) | |
print("%s\t%d\t%d (%.2f%%)\t%d" % | |
(pid, rss, shared, shared/rss*100, rss - shared)) | |
except IOError as e: | |
print(e) | |
if __name__ == '__main__': | |
if len(sys.argv) < 2: | |
print("usage: %s [pids]" % __file__) | |
sys.exit(-1) | |
read_smaps(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment