OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Symbolize log file produced by cypgofile instrumentation. | 6 """Symbolize log file produced by cypgofile instrumentation. |
7 | 7 |
8 Given a log file and the binary being profiled (e.g. executable, shared | 8 Given a log file and the binary being profiled (e.g. executable, shared |
9 library), the script can produce three different outputs: 1) symbols for the | 9 library), the script can produce three different outputs: 1) symbols for the |
10 addresses, 2) function and line numbers for the addresses, or 3) an order file. | 10 addresses, 2) function and line numbers for the addresses, or 3) an order file. |
11 """ | 11 """ |
12 | 12 |
13 import optparse | 13 import optparse |
14 import os | 14 import os |
15 import string | 15 import string |
16 import subprocess | 16 import subprocess |
17 import sys | 17 import sys |
18 | 18 |
19 | 19 |
20 def ParseLogLines(log_file_lines): | 20 def ParseLogLines(log_file_lines): |
21 """Parse a log file produced by the profiled run of clank. | 21 """Parse a log file produced by the profiled run of clank. |
22 | 22 |
23 Args: | 23 Args: |
24 log_file_lines: array of lines in log file produced by profiled run | 24 log_file_lines: array of lines in log file produced by profiled run |
25 lib_name: library or executable containing symbols | 25 lib_name: library or executable containing symbols |
26 | 26 |
27 Below is an example of a small log file: | 27 Below is an example of a small log file: |
28 5086e000-52e92000 r-xp 00000000 b3:02 51276 libchromeview.so | 28 5086e000-52e92000 r-xp 00000000 b3:02 51276 libchromeview.so |
29 secs msecs pid:threadid func | 29 secs usecs pid:threadid func |
30 START | 30 START |
31 1314897086 795828 3587:1074648168 0x509e105c | 31 1314897086 795828 3587:1074648168 0x509e105c |
32 1314897086 795874 3587:1074648168 0x509e0eb4 | 32 1314897086 795874 3587:1074648168 0x509e0eb4 |
33 1314897086 796326 3587:1074648168 0x509e0e3c | 33 1314897086 796326 3587:1074648168 0x509e0e3c |
34 1314897086 796552 3587:1074648168 0x509e07bc | 34 1314897086 796552 3587:1074648168 0x509e07bc |
35 END | 35 END |
36 | 36 |
37 Returns: | 37 Returns: |
38 call_info list with list of tuples of the format (sec, msec, call id, | 38 call_info list with list of tuples of the format (sec, usec, call id, |
39 function address called) | 39 function address called) |
40 """ | 40 """ |
41 call_lines = [] | 41 call_lines = [] |
42 has_started = False | 42 has_started = False |
43 vm_start = 0 | 43 vm_start = 0 |
44 line = log_file_lines[0] | 44 line = log_file_lines[0] |
45 assert("r-xp" in line) | 45 assert("r-xp" in line) |
46 end_index = line.find('-') | 46 end_index = line.find('-') |
47 vm_start = int(line[:end_index], 16) | 47 vm_start = int(line[:end_index], 16) |
48 for line in log_file_lines[2:]: | 48 for line in log_file_lines[2:]: |
49 # print hex(vm_start) | 49 # print hex(vm_start) |
50 fields = line.split() | 50 fields = line.split() |
51 if len(fields) == 4: | 51 if len(fields) == 4: |
52 call_lines.append(fields) | 52 call_lines.append(fields) |
53 | 53 |
54 # Convert strings to int in fields. | 54 # Convert strings to int in fields. |
55 call_info = [] | 55 call_info = [] |
56 for call_line in call_lines: | 56 for call_line in call_lines: |
57 (sec_timestamp, msec_timestamp) = map(int, call_line[0:2]) | 57 (sec_timestamp, usec_timestamp) = map(int, call_line[0:2]) |
58 callee_id = call_line[2] | 58 callee_id = call_line[2] |
59 addr = int(call_line[3], 16) | 59 addr = int(call_line[3], 16) |
60 if vm_start < addr: | 60 if vm_start < addr: |
61 addr -= vm_start | 61 addr -= vm_start |
62 call_info.append((sec_timestamp, msec_timestamp, callee_id, addr)) | 62 call_info.append((sec_timestamp, usec_timestamp, callee_id, addr)) |
63 | 63 |
64 return call_info | 64 return call_info |
65 | 65 |
66 | 66 |
67 def ParseLibSymbols(lib_file): | 67 def ParseLibSymbols(lib_file): |
68 """Get output from running nm and greping for text symbols. | 68 """Get output from running nm and greping for text symbols. |
69 | 69 |
70 Args: | 70 Args: |
71 lib_file: the library or executable that contains the profiled code | 71 lib_file: the library or executable that contains the profiled code |
72 | 72 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 if not first_symbol: | 242 if not first_symbol: |
243 print '\t\t\t\t\t' + symbol | 243 print '\t\t\t\t\t' + symbol |
244 else: | 244 else: |
245 first_symbol = False | 245 first_symbol = False |
246 except SymbolNotFoundException as e: | 246 except SymbolNotFoundException as e: |
247 sys.stderr.write('WARNING: Did not find function in binary. addr: ' | 247 sys.stderr.write('WARNING: Did not find function in binary. addr: ' |
248 + hex(addr) + '\n') | 248 + hex(addr) + '\n') |
249 | 249 |
250 if __name__ == '__main__': | 250 if __name__ == '__main__': |
251 main() | 251 main() |
OLD | NEW |