Skip to content

Instantly share code, notes, and snippets.

@heiner
Created July 22, 2021 14:06
Show Gist options
  • Save heiner/fb9e9a9db7ae17263461671f61d3978d to your computer and use it in GitHub Desktop.
Save heiner/fb9e9a9db7ae17263461671f61d3978d to your computer and use it in GitHub Desktop.
import collections
import sys
import pprint
class Entry:
pass
def load_file(filename):
entries = {}
with open(filename) as smaps:
entry = None
for line in smaps:
if len(line) >= 32:
if entry is not None:
entries[entry.name] = entry
entry = Entry()
elements = line.split()
entry.name = elements[-1].strip()
entry.header = line.strip()
entry.values = {}
else:
key, value = line.split(":", 2)
entry.values[key] = value.strip()
return entries
def map_entries(entries):
result = {}
for name, e in entries.items():
rss = int(e.values["Rss"].strip(" kB"))
result[name] = rss
return result
def main():
entries = {}
for filename in sys.argv[1:]:
old_entries = entries
entries = load_file(filename)
rsses = sorted(map_entries(entries).items(), key=lambda t: t[1], reverse=True)
print(filename, ":", len(rsses), "entries, top 5:", rsses[:5])
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment