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 ba975996719ce541a07445cf4a3a4c4cefb4cd23..d2f9617571e0608424d0ca302a3b8baf209324e1 100644 |
--- a/tools/metrics/histograms/update_histogram_enum.py |
+++ b/tools/metrics/histograms/update_histogram_enum.py |
@@ -142,17 +142,10 @@ def UpdateHistogramDefinitions(histogram_enum_name, source_enum_values, |
enum_node.appendChild(new_item_nodes[value]) |
-def UpdateHistogramFromDict(histogram_enum_name, source_enum_values, |
- source_enum_path): |
- """Updates |histogram_enum_name| enum in histograms.xml file with values |
- from the {value: 'key'} dictionary |source_enum_values|. A comment is added |
- to histograms.xml citing that the values in |histogram_enum_name| were |
- sourced from |source_enum_path|. |
- """ |
- HISTOGRAMS_PATH = path_util.GetHistogramsFile() |
- |
- Log('Reading existing histograms from "{0}".'.format(HISTOGRAMS_PATH)) |
- with open(HISTOGRAMS_PATH, 'rb') as f: |
+def _GetOldAndUpdatedXml(histograms_path, histogram_enum_name, |
+ source_enum_values, source_enum_path): |
Ilya Sherman
2016/03/02 23:18:46
Please add documentation for this function.
suzyh_UTC10 (ex-contributor)
2016/03/02 23:49:16
Done.
|
+ Log('Reading existing histograms from "{0}".'.format(histograms_path)) |
+ with open(histograms_path, 'rb') as f: |
histograms_doc = minidom.parse(f) |
f.seek(0) |
xml = f.read() |
@@ -161,8 +154,45 @@ def UpdateHistogramFromDict(histogram_enum_name, source_enum_values, |
UpdateHistogramDefinitions(histogram_enum_name, source_enum_values, |
source_enum_path, histograms_doc) |
- Log('Writing out new histograms file.') |
new_xml = print_style.GetPrintStyle().PrettyPrintNode(histograms_doc) |
+ |
Ilya Sherman
2016/03/02 23:18:46
Optional nit: I'd omit this newline.
suzyh_UTC10 (ex-contributor)
2016/03/02 23:49:17
Done.
|
+ return (xml, new_xml) |
+ |
+ |
+def HistogramNeedsUpdate(histogram_enum_name, source_enum_path, start_marker, |
+ end_marker): |
+ """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. |
+ |
+ Args: |
+ histogram_enum_name: The name of the XML <enum> attribute to update. |
+ source_enum_path: A unix-style path, relative to src/, giving |
+ the C++ header file from which to read the enum. |
+ start_marker: A regular expression that matches the start of the C++ enum. |
+ end_marker: A regular expression that matches the end of the C++ enum. |
+ """ |
+ Log('Reading histogram enum definition from "{0}".'.format(source_enum_path)) |
+ source_enum_values = ReadHistogramValues(source_enum_path, start_marker, |
+ end_marker) |
+ |
+ HISTOGRAMS_PATH = path_util.GetHistogramsFile() |
+ (xml, new_xml) = _GetOldAndUpdatedXml(HISTOGRAMS_PATH, histogram_enum_name, |
+ source_enum_values, source_enum_path) |
+ return xml != new_xml |
+ |
+ |
+def UpdateHistogramFromDict(histogram_enum_name, source_enum_values, |
+ source_enum_path): |
+ """Updates |histogram_enum_name| enum in histograms.xml file with values |
+ from the {value: 'key'} dictionary |source_enum_values|. A comment is added |
+ to histograms.xml citing that the values in |histogram_enum_name| were |
+ sourced from |source_enum_path|. |
+ """ |
+ HISTOGRAMS_PATH = path_util.GetHistogramsFile() |
Ilya Sherman
2016/03/02 23:18:46
nit: I think this can be moved into _GetOldAndUpda
suzyh_UTC10 (ex-contributor)
2016/03/02 23:27:10
I contemplated this, but then _GetOldAndUpdatedXml
Ilya Sherman
2016/03/02 23:35:31
Ah, I missed that. I think it would be fine to pr
suzyh_UTC10 (ex-contributor)
2016/03/02 23:49:17
Done.
|
+ |
+ (xml, new_xml) = _GetOldAndUpdatedXml(HISTOGRAMS_PATH, histogram_enum_name, |
+ source_enum_values, source_enum_path) |
if not diff_util.PromptUserToAcceptDiff( |
xml, new_xml, 'Is the updated version acceptable?'): |
Log('Cancelled.') |