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

Side by Side 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: fixed whitespace issues 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 unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Scans the Chromium source of UseCounter, formats the Feature enum for
7 histograms.xml and merges it. This script can also generate a python code
8 snippet to put in uma.py of Chromium Dashboard. Make sure that you review the
9 output for correctness.
10 """
11
12 import optparse
13 import os
14 import re
15 import sys
16
17 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common'))
18 from update_histogram_enum import ReadHistogramValues
19 from update_histogram_enum import UpdateHistogramFromDict
20 from update_use_counter_feature_enum import print_enum_for_dashboard
21
22
23 USE_COUNTER_CPP_PATH = \
24 '../../../third_party/WebKit/Source/core/frame/UseCounter.cpp'
25
26
27 def enum_to_css_property(enum_name):
28 """Converts a camel cased enum name to the lower case CSS property."""
29 return re.sub(r'([a-zA-Z])([A-Z])', r'\1-\2', enum_name).lower()
Ilya Sherman 2014/05/13 03:11:33 Hmm, why does the first captured group have upperc
Mike Lawther (Google) 2014/05/20 07:45:03 Good question! This was to deal with the property
Ilya Sherman 2014/05/20 14:13:17 Hmm, how odd. Could you please add a comment expl
Mike Lawther (Google) 2014/05/21 07:30:41 Done.
30
31
32 def read_css_properties(filename):
Ilya Sherman 2014/05/13 03:11:33 nit: I think function names are supposed to be wri
Mike Lawther (Google) 2014/05/20 07:45:03 Oh OK. I'd seen others in lower case (eg in update
33 # Read the file as a list of lines
34 with open(filename) as f:
35 content = f.readlines()
36
37 # Looking for a line like "case CSSPropertyGrid: return 453;"
38 bucket_finder = re.compile(r'.*CSSProperty(.*):\s*return\s*([0-9]+).*')
Ilya Sherman 2014/05/13 03:11:33 nit: Could you write this as a multi-line regex, s
Ilya Sherman 2014/05/13 03:11:33 nit: Do you really need the leading and trailing .
Ilya Sherman 2014/05/13 03:11:33 Optional nit: I'd name this something like PROPERT
Mike Lawther (Google) 2014/05/20 07:45:03 Did you mean break the regex string itself out and
Mike Lawther (Google) 2014/05/20 07:45:03 As in use re.MULTILINE so I can use ^ and $? Now t
Mike Lawther (Google) 2014/05/20 07:45:03 No. Removed. I had them there because I was using
Ilya Sherman 2014/05/20 14:13:17 I meant the compiled regex.
Ilya Sherman 2014/05/20 14:13:17 I meant using verbose mode: https://docs.python.or
Mike Lawther (Google) 2014/05/21 07:30:41 Done. I called it 'ENUM_REGEX', as that's what it'
Mike Lawther (Google) 2014/05/21 07:30:41 Gotcha. Done.
39
40 bucket_dict = {}
Ilya Sherman 2014/05/13 03:11:33 Optional nit: I'd name this "properties"
Mike Lawther (Google) 2014/05/20 07:45:03 Agreed. I also changed some of the other names in
Ilya Sherman 2014/05/20 14:13:17 LG, thanks :)
41 for line in content:
42 bucket_match = bucket_finder.match(line)
43 if bucket_match:
44 enum_name = bucket_match.group(1)
Ilya Sherman 2014/05/13 03:11:33 Optional nit: I'd name this "property"
Mike Lawther (Google) 2014/05/20 07:45:03 I've left this as 'enum_name', because later down
Ilya Sherman 2014/05/20 14:13:17 Ok.
45 bucket = int(bucket_match.group(2))
46 bucket_dict[bucket] = enum_to_css_property(enum_name)
47
48 return bucket_dict
49
50
51 if __name__ == '__main__':
52 parser = optparse.OptionParser()
53 parser.add_option('--for-dashboard', action='store_true', dest='dashboard',
54 default=False,
55 help='Print enum definition formatted for use in uma.py of '
56 'Chromium dashboard developed at '
57 'https://github.com/GoogleChrome/chromium-dashboard')
58 options, args = parser.parse_args()
59
60 if options.dashboard:
61 enum_dict = read_css_properties(USE_COUNTER_CPP_PATH)
62 print_enum_for_dashboard(enum_dict)
63 else:
64 UpdateHistogramFromDict(
65 'MappedCSSProperties', read_css_properties(USE_COUNTER_CPP_PATH),
66 USE_COUNTER_CPP_PATH)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698