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

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

Issue 276663002: Script to populate the XML for the CSS property UseCounter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@update-css-histogram
Patch Set: Created 6 years, 7 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
Index: tools/metrics/histograms/update_use_counter_css.py
diff --git a/tools/metrics/histograms/update_use_counter_feature_enum.py b/tools/metrics/histograms/update_use_counter_css.py
old mode 100755
new mode 100644
similarity index 54%
copy from tools/metrics/histograms/update_use_counter_feature_enum.py
copy to tools/metrics/histograms/update_use_counter_css.py
index 6886dfe6999dd9deaa22350269b6a072a1d1e4ad..bcd40472d8398c4b62860abc852bdbd2c876906e
--- a/tools/metrics/histograms/update_use_counter_feature_enum.py
+++ b/tools/metrics/histograms/update_use_counter_css.py
@@ -1,51 +1,68 @@
-#!/usr/bin/env python
-# Copyright 2014 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-"""Scans the Chromium source of UseCounter, formats the Feature enum for
-histograms.xml and merges it. This script can also generate a python code
-snippet to put in uma.py of Chromium Dashboard. Make sure that you review the
-output for correctness.
-"""
-
-import optparse
-import os
-import sys
-
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common'))
-from update_histogram_enum import ReadHistogramValues
-from update_histogram_enum import UpdateHistogramEnum
-
-
-def print_enum_for_dashboard(enum_dict):
- """Prints enum_items formatted for use in uma.py of Chromium dashboard."""
- for key in sorted(enum_dict.iterkeys()):
- print ' %d: \'%s\',' % (key, enum_dict[key])
-
-
-if __name__ == '__main__':
- parser = optparse.OptionParser()
- parser.add_option('--for-dashboard', action='store_true', dest='dashboard',
- default=False,
- help='Print enum definition formatted for use in uma.py of '
- 'Chromium dashboard developed at '
- 'https://github.com/GoogleChrome/chromium-dashboard')
- options, args = parser.parse_args()
-
- source_path = os.path.join(
- '..', '..', '..',
- 'third_party', 'WebKit', 'Source', 'core', 'frame', 'UseCounter.h')
-
- START_MARKER = '^enum Feature {'
- END_MARKER = '^NumberOfFeatures'
-
- if options.dashboard:
- enum_dict = ReadHistogramValues(source_path, START_MARKER, END_MARKER)
- print_enum_for_dashboard(enum_dict)
- else:
- UpdateHistogramEnum(
- histogram_enum_name='FeatureObserver',
- source_enum_path=source_path,
- start_marker=START_MARKER,
- end_marker=END_MARKER)
+#!/usr/bin/env python
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Scans the Chromium source of UseCounter, formats the Feature enum for
+histograms.xml and merges it. This script can also generate a python code
+snippet to put in uma.py of Chromium Dashboard. Make sure that you review the
+output for correctness.
+"""
+
+import optparse
+import os
+import re
+import sys
+
+sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common'))
+from update_histogram_enum import ReadHistogramValues
+from update_histogram_enum import UpdateHistogramFromDict
+
+
+USE_COUNTER_CPP_PATH = \
+ '../../../third_party/WebKit/Source/core/frame/UseCounter.cpp'
+
+
+def print_enum_for_dashboard(enum_dict):
Mike Lawther (Google) 2014/05/08 07:29:50 I wasn't sure where to factor this function to. Su
Mike Lawther (Google) 2014/05/09 01:11:03 I ended up just pulling it from the original locat
+ """Prints enum_items formatted for use in uma.py of Chromium dashboard."""
+ for key in sorted(enum_dict.iterkeys()):
+ print ' %d: \'%s\',' % (key, enum_dict[key])
+
tyoshino (SeeGerritForStatus) 2014/05/08 08:06:53 two vertical spaces plz http://google-styleguide.
Mike Lawther (Google) 2014/05/09 01:11:03 Done. It looks like the presubmit picks up some
+def enum_to_css(enum_name):
tyoshino (SeeGerritForStatus) 2014/05/08 08:06:53 enum_to_css_property
Mike Lawther (Google) 2014/05/09 01:11:03 Done.
+ """Converts a camel cased enum name to the lower case CSS property"""
tyoshino (SeeGerritForStatus) 2014/05/08 08:06:53 period plz
Mike Lawther (Google) 2014/05/09 01:11:03 Done.
+ return re.sub(r'([a-zA-Z])([A-Z])', r'\1-\2', enum_name).lower()
+
tyoshino (SeeGerritForStatus) 2014/05/08 08:06:53 ditto
Mike Lawther (Google) 2014/05/09 01:11:03 Done.
+def read_css_properties(filename):
+ # Read the file as a list of lines
+ with open(filename) as f:
+ content = f.readlines()
+
+ # Looking for a line like "case CSSPropertyGrid: return 453;"
+ bucket_finder = re.compile(r'.*CSSProperty(.*):\s*return\s*([0-9]+).*')
+
+ bucket_dict = {}
+ for line in content:
+ bucket_match = bucket_finder.match(line)
+ if bucket_match:
+ css_property = bucket_match.group(1)
+ bucket = int(bucket_match.group(2))
+ bucket_dict[bucket] = enum_to_css(css_property)
tyoshino (SeeGerritForStatus) 2014/05/08 08:06:53 this call looks weird. how about s/css_property/e
Mike Lawther (Google) 2014/05/09 01:11:03 Done.
+
+ return bucket_dict
+
tyoshino (SeeGerritForStatus) 2014/05/08 08:06:53 ditto
Mike Lawther (Google) 2014/05/09 01:11:03 Done.
+if __name__ == '__main__':
+ parser = optparse.OptionParser()
Mike Lawther (Google) 2014/05/08 07:29:50 Is it worth factoring these lines out somewhere?
+ parser.add_option('--for-dashboard', action='store_true', dest='dashboard',
+ default=False,
+ help='Print enum definition formatted for use in uma.py of '
+ 'Chromium dashboard developed at '
+ 'https://github.com/GoogleChrome/chromium-dashboard')
+ options, args = parser.parse_args()
+
+ if options.dashboard:
+ enum_dict = read_css_properties(USE_COUNTER_CPP_PATH)
+ print_enum_for_dashboard(enum_dict)
+ else:
+ UpdateHistogramFromDict(
+ 'MappedCSSProperties', read_css_properties(USE_COUNTER_CPP_PATH),
tyoshino (SeeGerritForStatus) 2014/05/08 08:06:53 4 space indentation
Mike Lawther (Google) 2014/05/09 01:11:03 Done.
+ USE_COUNTER_CPP_PATH)

Powered by Google App Engine
This is Rietveld 408576698