Chromium Code Reviews| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 """ | 135 """ |
| 136 if histogram_suffixes_node.hasAttribute('separator'): | 136 if histogram_suffixes_node.hasAttribute('separator'): |
| 137 separator = histogram_suffixes_node.getAttribute('separator') | 137 separator = histogram_suffixes_node.getAttribute('separator') |
| 138 else: | 138 else: |
| 139 separator = '_' | 139 separator = '_' |
| 140 | 140 |
| 141 if histogram_suffixes_node.hasAttribute('ordering'): | 141 if histogram_suffixes_node.hasAttribute('ordering'): |
| 142 ordering = histogram_suffixes_node.getAttribute('ordering') | 142 ordering = histogram_suffixes_node.getAttribute('ordering') |
| 143 else: | 143 else: |
| 144 ordering = 'suffix' | 144 ordering = 'suffix' |
| 145 parts = ordering.split(',') | |
|
Alexei Svitkine (slow)
2017/01/18 18:46:59
Note: Please also make the same change in the inte
bcwhite
2017/01/18 19:06:59
Acknowledged.
| |
| 146 ordering = parts[0] | |
| 147 if len(parts) > 1: | |
| 148 placement = int(parts[1]) | |
| 149 else: | |
| 150 placement = 1 | |
| 145 if ordering not in ['prefix', 'suffix']: | 151 if ordering not in ['prefix', 'suffix']: |
| 146 logging.error('ordering needs to be prefix or suffix, value is %s', | 152 logging.error('ordering needs to be prefix or suffix, value is %s', |
| 147 ordering) | 153 ordering) |
| 148 raise Error() | 154 raise Error() |
| 149 | 155 |
| 150 if not suffix_name: | 156 if not suffix_name: |
| 151 return histogram_name | 157 return histogram_name |
| 152 | 158 |
| 153 if ordering == 'suffix': | 159 if ordering == 'suffix': |
| 154 return histogram_name + separator + suffix_name | 160 return histogram_name + separator + suffix_name |
| 155 | 161 |
| 156 # For prefixes, the suffix_name is inserted between the "cluster" and the | 162 # For prefixes, the suffix_name is inserted between the "cluster" and the |
| 157 # "remainder", e.g. Foo.BarHist expanded with gamma becomes Foo.gamma_BarHist. | 163 # "remainder", e.g. Foo.BarHist expanded with gamma becomes Foo.gamma_BarHist. |
| 158 sections = histogram_name.split('.') | 164 sections = histogram_name.split('.') |
| 159 if len(sections) <= 1: | 165 if len(sections) <= placement: |
| 160 logging.error( | 166 logging.error( |
| 161 'Prefix Field Trial expansions require histogram names which include a ' | 167 'Prefix Field Trial expansions require histogram names which include a ' |
|
Alexei Svitkine (slow)
2017/01/18 18:46:59
Nit: Rename this message to not say "Field Trial".
bcwhite
2017/01/18 19:06:59
Done.
| |
| 162 'dot separator. Histogram name is %s, and Field Trial is %s', | 168 'dot separator. Histogram name is %s, Field Trial is %s, and placment ' |
| 163 histogram_name, histogram_suffixes_node.getAttribute('name')) | 169 'is %d', histogram_name, histogram_suffixes_node.getAttribute('name'), |
| 170 placement) | |
| 164 raise Error() | 171 raise Error() |
| 165 | 172 |
| 166 cluster = sections[0] + '.' | 173 cluster = '.'.join(sections[0:placement]) + '.' |
| 167 remainder = '.'.join(sections[1:]) | 174 remainder = '.'.join(sections[placement:]) |
| 168 return cluster + suffix_name + separator + remainder | 175 return cluster + suffix_name + separator + remainder |
| 169 | 176 |
| 170 | 177 |
| 171 def _ExtractEnumsFromXmlTree(tree): | 178 def _ExtractEnumsFromXmlTree(tree): |
| 172 """Extract all <enum> nodes in the tree into a dictionary.""" | 179 """Extract all <enum> nodes in the tree into a dictionary.""" |
| 173 | 180 |
| 174 enums = {} | 181 enums = {} |
| 175 have_errors = False | 182 have_errors = False |
| 176 | 183 |
| 177 last_name = None | 184 last_name = None |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 with open(filename, 'r') as f: | 509 with open(filename, 'r') as f: |
| 503 histograms, had_errors = ExtractHistogramsFromFile(f) | 510 histograms, had_errors = ExtractHistogramsFromFile(f) |
| 504 if had_errors: | 511 if had_errors: |
| 505 logging.error('Error parsing %s', filename) | 512 logging.error('Error parsing %s', filename) |
| 506 raise Error() | 513 raise Error() |
| 507 return histograms | 514 return histograms |
| 508 | 515 |
| 509 | 516 |
| 510 def ExtractNames(histograms): | 517 def ExtractNames(histograms): |
| 511 return sorted(histograms.keys()) | 518 return sorted(histograms.keys()) |
| OLD | NEW |