Index: tools/dump-cpp.py |
diff --git a/tools/dump-cpp.py b/tools/dump-cpp.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9a17d9ef28e7fe985e83920b30149eaf0b7a1540 |
--- /dev/null |
+++ b/tools/dump-cpp.py |
@@ -0,0 +1,95 @@ |
+#!/usr/bin/env python |
+# |
Michael Achenbach
2016/04/26 12:16:10
nit: Use short copyright header for new files.
lpy
2016/04/26 17:57:58
Done.
|
+# Copyright 2016 the V8 project authors. All rights reserved. |
+# Redistribution and use in source and binary forms, with or without |
+# modification, are permitted provided that the following conditions are |
+# met: |
+# |
+# * Redistributions of source code must retain the above copyright |
+# notice, this list of conditions and the following disclaimer. |
+# * Redistributions in binary form must reproduce the above |
+# copyright notice, this list of conditions and the following |
+# disclaimer in the documentation and/or other materials provided |
+# with the distribution. |
+# * Neither the name of Google Inc. nor the names of its |
+# contributors may be used to endorse or promote products derived |
+# from this software without specific prior written permission. |
+# |
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ |
+# This script executes dumpcpp.js, collects all dumped C++ symbols, |
+# and merges them back into v8 log. |
+ |
+import os |
+import platform |
+import re |
+import subprocess |
+import sys |
+ |
+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.
|
+ return os.path.isfile(fPath) and os.access(fPath, os.X_OK) |
+ |
+if __name__ == '__main__': |
+ JS_FILES = ['splaytree.js', 'codemap.js', 'csvparser.js', 'consarray.js', |
+ 'profile.js', 'logreader.js', 'tickprocessor.js', 'SourceMap.js', |
+ 'dumpcpp.js'] |
+ tools_path = os.path.dirname(os.path.realpath(__file__)) |
+ 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.
|
+ 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.
|
+ JS_FILES[i] = os.path.join(tools_path, JS_FILES[i]) |
+ |
+ args = [] |
+ log_file = 'v8.log' |
+ debug = False |
+ 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.
|
+ if sys.argv[i] == '--debug': |
+ debug = True |
+ continue |
+ args.append(sys.argv[i]) |
+ if not sys.argv[i].startswith('-'): |
+ log_file = sys.argv[i] |
+ |
+ if on_windows: |
+ args.append('--windows') |
+ |
+ with open(log_file, 'r') as f: |
+ lines = f.readlines() |
+ |
+ d8_line = re.search(',\"(.*d8)', ''.join(lines)) |
+ if d8_line: |
+ 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.
|
+ else: |
+ print 'No d8 binary path found in {}.'.format(log_file) |
+ 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.
|
+ |
+ args = [d8_exec] + JS_FILES + ['--'] + args |
+ |
+ 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
|
+ sp = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=f) |
+ out, err = sp.communicate() |
+ if debug: |
+ print err |
+ if sp.returncode != 0: |
+ print out |
+ exit(-1) |
+ |
+ if on_windows and out: |
+ out = re.sub('\r+\n', '\n', out) |
+ |
+ 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.
|
+ 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.
|
+ for line in lines: |
+ if not is_written and line.startswith('tick'): |
+ 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.
|
+ is_written = True |
+ f.write(line) |