Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 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 | # Usage: process-ticks.py <logfile> |
| 31 | # Where <logfile> is the log file name (eg, v8.log). |
| 32 | |
| 33 | import subprocess, re, sys, tickprocessor |
| 34 | |
| 35 | class LinuxTickProcessor(tickprocessor.TickProcessor): |
| 36 | |
| 37 | def ParseVMSymbols(self, filename, start, end): |
| 38 | """Extract symbols and add them to the cpp entries.""" |
| 39 | # Extra both dynamic and non-dynamic symbols. |
| 40 | command = 'nm -C -n "%s"; nm -C -n -D "%s"' % (filename, filename) |
| 41 | process = subprocess.Popen(command, shell=True, |
| 42 | stdout=subprocess.PIPE, |
| 43 | stderr=subprocess.STDOUT) |
| 44 | pipe = process.stdout |
| 45 | try: |
| 46 | for line in pipe: |
| 47 | row = re.match('^([0-9a-fA-F]{8}) . (.*)$', line) |
| 48 | if row: |
| 49 | addr = int(row.group(1), 16) |
| 50 | if addr < start and addr < end - start: |
| 51 | addr += start |
| 52 | self.cpp_entries.Insert(addr, tickprocessor.CodeEntry(addr, row.group(2))) |
| 53 | finally: |
| 54 | pipe.close() |
| 55 | |
| 56 | |
| 57 | class LinuxCmdLineProcessor(tickprocessor.CmdLineProcessor): |
| 58 | |
| 59 | def GetRequiredArgsNames(self): |
| 60 | return 'log_file' |
| 61 | |
| 62 | def ProcessRequiredArgs(self, args): |
| 63 | if len(args) != 1: |
| 64 | self.PrintUsageAndExit() |
| 65 | else: |
| 66 | self.log_file = args[0] |
| 67 | |
| 68 | |
| 69 | def Main(): |
| 70 | cmdline_processor = LinuxCmdLineProcessor() |
| 71 | cmdline_processor.ProcessArguments() |
| 72 | tick_processor = LinuxTickProcessor() |
| 73 | cmdline_processor.RunLogfileProcessing(tick_processor) |
| 74 | tick_processor.PrintResults() |
| 75 | |
| 76 | |
| 77 | if __name__ == '__main__': |
| 78 | Main() |