Created
July 22, 2021 14:06
-
-
Save heiner/fb9e9a9db7ae17263461671f61d3978d to your computer and use it in GitHub Desktop.
This file contains 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
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