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

Side by Side Diff: build/scripts/slave/chromium/sizes.py

Issue 9323047: Update sizes.py to print a list of all static initializers (Closed) Base URL: http://src.chromium.org/svn/trunk/tools/
Patch Set: '' Created 8 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 """A tool to extract size information for chrome, executed by buildbot. 6 """A tool to extract size information for chrome, executed by buildbot.
7 7
8 When this is run, the current directory (cwd) should be the outer build 8 When this is run, the current directory (cwd) should be the outer build
9 directory (e.g., chrome-release/build/). 9 directory (e.g., chrome-release/build/).
10 10
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 RESULT %(app_bundle)s: %(app_bundle)s= %(app_bundle_size)s bytes 118 RESULT %(app_bundle)s: %(app_bundle)s= %(app_bundle_size)s bytes
119 RESULT chrome-si: initializers= %(initializers)d files 119 RESULT chrome-si: initializers= %(initializers)d files
120 """) % ( 120 """) % (
121 print_dict) 121 print_dict)
122 # Found a match, don't check the other base_names. 122 # Found a match, don't check the other base_names.
123 return result 123 return result
124 # If no base_names matched, fail script. 124 # If no base_names matched, fail script.
125 return 66 125 return 66
126 126
127 127
128 def check_linux_binary(target_dir, binary_name): 128 def check_linux_binary(target_dir, binary_name, options):
129 """Collect appropriate size information about the built Linux binary given. 129 """Collect appropriate size information about the built Linux binary given.
130 130
131 Returns a tuple (result, sizes). result is the first non-zero exit 131 Returns a tuple (result, sizes). result is the first non-zero exit
132 status of any command it executes, or zero on success. sizes is a list 132 status of any command it executes, or zero on success. sizes is a list
133 of tuples (name, identifier, totals_identifier, value, units). 133 of tuples (name, identifier, totals_identifier, value, units).
134 The printed line looks like: 134 The printed line looks like:
135 name: identifier= value units 135 name: identifier= value units
136 When this same data is used for totals across all the binaries, then 136 When this same data is used for totals across all the binaries, then
137 totals_identifier is the identifier to use, or '' to just use identifier. 137 totals_identifier is the identifier to use, or '' to just use identifier.
138 """ 138 """
(...skipping 19 matching lines...) Expand all
158 get_size(binary_file), 'bytes')) 158 get_size(binary_file), 'bytes'))
159 159
160 result, stdout = run_process(result, ['size', binary_file]) 160 result, stdout = run_process(result, ['size', binary_file])
161 text, data, bss = re.search('(\d+)\s+(\d+)\s+(\d+)', stdout).groups() 161 text, data, bss = re.search('(\d+)\s+(\d+)\s+(\d+)', stdout).groups()
162 sizes += [ 162 sizes += [
163 (binary_name + '-text', 'text', '', text, 'bytes'), 163 (binary_name + '-text', 'text', '', text, 'bytes'),
164 (binary_name + '-data', 'data', '', data, 'bytes'), 164 (binary_name + '-data', 'data', '', data, 'bytes'),
165 (binary_name + '-bss', 'bss', '', bss, 'bytes'), 165 (binary_name + '-bss', 'bss', '', bss, 'bytes'),
166 ] 166 ]
167 167
168 # Find the number of files with at least one static initializer. 168 # For Release builds only, use dump-static-initializers.py to get the number
169 # First determine if we're 32 or 64 bit 169 # of static initializers.
170 result, stdout = run_process(result, ['readelf', '-h', binary_file]) 170 if options.target == 'Release':
171 elf_class_line = re.search('Class:.*$', stdout, re.MULTILINE).group(0) 171 dump_static_initializers = os.path.join(os.path.dirname(target_dir),
Lei Zhang 2012/02/04 03:10:00 So how about os.path.join(options.build_dir, 'tool
172 elf_class = re.split('\W+', elf_class_line)[1] 172 '..', '..', 'tools', 'linux',
173 if elf_class == 'ELF32': 173 'dump-static-initializers.py')
174 word_size = 4 174 result, stdout = run_process(result, [dump_static_initializers,
175 else: 175 '-d', binary_file])
176 word_size = 8 176 count = re.search('Found (\d+) static initializers',
177 177 stdout).group(1)
178 # Then find the size of the .ctors section. 178 if count is not '0':
179 result, stdout = run_process(result, ['readelf', '-SW', binary_file]) 179 print '\nStatic initializers in %s:' % binary_file
180 size_match = re.search('.ctors.*$', stdout, re.MULTILINE) 180 print stdout
181 if size_match is None: 181 sizes.append(
182 count = 0 182 (binary_name + '-si', 'initializers', '', count, 'initializers'))
183 else:
184 size_line = re.search('.ctors.*$', stdout, re.MULTILINE).group(0)
185 size = re.split('\W+', size_line)[5]
186 size = int(size, 16)
187 # The first entry is always 0 and the last is -1 as guards.
188 # So subtract 2 from the count.
189 count = (size / word_size) - 2
190 sizes.append((binary_name + '-si', 'initializers', '', count, 'files'))
191 183
192 # Determine if the binary has the DT_TEXTREL marker. 184 # Determine if the binary has the DT_TEXTREL marker.
193 result, stdout = run_process(result, ['readelf', '-Wd', binary_file]) 185 result, stdout = run_process(result, ['readelf', '-Wd', binary_file])
194 if re.search(r'\bTEXTREL\b', stdout) is None: 186 if re.search(r'\bTEXTREL\b', stdout) is None:
195 # Nope, so the count is zero. 187 # Nope, so the count is zero.
196 count = 0 188 count = 0
197 else: 189 else:
198 # There are some, so count them. 190 # There are some, so count them.
199 result, stdout = run_process(result, ['eu-findtextrel', binary_file]) 191 result, stdout = run_process(result, ['eu-findtextrel', binary_file])
200 count = stdout.count('\n') 192 count = stdout.count('\n')
(...skipping 19 matching lines...) Expand all
220 'libgcflashplayer.so', 212 'libgcflashplayer.so',
221 'libpdf.so', 213 'libpdf.so',
222 'libppGoogleNaClPluginChrome.so', 214 'libppGoogleNaClPluginChrome.so',
223 ] 215 ]
224 216
225 result = 0 217 result = 0
226 218
227 totals = {} 219 totals = {}
228 220
229 for binary in binaries: 221 for binary in binaries:
230 this_result, this_sizes = check_linux_binary(target_dir, binary) 222 this_result, this_sizes = check_linux_binary(target_dir, binary, options)
231 if result == 0: 223 if result == 0:
232 result = this_result 224 result = this_result
233 for name, identifier, totals_id, value, units in this_sizes: 225 for name, identifier, totals_id, value, units in this_sizes:
234 print 'RESULT %s: %s= %s %s' % (name, identifier, value, units) 226 print 'RESULT %s: %s= %s %s' % (name, identifier, value, units)
235 totals_id = totals_id or identifier, units 227 totals_id = totals_id or identifier, units
236 totals[totals_id] = totals.get(totals_id, 0) + int(value) 228 totals[totals_id] = totals.get(totals_id, 0) + int(value)
237 229
238 files = [ 230 files = [
239 'chrome.pak', 231 'chrome.pak',
240 'nacl_irt_x86_64.nexe', 232 'nacl_irt_x86_64.nexe',
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 else: 320 else:
329 sys.stderr.write('Unknown platform %s.\n' % repr(options.platform)) 321 sys.stderr.write('Unknown platform %s.\n' % repr(options.platform))
330 msg = 'Use the --platform= option to specify a supported platform:\n' 322 msg = 'Use the --platform= option to specify a supported platform:\n'
331 sys.stderr.write(msg + ' ' + ' '.join(platforms) + '\n') 323 sys.stderr.write(msg + ' ' + ' '.join(platforms) + '\n')
332 return 2 324 return 2
333 return real_main(options, args) 325 return real_main(options, args)
334 326
335 327
336 if '__main__' == __name__: 328 if '__main__' == __name__:
337 sys.exit(main()) 329 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698