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

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

Issue 2835733002: Readdress use_counter_feature_enum issue (Closed)
Patch Set: Codereview: nit 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 | « third_party/WebKit/Source/core/frame/PRESUBMIT.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/metrics/histograms/update_histogram_enum.py
diff --git a/tools/metrics/histograms/update_histogram_enum.py b/tools/metrics/histograms/update_histogram_enum.py
index f0a29e0fe91c7aaf1c0500e82c572c0d836c4059..3ec3db297764156a14794ab42395f20433c16afb 100644
--- a/tools/metrics/histograms/update_histogram_enum.py
+++ b/tools/metrics/histograms/update_histogram_enum.py
@@ -33,16 +33,27 @@ class UserError(Exception):
return self.args[0]
+class DuplicatedValue(Exception):
+ """Exception raised for duplicated enum values.
+
+ Attributes:
+ first_label: First enum label that shares the duplicated enum value.
+ second_label: Second enum label that shares the duplicated enum value.
+ """
+ def __init__(self, first_label, second_label):
+ self.first_label = first_label
+ self.second_label = second_label
+
+
def Log(message):
logging.info(message)
def ReadHistogramValues(filename, start_marker, end_marker, strip_k_prefix):
- """Returns a dictionary of enum values and a pair of labels that have the same
- enum values, read from a C++ file.
+ """Creates a dictionary of enum values, read from a C++ file.
Args:
- filename: The unix-style path (relative to src/) of the file to open.
+ filename: The unix-style (relative to src/) of the file to open.
start_marker: A regex that signifies the start of the enum values.
end_marker: A regex that signifies the end of the enum values.
strip_k_prefix: Set to True if enum values are declared as kFoo and the
@@ -89,13 +100,13 @@ def ReadHistogramValues(filename, start_marker, end_marker, strip_k_prefix):
continue
# If two enum labels have the same value
if enum_value in result:
- return result, (result[enum_value], label)
+ raise DuplicatedValue(result[enum_value], label)
if strip_k_prefix:
assert label.startswith('k'), "Enum " + label + " should start with 'k'."
label = label[1:]
result[enum_value] = label
enum_value += 1
- return result, None
+ return result
def CreateEnumItemNode(document, value, label):
@@ -183,8 +194,7 @@ def _GetOldAndUpdatedXml(histogram_enum_name, source_enum_values,
def HistogramNeedsUpdate(histogram_enum_name, source_enum_path, start_marker,
end_marker, strip_k_prefix = False):
"""Reads a C++ enum from a .h file and does a dry run of updating
- histograms.xml to match. Returns true if the histograms.xml file would be
- changed.
+ histograms.xml to match.
Args:
histogram_enum_name: The name of the XML <enum> attribute to update.
@@ -194,16 +204,22 @@ def HistogramNeedsUpdate(histogram_enum_name, source_enum_path, start_marker,
end_marker: A regular expression that matches the end of the C++ enum.
strip_k_prefix: Set to True if enum values are declared as kFoo and the
'k' should be stripped.
+
+ Returns:
+ A boolean indicating wheather the histograms.xml file would be changed.
+
+ Raises:
+ DuplicatedValue: An error when two enum labels share the same value.
"""
Log('Reading histogram enum definition from "{0}".'.format(source_enum_path))
source_enum_values, duplicated_values = ReadHistogramValues(
source_enum_path, start_marker, end_marker, strip_k_prefix)
Ilya Sherman 2017/04/27 22:23:15 ReadHistogramValues now only returns the source_en
lunalu1 2017/04/28 00:31:32 Done.
if duplicated_values:
- return False, duplicated_values
+ return False
(xml, new_xml) = _GetOldAndUpdatedXml(histogram_enum_name, source_enum_values,
source_enum_path)
- return xml != new_xml, None
+ return xml != new_xml
def UpdateHistogramFromDict(histogram_enum_name, source_enum_values,
« no previous file with comments | « third_party/WebKit/Source/core/frame/PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698