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 sys | 14 import sys |
15 | 15 |
16 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common')) | 16 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common')) |
17 from update_histogram_enum import ReadHistogramValues | 17 from update_histogram_enum import ReadHistogramValues |
18 from update_histogram_enum import UpdateHistogramEnum | 18 from update_histogram_enum import UpdateHistogramEnum |
19 | 19 |
20 USE_COUNTER_HEADER_PATH = \ | |
21 '../../../third_party/WebKit/Source/core/frame/UseCounter.h' | |
22 | 20 |
23 | 21 def PrintEnumForDashboard(enum_dict): |
24 def print_enum_for_dashboard(enum_dict): | |
25 """Prints enum_items formatted for use in uma.py of Chromium dashboard.""" | 22 """Prints enum_items formatted for use in uma.py of Chromium dashboard.""" |
26 for key in sorted(enum_dict.iterkeys()): | 23 for key in sorted(enum_dict.iterkeys()): |
27 print ' %d: \'%s\',' % (key, enum_dict[key]) | 24 print ' %d: \'%s\',' % (key, enum_dict[key]) |
28 | 25 |
29 | 26 |
30 if __name__ == '__main__': | 27 if __name__ == '__main__': |
31 parser = optparse.OptionParser() | 28 parser = optparse.OptionParser() |
32 parser.add_option('--for-dashboard', action='store_true', dest='dashboard', | 29 parser.add_option('--for-dashboard', action='store_true', dest='dashboard', |
33 default=False, | 30 default=False, |
34 help='Print enum definition formatted for use in uma.py of ' | 31 help='Print enum definition formatted for use in uma.py of ' |
35 'Chromium dashboard developed at ' | 32 'Chromium dashboard developed at ' |
36 'https://github.com/GoogleChrome/chromium-dashboard') | 33 'https://github.com/GoogleChrome/chromium-dashboard') |
37 options, args = parser.parse_args() | 34 options, args = parser.parse_args() |
38 | 35 |
| 36 source_path = os.path.join( |
| 37 '..', '..', '..', |
| 38 'third_party', 'WebKit', 'Source', 'core', 'frame', 'UseCounter.h') |
| 39 |
39 START_MARKER = '^enum Feature {' | 40 START_MARKER = '^enum Feature {' |
40 END_MARKER = '^NumberOfFeatures' | 41 END_MARKER = '^NumberOfFeatures' |
41 | 42 |
42 if options.dashboard: | 43 if options.dashboard: |
43 enum_dict = ReadHistogramValues( | 44 enum_dict = ReadHistogramValues(source_path, START_MARKER, END_MARKER) |
44 USE_COUNTER_HEADER_PATH, START_MARKER, END_MARKER) | 45 PrintEnumForDashboard(enum_dict) |
45 print_enum_for_dashboard(enum_dict) | |
46 else: | 46 else: |
47 UpdateHistogramEnum( | 47 UpdateHistogramEnum( |
48 histogram_enum_name='FeatureObserver', | 48 histogram_enum_name='FeatureObserver', |
49 source_enum_path=USE_COUNTER_HEADER_PATH, | 49 source_enum_path=source_path, |
50 start_marker=START_MARKER, | 50 start_marker=START_MARKER, |
51 end_marker=END_MARKER) | 51 end_marker=END_MARKER) |
OLD | NEW |