OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2016 the V8 project authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 # This script executes dumpcpp.js, collects all dumped C++ symbols, | |
7 # and merges them back into v8 log. | |
8 | |
9 import os | |
10 import platform | |
11 import re | |
12 import subprocess | |
13 import sys | |
14 | |
15 def is_file_executable(fPath): | |
16 return os.path.isfile(fPath) and os.access(fPath, os.X_OK) | |
17 | |
18 if __name__ == '__main__': | |
19 JS_FILES = ['splaytree.js', 'codemap.js', 'csvparser.js', 'consarray.js', | |
20 'profile.js', 'logreader.js', 'tickprocessor.js', 'SourceMap.js', | |
21 'dumpcpp.js'] | |
22 tools_path = os.path.dirname(os.path.realpath(__file__)) | |
23 on_windows = platform.system() == 'Windows' | |
24 JS_FILES = [os.path.join(tools_path, f) for f in JS_FILES] | |
25 | |
26 args = [] | |
27 log_file = 'v8.log' | |
28 debug = False | |
29 for arg in sys.argv[1:]: | |
30 if arg == '--debug': | |
31 debug = True | |
32 continue | |
33 args.append(arg) | |
34 if not arg.startswith('-'): | |
35 log_file = arg | |
36 | |
37 if on_windows: | |
38 args.append('--windows') | |
39 | |
40 with open(log_file, 'r') as f: | |
41 lines = f.readlines() | |
42 | |
43 d8_line = re.search(',\"(.*d8)', ''.join(lines)) | |
44 if d8_line: | |
45 d8_exec = d8_line.group(1) | |
46 if not is_file_executable(d8_exec): | |
47 print 'd8 binary path found in {} is not executable.'.format(log_file) | |
48 sys.exit(-1) | |
49 else: | |
50 print 'No d8 binary path found in {}.'.format(log_file) | |
51 sys.exit(-1) | |
52 | |
53 args = [d8_exec] + JS_FILES + ['--'] + args | |
54 | |
55 with open(log_file) as f: | |
56 sp = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=f) | |
Yang
2016/04/28 05:15:12
Can we maintain the 80-char limit here? Thanks.
lpy
2016/04/28 05:24:38
Done.
| |
57 out, err = sp.communicate() | |
58 if debug: | |
59 print err | |
60 if sp.returncode != 0: | |
61 print out | |
62 exit(-1) | |
63 | |
64 if on_windows and out: | |
65 out = re.sub('\r+\n', '\n', out) | |
66 | |
67 is_written = not bool(out) | |
68 with open(log_file, 'w') as f: | |
69 for line in lines: | |
70 if not is_written and line.startswith('tick'): | |
71 f.write(out) | |
72 is_written = True | |
73 f.write(line) | |
OLD | NEW |