| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Scans the Chromium source of UseCounter, formats the Feature enum for | 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 | 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 | 8 snippet to put in uma.py of Chromium Dashboard. Make sure that you review the |
| 9 output for correctness. | 9 output for correctness. |
| 10 """ | 10 """ |
| 11 | 11 |
| 12 import optparse | 12 import optparse |
| 13 import os | 13 import os |
| 14 import re | 14 import re |
| 15 import sys | 15 import sys |
| 16 | 16 |
| 17 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common')) | 17 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) # tools/metrics |
| 18 from update_histogram_enum import ReadHistogramValues | 18 from common import path_util |
| 19 from update_histogram_enum import UpdateHistogramFromDict | 19 from histograms import update_histogram_enum |
| 20 from update_use_counter_feature_enum import PrintEnumForDashboard | 20 from histograms import update_use_counter_feature_enum |
| 21 | 21 |
| 22 | 22 |
| 23 USE_COUNTER_CPP_PATH = \ | 23 USE_COUNTER_CPP_PATH = 'third_party/WebKit/Source/core/frame/UseCounter.cpp' |
| 24 '../../../third_party/WebKit/Source/core/frame/UseCounter.cpp' | |
| 25 | 24 |
| 26 | 25 |
| 27 def EnumToCssProperty(enum_name): | 26 def EnumToCssProperty(enum_name): |
| 28 """Converts a camel cased enum name to the lower case CSS property.""" | 27 """Converts a camel cased enum name to the lower case CSS property.""" |
| 29 # The first group also searches for uppercase letters to account for single | 28 # The first group also searches for uppercase letters to account for single |
| 30 # uppercase letters, such as in "ZIndex" that need to convert to "z-index". | 29 # uppercase letters, such as in "ZIndex" that need to convert to "z-index". |
| 31 return re.sub(r'([a-zA-Z])([A-Z])', r'\1-\2', enum_name).lower() | 30 return re.sub(r'([a-zA-Z])([A-Z])', r'\1-\2', enum_name).lower() |
| 32 | 31 |
| 33 | 32 |
| 34 def ReadCssProperties(filename): | 33 def ReadCssProperties(filename): |
| 35 # Read the file as a list of lines | 34 # Read the file as a list of lines |
| 36 with open(filename) as f: | 35 with open(path_util.GetInputFile(filename)) as f: |
| 37 content = f.readlines() | 36 content = f.readlines() |
| 38 | 37 |
| 39 # Looking for a line like "case CSSPropertyGrid: return 453;". | 38 # Looking for a line like "case CSSPropertyGrid: return 453;". |
| 40 ENUM_REGEX = re.compile(r"""CSSProperty(.*): # capture the enum name | 39 ENUM_REGEX = re.compile(r"""CSSProperty(.*): # capture the enum name |
| 41 \s*return\s* | 40 \s*return\s* |
| 42 ([0-9]+) # capture the id | 41 ([0-9]+) # capture the id |
| 43 """, re.VERBOSE) | 42 """, re.VERBOSE) |
| 44 | 43 |
| 45 properties = {} | 44 properties = {} |
| 46 for line in content: | 45 for line in content: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 57 parser = optparse.OptionParser() | 56 parser = optparse.OptionParser() |
| 58 parser.add_option('--for-dashboard', action='store_true', dest='dashboard', | 57 parser.add_option('--for-dashboard', action='store_true', dest='dashboard', |
| 59 default=False, | 58 default=False, |
| 60 help='Print enum definition formatted for use in uma.py of ' | 59 help='Print enum definition formatted for use in uma.py of ' |
| 61 'Chromium dashboard developed at ' | 60 'Chromium dashboard developed at ' |
| 62 'https://github.com/GoogleChrome/chromium-dashboard') | 61 'https://github.com/GoogleChrome/chromium-dashboard') |
| 63 options, args = parser.parse_args() | 62 options, args = parser.parse_args() |
| 64 | 63 |
| 65 if options.dashboard: | 64 if options.dashboard: |
| 66 enum_dict = ReadCssProperties(USE_COUNTER_CPP_PATH) | 65 enum_dict = ReadCssProperties(USE_COUNTER_CPP_PATH) |
| 67 PrintEnumForDashboard(enum_dict) | 66 update_use_counter_feature_enum.PrintEnumForDashboard(enum_dict) |
| 68 else: | 67 else: |
| 69 UpdateHistogramFromDict( | 68 update_histogram_enum.UpdateHistogramFromDict( |
| 70 'MappedCSSProperties', ReadCssProperties(USE_COUNTER_CPP_PATH), | 69 'MappedCSSProperties', ReadCssProperties(USE_COUNTER_CPP_PATH), |
| 71 USE_COUNTER_CPP_PATH) | 70 USE_COUNTER_CPP_PATH) |
| OLD | NEW |