| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # | |
| 3 # Copyright 2008 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 | |
| 31 # Usage: process-ticks.py <binary> <logfile> | |
| 32 # | |
| 33 # Where <binary> is the binary program name (eg, v8_shell.exe) and | |
| 34 # <logfile> is the log file name (eg, v8.log). | |
| 35 # | |
| 36 # This tick processor expects to find a map file for the binary named | |
| 37 # binary.map if the binary is named binary.exe. The tick processor | |
| 38 # only works for statically linked executables - no information about | |
| 39 # shared libraries is logged from v8 on Windows. | |
| 40 | |
| 41 import os, re, sys, tickprocessor | |
| 42 | |
| 43 class WindowsTickProcessor(tickprocessor.TickProcessor): | |
| 44 | |
| 45 def Unmangle(self, name): | |
| 46 """Performs very simple unmangling of C++ names. | |
| 47 | |
| 48 Does not handle arguments and template arguments. The mangled names have | |
| 49 the form: | |
| 50 | |
| 51 ?LookupInDescriptor@JSObject@internal@v8@@...arguments info... | |
| 52 | |
| 53 """ | |
| 54 # Name is mangled if it starts with a question mark. | |
| 55 is_mangled = re.match("^\?(.*)", name) | |
| 56 if is_mangled: | |
| 57 substrings = is_mangled.group(1).split('@') | |
| 58 try: | |
| 59 # The function name is terminated by two @s in a row. Find the | |
| 60 # substrings that are part of the function name. | |
| 61 index = substrings.index('') | |
| 62 substrings = substrings[0:index] | |
| 63 except ValueError: | |
| 64 # If we did not find two @s in a row, the mangled name is not in | |
| 65 # the format we expect and we give up. | |
| 66 return name | |
| 67 substrings.reverse() | |
| 68 function_name = "::".join(substrings) | |
| 69 return function_name | |
| 70 return name | |
| 71 | |
| 72 | |
| 73 def ParseMapFile(self, filename): | |
| 74 """Parse map file and add symbol information to the cpp entries.""" | |
| 75 # Locate map file. | |
| 76 has_dot = re.match('^([a-zA-F0-9_-]*)[\.]?.*$', filename) | |
| 77 if has_dot: | |
| 78 map_file_name = has_dot.group(1) + '.map' | |
| 79 try: | |
| 80 map_file = open(map_file_name, 'rb') | |
| 81 except IOError: | |
| 82 sys.exit("Could not open map file: " + map_file_name) | |
| 83 else: | |
| 84 sys.exit("Could not find map file for executable: " + filename) | |
| 85 try: | |
| 86 max_addr = 0 | |
| 87 min_addr = 2**30 | |
| 88 # Process map file and search for function entries. | |
| 89 row_regexp = re.compile(' 0001:[0-9a-fA-F]{8}\s*([_\?@$0-9a-zA-Z]*)\s*([0-
9a-fA-F]{8}).*') | |
| 90 for line in map_file: | |
| 91 row = re.match(row_regexp, line) | |
| 92 if row: | |
| 93 addr = int(row.group(2), 16) | |
| 94 if addr > max_addr: | |
| 95 max_addr = addr | |
| 96 if addr < min_addr: | |
| 97 min_addr = addr | |
| 98 mangled_name = row.group(1) | |
| 99 name = self.Unmangle(mangled_name) | |
| 100 self.cpp_entries.Insert(addr, tickprocessor.CodeEntry(addr, name)); | |
| 101 i = min_addr | |
| 102 # Mark the pages for which there are functions in the map file. | |
| 103 while i < max_addr: | |
| 104 page = i >> 12 | |
| 105 self.vm_extent[page] = 1 | |
| 106 i += 4096 | |
| 107 finally: | |
| 108 map_file.close() | |
| 109 | |
| 110 | |
| 111 class WindowsCmdLineProcessor(tickprocessor.CmdLineProcessor): | |
| 112 | |
| 113 def __init__(self): | |
| 114 super(WindowsCmdLineProcessor, self).__init__() | |
| 115 self.binary_file = None | |
| 116 | |
| 117 def GetRequiredArgsNames(self): | |
| 118 return 'binary log_file' | |
| 119 | |
| 120 def ProcessRequiredArgs(self, args): | |
| 121 if len(args) != 2: | |
| 122 self.PrintUsageAndExit() | |
| 123 else: | |
| 124 self.binary_file = args[0] | |
| 125 self.log_file = args[1] | |
| 126 | |
| 127 | |
| 128 def Main(): | |
| 129 cmdline_processor = WindowsCmdLineProcessor() | |
| 130 cmdline_processor.ProcessArguments() | |
| 131 tickprocessor = WindowsTickProcessor() | |
| 132 tickprocessor.ParseMapFile(cmdline_processor.binary_file) | |
| 133 cmdline_processor.RunLogfileProcessing(tickprocessor) | |
| 134 tickprocessor.PrintResults() | |
| 135 | |
| 136 if __name__ == '__main__': | |
| 137 Main() | |
| OLD | NEW |