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

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: 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..4affdb99d07b5de81eb19e05af6c1b453123d83c 100644
--- a/tools/metrics/histograms/update_histogram_enum.py
+++ b/tools/metrics/histograms/update_histogram_enum.py
@@ -20,6 +20,8 @@ import path_util
import print_style
+HISTOGRAMS_PATH = path_util.GetHistogramsFile()
Ilya Sherman 2016/03/02 23:52:05 nit: Please leave two blank lines above and below
suzyh_UTC10 (ex-contributor) 2016/03/03 00:04:59 Done.
+
class UserError(Exception):
def __init__(self, message):
Exception.__init__(self, message)
@@ -142,15 +144,12 @@ 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|.
+def _GetOldAndUpdatedXml(histogram_enum_name, source_enum_values,
+ source_enum_path):
+ """Reads old histogram from |histogram_enum_name| from |HISTOGRAMS_PATH|, and
+ calculates new histogram from |source_enum_values| from |source_enum_path|,
+ and returns both in XML format.
"""
- HISTOGRAMS_PATH = path_util.GetHistogramsFile()
-
Log('Reading existing histograms from "{0}".'.format(HISTOGRAMS_PATH))
with open(HISTOGRAMS_PATH, 'rb') as f:
histograms_doc = minidom.parse(f)
@@ -161,8 +160,41 @@ 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)
+ 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)
+
+ (xml, new_xml) = _GetOldAndUpdatedXml(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|.
+ """
+ (xml, new_xml) = _GetOldAndUpdatedXml(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