Commit 27936225 authored by Kirill Smelkov's avatar Kirill Smelkov

mapstop: Program to output /proc/pid/maps in sorted order by virtsize

Committing as-is quick & dirty program I did a while ago to investigate
process mappings. This was handy for understanding something related to
wendelin.core.
parent 43cf60c4
#!/usr/bin/env python
""" read /prod/pid/maps-like input and sort entries based on amount of
allocated address space """
import sys
# 7fdd3fe01000-7fdd40000000 ... ->
def virt_space_amount(arg):
addr_range = arg.split()[0]
addr_start, addr_stop = addr_range.split('-')
addr_start = int(addr_start, 16)
addr_stop = int(addr_stop, 16)
return addr_stop - addr_start
KB = 1024
MB = 1024*KB
GB = 1024*MB
def pretty_size(size):
if size > GB:
return '%.2fGB' % (float(size) / GB)
if size > MB:
return '%.0fMB' % (float(size) / MB)
return '%.0fKB' % (float(size) / KB)
def main():
lines = sys.stdin.readlines()
#lines.sort(key=virt_space_amount, reverse=True)
for _ in lines:
print '%8s %s' % (pretty_size(virt_space_amount(_)), _,),
if __name__ == '__main__':
main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment