Chromium Code Reviews| Index: tools/metrics/histograms/extract_histograms.py |
| diff --git a/tools/metrics/histograms/extract_histograms.py b/tools/metrics/histograms/extract_histograms.py |
| index 7ed28318a99547b67481dca418df825fdbf92376..61d7e864d6e1fbe4a4652de484c2302f51640e75 100644 |
| --- a/tools/metrics/histograms/extract_histograms.py |
| +++ b/tools/metrics/histograms/extract_histograms.py |
| @@ -54,6 +54,7 @@ XML below will generate the following five histograms: |
| """ |
| +import bisect |
| import copy |
| import logging |
| import xml.dom.minidom |
| @@ -200,7 +201,6 @@ def _ExtractEnumsFromXmlTree(tree): |
| have_errors = True |
| continue |
| - last_int_value = None |
| enum_dict = {} |
| enum_dict['name'] = name |
| enum_dict['values'] = {} |
| @@ -208,11 +208,6 @@ def _ExtractEnumsFromXmlTree(tree): |
| for int_tag in enum.getElementsByTagName('int'): |
| value_dict = {} |
| int_value = int(int_tag.getAttribute('value')) |
| - if last_int_value is not None and int_value < last_int_value: |
| - logging.error('Enum %s int values %d and %d are not in numerical order', |
| - name, last_int_value, int_value) |
| - have_errors = True |
| - last_int_value = int_value |
| if int_value in enum_dict['values']: |
| logging.error('Duplicate enum value %d for enum %s', int_value, name) |
| have_errors = True |
| @@ -221,6 +216,26 @@ def _ExtractEnumsFromXmlTree(tree): |
| value_dict['summary'] = _JoinChildNodes(int_tag) |
| enum_dict['values'][int_value] = value_dict |
| + enum_items = sorted(enum_dict['values'].iteritems(), key=lambda i: i[0]) |
| + enum_int_values = list(i[0] for i in enum_items) |
|
Ilya Sherman
2017/04/12 20:29:33
Optional: I was thinking you could write something
|
| + |
| + last_int_value = None |
| + for int_tag in enum.getElementsByTagName('int'): |
| + int_value = int(int_tag.getAttribute('value')) |
| + if last_int_value is not None and int_value < last_int_value: |
| + logging.error('Enum %s int values %d and %d are not in numerical order', |
| + name, last_int_value, int_value) |
| + have_errors = True |
| + left_item_index = bisect.bisect_left(enum_int_values, int_value) |
| + if left_item_index == 0: |
| + logging.warning('Insert value %d at the beginning', int_value) |
| + else: |
| + left_int_value, left_value_dict = enum_items[left_item_index - 1] |
| + logging.warning('Insert value %d after %d ("%s")', |
| + int_value, left_int_value, left_value_dict['label']) |
| + else: |
| + last_int_value = int_value |
| + |
| summary_nodes = enum.getElementsByTagName('summary') |
| if summary_nodes: |
| enum_dict['summary'] = _NormalizeString(_JoinChildNodes(summary_nodes[0])) |