OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Scans the Chromium source for histograms that are absent from histograms.xml. | 5 """Scans the Chromium source for histograms that are absent from histograms.xml. |
6 | 6 |
7 This is a heuristic scan, so a clean run of this script does not guarantee that | 7 This is a heuristic scan, so a clean run of this script does not guarantee that |
8 all histograms in the Chromium source are properly mapped. Notably, field | 8 all histograms in the Chromium source are properly mapped. Notably, field |
9 trials are entirely ignored by this script. | 9 trials are entirely ignored by this script. |
10 | 10 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 | 282 |
283 Args: | 283 Args: |
284 name: The string to hash (a histogram name). | 284 name: The string to hash (a histogram name). |
285 | 285 |
286 Returns: | 286 Returns: |
287 Histogram hash as a string representing a hex number (with leading 0x). | 287 Histogram hash as a string representing a hex number (with leading 0x). |
288 """ | 288 """ |
289 return '0x' + hashlib.md5(name).hexdigest()[:16] | 289 return '0x' + hashlib.md5(name).hexdigest()[:16] |
290 | 290 |
291 | 291 |
292 def output_csv(unmapped_histograms, location_map): | |
293 for histogram in sorted(unmapped_histograms): | |
294 (filename, line_number) = location_map[histogram].split(':', 1) | |
Ilya Sherman
2016/08/17 22:09:24
Hmm, is it really necessary to include the max-spl
| |
295 print '%s,%s,%s,%s' % (filename, line_number, histogram, | |
296 hashHistogramName(histogram)) | |
297 | |
298 | |
299 def output_log(unmapped_histograms, location_map, verbose): | |
300 if len(unmapped_histograms): | |
301 logging.info('') | |
302 logging.info('') | |
303 logging.info('Histograms in Chromium but not in XML files:') | |
304 logging.info('-------------------------------------------------') | |
305 for histogram in sorted(unmapped_histograms): | |
306 if verbose: | |
307 logging.info('%s: %s - %s', location_map[histogram], histogram, | |
308 hashHistogramName(histogram)) | |
309 else: | |
310 logging.info(' %s - %s', histogram, hashHistogramName(histogram)) | |
311 else: | |
312 logging.info('Success! No unmapped histograms found.') | |
313 | |
314 | |
292 def main(): | 315 def main(): |
293 # Find default paths. | 316 # Find default paths. |
294 default_root = path_util.GetInputFile('/') | 317 default_root = path_util.GetInputFile('/') |
295 default_histograms_path = path_util.GetInputFile( | 318 default_histograms_path = path_util.GetInputFile( |
296 'tools/metrics/histograms/histograms.xml') | 319 'tools/metrics/histograms/histograms.xml') |
297 default_extra_histograms_path = path_util.GetInputFile( | 320 default_extra_histograms_path = path_util.GetInputFile( |
298 'tools/histograms/histograms.xml') | 321 'tools/histograms/histograms.xml') |
299 | 322 |
300 # Parse command line options | 323 # Parse command line options |
301 parser = optparse.OptionParser() | 324 parser = optparse.OptionParser() |
302 parser.add_option( | 325 parser.add_option( |
303 '--root-directory', dest='root_directory', default=default_root, | 326 '--root-directory', dest='root_directory', default=default_root, |
304 help='scan within DIRECTORY for histograms [optional, defaults to "%s"]' % | 327 help='scan within DIRECTORY for histograms [optional, defaults to "%s"]' % |
305 default_root, | 328 default_root, |
306 metavar='DIRECTORY') | 329 metavar='DIRECTORY') |
307 parser.add_option( | 330 parser.add_option( |
308 '--histograms-file', dest='histograms_file_location', | 331 '--histograms-file', dest='histograms_file_location', |
309 default=default_histograms_path, | 332 default=default_histograms_path, |
310 help='read histogram definitions from FILE (relative to --root-directory) ' | 333 help='read histogram definitions from FILE (relative to --root-directory) ' |
311 '[optional, defaults to "%s"]' % default_histograms_path, | 334 '[optional, defaults to "%s"]' % default_histograms_path, |
312 metavar='FILE') | 335 metavar='FILE') |
313 parser.add_option( | 336 parser.add_option( |
314 '--exrta_histograms-file', dest='extra_histograms_file_location', | 337 '--exrta_histograms-file', dest='extra_histograms_file_location', |
315 default=default_extra_histograms_path, | 338 default=default_extra_histograms_path, |
316 help='read additional histogram definitions from FILE (relative to ' | 339 help='read additional histogram definitions from FILE (relative to ' |
317 '--root-directory) [optional, defaults to "%s"]' % | 340 '--root-directory) [optional, defaults to "%s"]' % |
318 default_extra_histograms_path, | 341 default_extra_histograms_path, |
319 metavar='FILE') | 342 metavar='FILE') |
320 parser.add_option( | 343 parser.add_option( |
344 '--csv', action='store_true', dest='csv', default=False, | |
Ilya Sherman
2016/08/17 22:09:24
nit: Let's name this variable 'output_as_csv' rath
| |
345 help=( | |
346 'output as csv for ease of parsing ' + | |
347 '[optional, defaults to %default]')) | |
348 parser.add_option( | |
321 '--verbose', action='store_true', dest='verbose', default=False, | 349 '--verbose', action='store_true', dest='verbose', default=False, |
322 help=( | 350 help=( |
323 'print file position information with histograms ' + | 351 'print file position information with histograms ' + |
324 '[optional, defaults to %default]')) | 352 '[optional, defaults to %default]')) |
325 | 353 |
326 (options, args) = parser.parse_args() | 354 (options, args) = parser.parse_args() |
327 if args: | 355 if args: |
328 parser.print_help() | 356 parser.print_help() |
329 sys.exit(1) | 357 sys.exit(1) |
330 | 358 |
331 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) | 359 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) |
332 | 360 |
333 try: | 361 try: |
334 os.chdir(options.root_directory) | 362 os.chdir(options.root_directory) |
335 except EnvironmentError as e: | 363 except EnvironmentError as e: |
336 logging.error("Could not change to root directory: %s", e) | 364 logging.error("Could not change to root directory: %s", e) |
337 sys.exit(1) | 365 sys.exit(1) |
338 chromium_histograms, location_map = readChromiumHistograms() | 366 chromium_histograms, location_map = readChromiumHistograms() |
339 xml_histograms = readXmlHistograms(options.histograms_file_location) | 367 xml_histograms = readXmlHistograms(options.histograms_file_location) |
340 unmapped_histograms = chromium_histograms - xml_histograms | 368 unmapped_histograms = chromium_histograms - xml_histograms |
341 | 369 |
342 if os.path.isfile(options.extra_histograms_file_location): | 370 if os.path.isfile(options.extra_histograms_file_location): |
343 xml_histograms2 = readXmlHistograms(options.extra_histograms_file_location) | 371 xml_histograms2 = readXmlHistograms(options.extra_histograms_file_location) |
344 unmapped_histograms -= xml_histograms2 | 372 unmapped_histograms -= xml_histograms2 |
345 else: | 373 else: |
346 logging.warning('No such file: %s', options.extra_histograms_file_location) | 374 logging.warning('No such file: %s', options.extra_histograms_file_location) |
347 | 375 |
348 if len(unmapped_histograms): | 376 if options.csv: |
349 logging.info('') | 377 output_csv(unmapped_histograms, location_map) |
350 logging.info('') | |
351 logging.info('Histograms in Chromium but not in XML files:') | |
352 logging.info('-------------------------------------------------') | |
353 for histogram in sorted(unmapped_histograms): | |
354 if options.verbose: | |
355 logging.info('%s: %s - %s', location_map[histogram], histogram, | |
356 hashHistogramName(histogram)) | |
357 else: | |
358 logging.info(' %s - %s', histogram, hashHistogramName(histogram)) | |
359 else: | 378 else: |
360 logging.info('Success! No unmapped histograms found.') | 379 output_log(unmapped_histograms, location_map, options.verbose) |
361 | 380 |
362 | 381 |
363 if __name__ == '__main__': | 382 if __name__ == '__main__': |
364 main() | 383 main() |
OLD | NEW |