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

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

Issue 1745913002: Add histograms presubmit check for UseCounter.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re-remove dummy UseCounter Created 4 years, 10 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 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.')
« 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