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..2d9386cee1331b0ee40f5dc3938056191fafb9a1 100644 |
| --- a/tools/metrics/histograms/extract_histograms.py |
| +++ b/tools/metrics/histograms/extract_histograms.py |
| @@ -200,7 +200,6 @@ def _ExtractEnumsFromXmlTree(tree): |
| have_errors = True |
| continue |
| - last_int_value = None |
| enum_dict = {} |
| enum_dict['name'] = name |
| enum_dict['values'] = {} |
| @@ -208,11 +207,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 +215,36 @@ 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]) |
| + def _FindLeftEnumItemIndex(int_value): |
| + """ Copy of bisect.bisect_left() modified to work with |enum_items|. """ |
| + lo = 0 |
| + hi = len(enum_items) |
| + while lo < hi: |
| + mid = (lo + hi) / 2 |
| + if enum_items[mid][0] < int_value: lo = mid + 1 |
| + else: hi = mid |
| + return lo |
|
Ilya Sherman
2017/04/11 21:34:25
Rather than copying bisect.bisect_left(), could yo
DmitrySkiba
2017/04/12 16:24:13
Done.
|
| + |
| + 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 = _FindLeftEnumItemIndex(int_value) |
| + if left_item_index == 0: |
| + logging.warning('Insert value %d at the beginning of enum %s', |
| + int_value, name) |
| + else: |
| + left_item_index -= 1 |
| + left_int_value, left_value_dict = enum_items[left_item_index] |
|
Ilya Sherman
2017/04/11 21:34:25
nit: It looks like the -1 calculation could be mov
DmitrySkiba
2017/04/12 16:24:13
Done.
|
| + 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])) |