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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 value_dict = {} | 209 value_dict = {} |
210 int_value = int(int_tag.getAttribute('value')) | 210 int_value = int(int_tag.getAttribute('value')) |
211 if int_value in enum_dict['values']: | 211 if int_value in enum_dict['values']: |
212 logging.error('Duplicate enum value %d for enum %s', int_value, name) | 212 logging.error('Duplicate enum value %d for enum %s', int_value, name) |
213 have_errors = True | 213 have_errors = True |
214 continue | 214 continue |
215 value_dict['label'] = int_tag.getAttribute('label') | 215 value_dict['label'] = int_tag.getAttribute('label') |
216 value_dict['summary'] = _JoinChildNodes(int_tag) | 216 value_dict['summary'] = _JoinChildNodes(int_tag) |
217 enum_dict['values'][int_value] = value_dict | 217 enum_dict['values'][int_value] = value_dict |
218 | 218 |
219 enum_items = sorted(enum_dict['values'].iteritems(), key=lambda i: i[0]) | 219 enum_int_values = sorted(enum_dict['values'].keys()) |
220 enum_int_values = list(i[0] for i in enum_items) | |
221 | 220 |
222 last_int_value = None | 221 last_int_value = None |
223 for int_tag in enum.getElementsByTagName('int'): | 222 for int_tag in enum.getElementsByTagName('int'): |
224 int_value = int(int_tag.getAttribute('value')) | 223 int_value = int(int_tag.getAttribute('value')) |
225 if last_int_value is not None and int_value < last_int_value: | 224 if last_int_value is not None and int_value < last_int_value: |
226 logging.error('Enum %s int values %d and %d are not in numerical order', | 225 logging.error('Enum %s int values %d and %d are not in numerical order', |
227 name, last_int_value, int_value) | 226 name, last_int_value, int_value) |
228 have_errors = True | 227 have_errors = True |
229 left_item_index = bisect.bisect_left(enum_int_values, int_value) | 228 left_item_index = bisect.bisect_left(enum_int_values, int_value) |
230 if left_item_index == 0: | 229 if left_item_index == 0: |
231 logging.warning('Insert value %d at the beginning', int_value) | 230 logging.warning('Insert value %d at the beginning', int_value) |
232 else: | 231 else: |
233 left_int_value, left_value_dict = enum_items[left_item_index - 1] | 232 left_int_value = enum_int_values[left_item_index - 1] |
233 left_label = enum_dict['values'][left_int_value] | |
234 logging.warning('Insert value %d after %d ("%s")', | 234 logging.warning('Insert value %d after %d ("%s")', |
235 int_value, left_int_value, left_value_dict['label']) | 235 int_value, left_int_value, left_label) |
DmitrySkiba
2017/04/14 22:01:41
Previously it was logging just a string, but now l
Ilya Sherman
2017/04/14 22:31:26
Whoops, not intentional, thanks. Fixed.
| |
236 else: | 236 else: |
237 last_int_value = int_value | 237 last_int_value = int_value |
238 | 238 |
239 summary_nodes = enum.getElementsByTagName('summary') | 239 summary_nodes = enum.getElementsByTagName('summary') |
240 if summary_nodes: | 240 if summary_nodes: |
241 enum_dict['summary'] = _NormalizeString(_JoinChildNodes(summary_nodes[0])) | 241 enum_dict['summary'] = _NormalizeString(_JoinChildNodes(summary_nodes[0])) |
242 | 242 |
243 enums[name] = enum_dict | 243 enums[name] = enum_dict |
244 | 244 |
245 return enums, have_errors | 245 return enums, have_errors |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 with open(filename, 'r') as f: | 524 with open(filename, 'r') as f: |
525 histograms, had_errors = ExtractHistogramsFromFile(f) | 525 histograms, had_errors = ExtractHistogramsFromFile(f) |
526 if had_errors: | 526 if had_errors: |
527 logging.error('Error parsing %s', filename) | 527 logging.error('Error parsing %s', filename) |
528 raise Error() | 528 raise Error() |
529 return histograms | 529 return histograms |
530 | 530 |
531 | 531 |
532 def ExtractNames(histograms): | 532 def ExtractNames(histograms): |
533 return sorted(histograms.keys()) | 533 return sorted(histograms.keys()) |
OLD | NEW |