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

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

Issue 2228573003: In find_unmapped_histograms.py, remove comments from histogram names (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@find_unmapped_histograms_non_literal
Patch Set: Rebase Created 4 years, 4 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/metrics/histograms/find_unmapped_histograms.py
diff --git a/tools/metrics/histograms/find_unmapped_histograms.py b/tools/metrics/histograms/find_unmapped_histograms.py
index 903afa97494624dd3837e32bb49bb7171ca03d5b..e25f52aef0df01cf4ee14c494808ee3bef4fc6bf 100644
--- a/tools/metrics/histograms/find_unmapped_histograms.py
+++ b/tools/metrics/histograms/find_unmapped_histograms.py
@@ -24,6 +24,21 @@ import path_util
import extract_histograms
+CPP_COMMENT = re.compile(r"""
+ \s* # Optional whitespace
+ (?: # Non-capturing group
+ //.* # C++-style comment
+ \n # Newline
+ | # or
+ /\* # Start C-style comment
+ (?: # Non-capturing group
+ (?!\*/) # Negative lookahead for comment end
+ [\s\S] # Any character including newline
+ )* # Repeated zero or more times
+ \*/ # End C-style comment
+ ) # End group
+ \s* # Optional whitespace
+ """, re.VERBOSE);
ADJACENT_C_STRING_REGEX = re.compile(r"""
(" # Opening quotation mark
[^"]*) # Literal string contents
@@ -79,6 +94,21 @@ class DirectoryNotFoundException(Exception):
return self.msg
+def removeComments(string):
+ """Remove any comments from an expression, including leading and trailing
+ whitespace. This does not correctly ignore comments embedded in strings,
+ but that shouldn't matter for this script.
+
+ Args:
+ string: The string to remove comments from, e.g.
+ ' // My histogram\n "My.Important.Counts" '
+
+ Returns:
+ The string with comments removed, e.g. '"My.Important.Counts" '
+ """
+ return CPP_COMMENT.sub('', string)
+
+
def collapseAdjacentCStrings(string):
"""Collapses any adjacent C strings into a single string.
@@ -166,6 +196,7 @@ def readChromiumHistograms():
for match in HISTOGRAM_REGEX.finditer(contents):
histogram = collapseAdjacentCStrings(match.group(1))
+ histogram = removeComments(histogram)
# Must begin and end with a quotation mark.
if not histogram or histogram[0] != '"' or histogram[-1] != '"':
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698