-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_v8_wasm_profile.py
57 lines (46 loc) · 1.55 KB
/
update_v8_wasm_profile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
import sys
import re
import os
def main(cpuprofile_file, symbol_file):
print('start parse symbol')
symbol_map = {}
with open(symbol_file) as f:
symbol_text = f.read()
result = re.findall(r"(\d+):'(.*)'", symbol_text)
for p in result:
symbol_map['wasm-function['+str(p[0])+']'] = p[1]
parts = os.path.splitext(cpuprofile_file)
out_file = parts[0] + '_out' + parts[1]
total = len(symbol_map)
print('start replace, symbol count {0}'.format(total))
count = 0
all_md5s = []
with open(cpuprofile_file) as f:
profile_text = f.read()
for k, v in symbol_map.items():
count += 1
strip_name = []
for p in v.split('_'):
if len(p) != 41:
strip_name.append(p)
else:
all_md5s.append(p)
profile_text = profile_text.replace(k, '_'.join(strip_name))
if count % 1000 == 0:
print('symbol {0}/{1}'.format(count, total))
print('remove md5 count {0}'.format(len(all_md5s)))
count = 0
for m in all_md5s:
count += 1
profile_text = profile_text.replace(m, '')
if count % 1000 == 0:
print('md5 {0}/{1}'.format(count, total))
with open(out_file, 'w') as f:
f.write(profile_text)
print('done')
if __name__ == '__main__':
if len(sys.argv) != 3:
print('usage: python update_v8_wasm_profile.py xxx.cpuprofile xxx.symbols')
else:
main(sys.argv[1], sys.argv[2])