Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: tools/cygprofile/patch_orderfile.py

Issue 799893003: Fix pylint error in patch_orderfile and symbolize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use super instead of Exception Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/cygprofile/symbolize.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import commands 6 import commands
7 import os 7 import os
8 import sys 8 import sys
9 9
10 orderfile = sys.argv[1] 10 orderfile = sys.argv[1]
(...skipping 20 matching lines...) Expand all
31 nm_index = nm_index + 1 31 nm_index = nm_index + 1
32 while nm_index < len(nmlines) and nm_int == int ( 32 while nm_index < len(nmlines) and nm_int == int (
33 nmlines[nm_index].split()[0], 16): 33 nmlines[nm_index].split()[0], 16):
34 fnames.append(nmlines[nm_index].split()[3]) 34 fnames.append(nmlines[nm_index].split()[3])
35 nm_index = nm_index + 1 35 nm_index = nm_index + 1
36 addressMap[nm_int] = fnames 36 addressMap[nm_int] = fnames
37 uniqueAddrs.append((nm_int, size)) 37 uniqueAddrs.append((nm_int, size))
38 else: 38 else:
39 nm_index = nm_index + 1 39 nm_index = nm_index + 1
40 40
41 def binary_search (addr, start, end): 41 def binary_search (search_addr, start, end):
42 if start >= end or start == end - 1: 42 if start >= end or start == end - 1:
43 (nm_addr, size) = uniqueAddrs[start] 43 (nm_addr, sym_size) = uniqueAddrs[start]
44 if not (addr >= nm_addr and addr < nm_addr + size): 44 if not (search_addr >= nm_addr and search_addr < nm_addr + sym_size):
45 sys.stderr.write ("ERROR: did not find function in binary: addr: " + 45 error_message = ('ERROR: did not find function in binary: addr: ' +
46 hex(addr) + " nm_addr: " + str(nm_addr) + " start: " + str(start) + 46 hex(addr) + ' nm_addr: ' + str(nm_addr) + ' start: ' +
47 " end: " + str(end) + "\n") 47 str(start) + ' end: ' + str(end))
48 raise Error("error") 48 sys.stderr.write(error_message + "\n")
49 return (addressMap[nm_addr], size) 49 raise Exception(error_message)
50 return (addressMap[nm_addr], sym_size)
50 else: 51 else:
51 halfway = start + ((end - start) / 2) 52 halfway = start + ((end - start) / 2)
52 (nm_addr, size) = uniqueAddrs[halfway] 53 nm_addr = uniqueAddrs[halfway][0]
53 if (addr >= nm_addr and addr < nm_addr + size): 54 if (addr >= nm_addr and addr < nm_addr + sym_size):
54 return (addressMap[nm_addr], size) 55 return (addressMap[nm_addr], sym_size)
55 elif (addr < nm_addr): 56 elif (addr < nm_addr):
56 return binary_search (addr, start, halfway) 57 return binary_search (addr, start, halfway)
57 elif (addr >= nm_addr + size): 58 elif (addr >= nm_addr + sym_size):
58 return binary_search (addr, halfway, end) 59 return binary_search (addr, halfway, end)
59 else: 60 else:
60 raise "ERROR: did not expect this case" 61 raise Exception("ERROR: did not expect this case")
61 62
62 f = open (orderfile) 63 f = open (orderfile)
63 lines = f.readlines() 64 lines = f.readlines()
64 profiled_list = [] 65 profiled_list = []
65 for line in lines: 66 for line in lines:
66 if (line.strip() == ''): 67 if (line.strip() == ''):
67 continue 68 continue
68 functionName = line.replace('.text.', '').split('.clone.')[0].strip() 69 functionName = line.replace('.text.', '').split('.clone.')[0].strip()
69 profiled_list.append (functionName) 70 profiled_list.append (functionName)
70 71
71 # Symbol names are not unique. Since the order file uses symbol names, the 72 # Symbol names are not unique. Since the order file uses symbol names, the
72 # patched order file pulls in all symbols with the same name. Multiple function 73 # patched order file pulls in all symbols with the same name. Multiple function
73 # addresses for the same function name may also be due to ".clone" symbols, 74 # addresses for the same function name may also be due to ".clone" symbols,
74 # since the substring is stripped. 75 # since the substring is stripped.
75 functions = [] 76 functions = []
76 functionAddressMap = {} 77 functionAddressMap = {}
77 for line in nmlines: 78 for line in nmlines:
78 try: 79 try:
79 functionName = line.split()[3] 80 functionName = line.split()[3]
80 except: 81 except Exception:
81 functionName = line.split()[2] 82 functionName = line.split()[2]
82 functionName = functionName.split('.clone.')[0] 83 functionName = functionName.split('.clone.')[0]
83 functionAddress = int (line.split()[0].strip(), 16) 84 functionAddress = int (line.split()[0].strip(), 16)
84 try: 85 try:
85 functionAddressMap[functionName].append(functionAddress) 86 functionAddressMap[functionName].append(functionAddress)
86 except: 87 except Exception:
87 functionAddressMap[functionName] = [functionAddress] 88 functionAddressMap[functionName] = [functionAddress]
88 functions.append(functionName) 89 functions.append(functionName)
89 90
90 sys.stderr.write ("profiled list size: " + str(len(profiled_list)) + "\n") 91 sys.stderr.write ("profiled list size: " + str(len(profiled_list)) + "\n")
91 addresses = [] 92 addresses = []
92 symbols_found = 0 93 symbols_found = 0
93 for function in profiled_list: 94 for function in profiled_list:
94 try: 95 try:
95 addrs = functionAddressMap[function] 96 addrs = functionAddressMap[function]
96 symbols_found = symbols_found + 1 97 symbols_found = symbols_found + 1
97 except: 98 except Exception:
98 addrs = [] 99 addrs = []
99 # sys.stderr.write ("WARNING: could not find symbol " + function + "\n") 100 # sys.stderr.write ("WARNING: could not find symbol " + function + "\n")
100 for addr in addrs: 101 for addr in addrs:
101 if not (addr in addresses): 102 if not (addr in addresses):
102 addresses.append(addr) 103 addresses.append(addr)
103 sys.stderr.write ("symbols found: " + str(symbols_found) + "\n") 104 sys.stderr.write ("symbols found: " + str(symbols_found) + "\n")
104 105
105 sys.stderr.write ("number of addresses: " + str(len(addresses)) + "\n") 106 sys.stderr.write ("number of addresses: " + str(len(addresses)) + "\n")
106 total_size = 0 107 total_size = 0
107 for addr in addresses: 108 for addr in addresses:
108 (functions, size) = binary_search (addr, 0, len(uniqueAddrs)) 109 (functions, size) = binary_search (addr, 0, len(uniqueAddrs))
109 total_size = total_size + size 110 total_size = total_size + size
110 prefixes = ['.text.', '.text.startup.', '.text.hot.', '.text.unlikely.'] 111 prefixes = ['.text.', '.text.startup.', '.text.hot.', '.text.unlikely.']
111 for function in functions: 112 for function in functions:
112 for prefix in prefixes: 113 for prefix in prefixes:
113 print prefix + function 114 print prefix + function
114 115
115 # The following is needed otherwise Gold only applies a partial sort. 116 # The following is needed otherwise Gold only applies a partial sort.
116 print '.text.*' 117 print '.text.*'
117 sys.stderr.write ("total_size: " + str(total_size) + "\n") 118 sys.stderr.write ("total_size: " + str(total_size) + "\n")
OLDNEW
« no previous file with comments | « no previous file | tools/cygprofile/symbolize.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698