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

Side by Side Diff: tools/metrics/histograms/extract_histograms.py

Issue 2890013004: Clean up histograms.xml formatting
Patch Set: Created 3 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
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Extract histogram names from the description XML file. 5 """Extract histogram names from the description XML file.
6 6
7 For more information on the format of the XML file, which is self-documenting, 7 For more information on the format of the XML file, which is self-documenting,
8 see histograms.xml; however, here is a simple example to get you started. The 8 see histograms.xml; however, here is a simple example to get you started. The
9 XML below will generate the following five histograms: 9 XML below will generate the following five histograms:
10 10
(...skipping 21 matching lines...) Expand all
32 <enums> 32 <enums>
33 33
34 <enum name="MyEnumType"> 34 <enum name="MyEnumType">
35 <summary>This is an example enum type, where the values mean little.</summary> 35 <summary>This is an example enum type, where the values mean little.</summary>
36 <int value="1" label="FIRST_VALUE">This is the first value.</int> 36 <int value="1" label="FIRST_VALUE">This is the first value.</int>
37 <int value="2" label="SECOND_VALUE">This is the second value.</int> 37 <int value="2" label="SECOND_VALUE">This is the second value.</int>
38 </enum> 38 </enum>
39 39
40 </enums> 40 </enums>
41 41
42 <histogram_suffixes_list> 42 <histogram-suffixes-list>
43 43
44 <histogram_suffixes name="BrowserType"> 44 <histogram-suffixes name="BrowserType">
45 <suffix name="Chrome"/> 45 <suffix name="Chrome"/>
46 <suffix name="IE"/> 46 <suffix name="IE"/>
47 <suffix name="Firefox"/> 47 <suffix name="Firefox"/>
48 <affected-histogram name="HistogramEnum"/> 48 <affected-histogram name="HistogramEnum"/>
49 </histogram_suffixes> 49 </histogram-suffixes>
50 50
51 </histogram_suffixes_list> 51 </histogram-suffixes-list>
52 52
53 </histogram-configuration> 53 </histogram-configuration>
54 54
55 """ 55 """
56 56
57 import bisect 57 import bisect
58 import copy 58 import copy
59 import logging 59 import logging
60 import xml.dom.minidom 60 import xml.dom.minidom
61 61
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 178
179 def _ExtractEnumsFromXmlTree(tree): 179 def _ExtractEnumsFromXmlTree(tree):
180 """Extract all <enum> nodes in the tree into a dictionary.""" 180 """Extract all <enum> nodes in the tree into a dictionary."""
181 181
182 enums = {} 182 enums = {}
183 have_errors = False 183 have_errors = False
184 184
185 last_name = None 185 last_name = None
186 for enum in tree.getElementsByTagName('enum'): 186 for enum in tree.getElementsByTagName('enum'):
187 if enum.getAttribute('type') != 'int':
188 logging.error('Unknown enum type %s', enum.getAttribute('type'))
189 have_errors = True
190 continue
191
192 name = enum.getAttribute('name') 187 name = enum.getAttribute('name')
193 if last_name is not None and name.lower() < last_name.lower(): 188 if last_name is not None and name.lower() < last_name.lower():
194 logging.error('Enums %s and %s are not in alphabetical order', 189 logging.error('Enums %s and %s are not in alphabetical order',
195 last_name, name) 190 last_name, name)
196 have_errors = True 191 have_errors = True
197 last_name = name 192 last_name = name
198 193
199 if name in enums: 194 if name in enums:
200 logging.error('Duplicate enum %s', name) 195 logging.error('Duplicate enum %s', name)
201 have_errors = True 196 have_errors = True
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 tree = xml.dom.minidom.parse(f) 519 tree = xml.dom.minidom.parse(f)
525 histograms, had_errors = ExtractHistogramsFromDom(tree) 520 histograms, had_errors = ExtractHistogramsFromDom(tree)
526 if had_errors: 521 if had_errors:
527 logging.error('Error parsing %s', filename) 522 logging.error('Error parsing %s', filename)
528 raise Error() 523 raise Error()
529 return histograms 524 return histograms
530 525
531 526
532 def ExtractNames(histograms): 527 def ExtractNames(histograms):
533 return sorted(histograms.keys()) 528 return sorted(histograms.keys())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698