OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2016 the V8 project authors. All rights reserved. | 3 # Copyright 2016 the V8 project authors. All rights reserved. |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
11 # copyright notice, this list of conditions and the following | 11 # copyright notice, this list of conditions and the following |
12 # disclaimer in the documentation and/or other materials provided | 12 # disclaimer in the documentation and/or other materials provided |
13 # with the distribution. | 13 # with the distribution. |
14 # * Neither the name of Google Inc. nor the names of its | 14 # * Neither the name of Google Inc. nor the names of its |
15 # contributors may be used to endorse or promote products derived | 15 # contributors may be used to endorse or promote products derived |
16 # from this software without specific prior written permission. | 16 # from this software without specific prior written permission. |
17 # | 17 # |
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 import os.path | |
30 import re | 31 import re |
31 import subprocess | 32 import subprocess |
32 import sys | 33 import sys |
33 | 34 |
34 | 35 |
35 def get_address_bounds(): | 36 def get_address_bounds(): |
36 start = -1 | 37 start = -1 |
37 end = -1 | 38 end = -1 |
38 for arg in sys.argv: | 39 for arg in sys.argv: |
39 if arg.startswith("--start-address="): | 40 if arg.startswith("--start-address="): |
40 start = int(arg[-12:], 16) | 41 start = int(arg[-12:], 16) |
41 if arg.startswith("--stop-address="): | 42 if arg.startswith("--stop-address="): |
42 end = int(arg[-12:], 16) | 43 end = int(arg[-12:], 16) |
43 return start, end | 44 return start, end |
44 | 45 |
45 | 46 |
46 def format_line(line): | 47 def format_line(line): |
47 pieces = line.split(None, 3) | 48 pieces = line.split(None, 3) |
48 return " " + pieces[0][2:] + ":\t" + pieces[3] | 49 return " " + pieces[0][2:] + ":\t" + pieces[3] |
49 | 50 |
50 | 51 |
51 def is_comment(line): | 52 def is_comment(line): |
52 stripped = line.strip() | 53 stripped = line.strip() |
53 return stripped.startswith("--") or stripped.startswith(";;;") | 54 return stripped.startswith("--") or stripped.startswith(";;") |
54 | 55 |
55 def main(): | 56 def main(): |
56 filename = sys.argv[-1] | 57 filename = sys.argv[-1] |
57 match = re.match(r"/tmp/perf-(.*)\.map", filename) | 58 match = re.match(r"/tmp/perf-(.*)\.map", filename) |
58 if match: | 59 if match: |
59 start, end = get_address_bounds() | 60 start, end = get_address_bounds() |
60 codefile = "code-" + match.group(1) + "-1.asm" | 61 if os.path.exists("code.asm"): |
61 with open(codefile, "r") as code: | 62 codefile = open("code.asm", "r") |
Benedikt Meurer
2016/07/21 17:28:26
I think you should prefer the code-<pid>-<isolate
| |
63 else: | |
64 codefile = open("code-" + match.group(1) + "-1.asm", "r") | |
65 with codefile: | |
62 printing = False | 66 printing = False |
63 for line in code: | 67 for line in codefile: |
64 if line.startswith("0x"): | 68 if line.startswith("0x"): |
65 addr = int(line.split()[0], 0) | 69 addr = int(line.split()[0], 0) |
66 if start <= addr <= end: | 70 if start <= addr <= end: |
67 printing = True | 71 printing = True |
68 sys.stdout.write(format_line(line)) | 72 sys.stdout.write(format_line(line)) |
69 elif printing: | 73 elif printing: |
70 break | 74 break |
71 elif printing and not is_comment(line): | 75 elif printing and not is_comment(line): |
72 break | 76 break |
73 else: | 77 else: |
74 sys.argv[0] = "objdump" | 78 sys.argv[0] = "objdump" |
75 sys.exit(subprocess.call(sys.argv)) | 79 sys.exit(subprocess.call(sys.argv)) |
76 | 80 |
77 if __name__ == "__main__": | 81 if __name__ == "__main__": |
78 main() | 82 main() |
OLD | NEW |