Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
解析 /proc/pid/maps 文件的脚本
data_list = []
while (True):
raw_data = input('paste maps string here: ' if len(data_list) == 0 else '')
if (raw_data.strip() == ''):
break
data_list.append(raw_data)
#print('====')
#print(data_list)
#print('====')
mem_map = {}
for item in data_list:
tmp = item.split(' ')
#print(tmp)
addr = tmp[0].split('-')
if len(addr) == 2:
# print(addr[0], addr[1], tmp[-1][-20:])
mem = (int(addr[1], 16) - int(addr[0], 16)) / 1024.0 / 1024.0
#print(mem, tmp[-1][-30:])
key = tmp[-1][-30:]
if key in mem_map:
mem_map[key].append(mem)
else:
li = []
li.append(mem)
mem_map[key] = li
else:
pass
for (k, v) in mem_map.items():
print(k, ' ', sum(v), 'MB')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment