Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Unified Diff: tools/metrics/histograms/extract_histograms.py

Issue 2810733005: Hint about where to insert integer histogram enum values. (Closed)
Patch Set: Address comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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]))
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698