OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # | |
Michael Achenbach
2016/04/26 12:16:10
nit: Use short copyright header for new files.
lpy
2016/04/26 17:57:58
Done.
| |
3 # Copyright 2016 the V8 project authors. All rights reserved. | |
4 # Redistribution and use in source and binary forms, with or without | |
5 # modification, are permitted provided that the following conditions are | |
6 # met: | |
7 # | |
8 # * Redistributions of source code must retain the above copyright | |
9 # notice, this list of conditions and the following disclaimer. | |
10 # * Redistributions in binary form must reproduce the above | |
11 # copyright notice, this list of conditions and the following | |
12 # disclaimer in the documentation and/or other materials provided | |
13 # with the distribution. | |
14 # * Neither the name of Google Inc. nor the names of its | |
15 # contributors may be used to endorse or promote products derived | |
16 # from this software without specific prior written permission. | |
17 # | |
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 | |
30 # This script executes dumpcpp.js, collects all dumped C++ symbols, | |
31 # and merges them back into v8 log. | |
32 | |
33 import os | |
34 import platform | |
35 import re | |
36 import subprocess | |
37 import sys | |
38 | |
39 def isFileExecutable(fPath): | |
Michael Achenbach
2016/04/26 12:16:10
nit: I prefer consistent underscore method names,
lpy
2016/04/26 17:57:58
Done.
| |
40 return os.path.isfile(fPath) and os.access(fPath, os.X_OK) | |
41 | |
42 if __name__ == '__main__': | |
43 JS_FILES = ['splaytree.js', 'codemap.js', 'csvparser.js', 'consarray.js', | |
44 'profile.js', 'logreader.js', 'tickprocessor.js', 'SourceMap.js', | |
45 'dumpcpp.js'] | |
46 tools_path = os.path.dirname(os.path.realpath(__file__)) | |
47 on_windows = True if platform.system() == 'Windows' else False | |
Michael Achenbach
2016/04/26 12:16:10
on_windows = platform.system() == 'Windows'
lpy
2016/04/26 17:57:58
Done.
| |
48 for i in range(0, len(JS_FILES)): | |
Michael Achenbach
2016/04/26 12:16:10
Readability:
JS_FILES = [os.path.join(tools_path,
lpy
2016/04/26 17:57:58
Done.
| |
49 JS_FILES[i] = os.path.join(tools_path, JS_FILES[i]) | |
50 | |
51 args = [] | |
52 log_file = 'v8.log' | |
53 debug = False | |
54 for i in range(1, len(sys.argv)): | |
Michael Achenbach
2016/04/26 12:16:10
Readability:
for arg in sys.argv[1:]:
# s/sys.ar
lpy
2016/04/26 17:57:58
Done.
| |
55 if sys.argv[i] == '--debug': | |
56 debug = True | |
57 continue | |
58 args.append(sys.argv[i]) | |
59 if not sys.argv[i].startswith('-'): | |
60 log_file = sys.argv[i] | |
61 | |
62 if on_windows: | |
63 args.append('--windows') | |
64 | |
65 with open(log_file, 'r') as f: | |
66 lines = f.readlines() | |
67 | |
68 d8_line = re.search(',\"(.*d8)', ''.join(lines)) | |
69 if d8_line: | |
70 d8_exec = d8_line.groups()[0] | |
Michael Achenbach
2016/04/26 12:16:10
d8_exec = d8_line.groups()[0]
equivalent to
d8_exe
lpy
2016/04/26 17:57:58
Done.
| |
71 else: | |
72 print 'No d8 binary path found in {}.'.format(log_file) | |
73 exit(-1) | |
Michael Achenbach
2016/04/26 12:16:10
Rather sys.exit(-1) in scripts I guess.
lpy
2016/04/26 17:57:58
Done.
| |
74 | |
75 args = [d8_exec] + JS_FILES + ['--'] + args | |
76 | |
77 with open(log_file) as f: | |
Michael Achenbach
2016/04/26 12:16:10
I'm not familiar with this pattern. Will it keep t
lpy
2016/04/26 17:57:58
Sorry, I should put sp.communicate() in the clause
| |
78 sp = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=f) | |
79 out, err = sp.communicate() | |
80 if debug: | |
81 print err | |
82 if sp.returncode != 0: | |
83 print out | |
84 exit(-1) | |
85 | |
86 if on_windows and out: | |
87 out = re.sub('\r+\n', '\n', out) | |
88 | |
89 is_written = False if out else True | |
Michael Achenbach
2016/04/26 12:16:10
Readability:
is_written = not out
or if you prefe
lpy
2016/04/26 17:57:58
Done.
| |
90 with open(log_file, 'w+') as f: | |
Michael Achenbach
2016/04/26 12:16:10
How about just w as you only write to the file?
lpy
2016/04/26 17:57:58
Done.
| |
91 for line in lines: | |
92 if not is_written and line.startswith('tick'): | |
93 f.write(out) | |
Michael Achenbach
2016/04/26 12:16:10
So you append all symbols right after the first ti
lpy
2016/04/26 17:57:58
Yes.
| |
94 is_written = True | |
95 f.write(line) | |
OLD | NEW |