| 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 """Extract histogram names from the description XML file. | 5 """Extract histogram names from the description XML file. |
| 6 | 6 |
| 7 For more information on the format of the XML file, which is self-documenting, | 7 For more information on the format of the XML file, which is self-documenting, |
| 8 see histograms.xml; however, here is a simple example to get you started. The | 8 see histograms.xml; however, here is a simple example to get you started. The |
| 9 XML below will generate the following five histograms: | 9 XML below will generate the following five histograms: |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 <summary>This is an example enum type, where the values mean little.</summary> | 35 <summary>This is an example enum type, where the values mean little.</summary> |
| 36 <int value="1" label="FIRST_VALUE">This is the first value.</int> | 36 <int value="1" label="FIRST_VALUE">This is the first value.</int> |
| 37 <int value="2" label="SECOND_VALUE">This is the second value.</int> | 37 <int value="2" label="SECOND_VALUE">This is the second value.</int> |
| 38 </enum> | 38 </enum> |
| 39 | 39 |
| 40 </enums> | 40 </enums> |
| 41 | 41 |
| 42 <histogram_suffixes_list> | 42 <histogram_suffixes_list> |
| 43 | 43 |
| 44 <histogram_suffixes name="BrowserType"> | 44 <histogram_suffixes name="BrowserType"> |
| 45 <group name="Chrome"/> | 45 <suffix name="Chrome"/> |
| 46 <group name="IE"/> | 46 <suffix name="IE"/> |
| 47 <group name="Firefox"/> | 47 <suffix name="Firefox"/> |
| 48 <affected-histogram name="HistogramEnum"/> | 48 <affected-histogram name="HistogramEnum"/> |
| 49 </histogram_suffixes> | 49 </histogram_suffixes> |
| 50 | 50 |
| 51 </histogram_suffixes_list> | 51 </histogram_suffixes_list> |
| 52 | 52 |
| 53 </histogram-configuration> | 53 </histogram-configuration> |
| 54 | 54 |
| 55 """ | 55 """ |
| 56 | 56 |
| 57 import copy | 57 import copy |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 300 |
| 301 Args: | 301 Args: |
| 302 tree: XML dom tree. | 302 tree: XML dom tree. |
| 303 histograms: a dictionary of histograms previously extracted from the tree; | 303 histograms: a dictionary of histograms previously extracted from the tree; |
| 304 | 304 |
| 305 Returns: | 305 Returns: |
| 306 True if any errors were found. | 306 True if any errors were found. |
| 307 """ | 307 """ |
| 308 have_errors = False | 308 have_errors = False |
| 309 | 309 |
| 310 # TODO(yiyaoliu): Remove this part after fieldtrial is not used any more. | 310 histogram_suffix_tag = 'histogram_suffixes' |
| 311 if tree.getElementsByTagName('histogram_suffixes'): | 311 suffix_tag = 'suffix' |
| 312 histogram_suffix_tag = 'histogram_suffixes' | 312 with_tag = 'with-suffix' |
| 313 suffix_tag = 'suffix' | |
| 314 with_tag = 'with-suffix' | |
| 315 else: | |
| 316 histogram_suffix_tag = 'fieldtrial' | |
| 317 suffix_tag = 'group' | |
| 318 with_tag = 'with-group' | |
| 319 | 313 |
| 320 # Verify order of histogram_suffixes fields first. | 314 # Verify order of histogram_suffixes fields first. |
| 321 last_name = None | 315 last_name = None |
| 322 for histogram_suffixes in tree.getElementsByTagName(histogram_suffix_tag): | 316 for histogram_suffixes in tree.getElementsByTagName(histogram_suffix_tag): |
| 323 name = histogram_suffixes.getAttribute('name') | 317 name = histogram_suffixes.getAttribute('name') |
| 324 if last_name is not None and name.lower() < last_name.lower(): | 318 if last_name is not None and name.lower() < last_name.lower(): |
| 325 logging.error('histogram_suffixes %s and %s are not in alphabetical ' | 319 logging.error('histogram_suffixes %s and %s are not in alphabetical ' |
| 326 'order', last_name, name) | 320 'order', last_name, name) |
| 327 have_errors = True | 321 have_errors = True |
| 328 last_name = name | 322 last_name = name |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 with open(filename, 'r') as f: | 452 with open(filename, 'r') as f: |
| 459 histograms, had_errors = ExtractHistogramsFromFile(f) | 453 histograms, had_errors = ExtractHistogramsFromFile(f) |
| 460 if had_errors: | 454 if had_errors: |
| 461 logging.error('Error parsing %s', filename) | 455 logging.error('Error parsing %s', filename) |
| 462 raise Error() | 456 raise Error() |
| 463 return histograms | 457 return histograms |
| 464 | 458 |
| 465 | 459 |
| 466 def ExtractNames(histograms): | 460 def ExtractNames(histograms): |
| 467 return sorted(histograms.keys()) | 461 return sorted(histograms.keys()) |
| OLD | NEW |