Created
July 17, 2020 08:46
-
-
Save 410063005/eb8d405d1605e9990620c9f4135762b2 to your computer and use it in GitHub Desktop.
解析 /proc/pid/maps 文件的脚本
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
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