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

Side by Side Diff: tools/metrics/histograms/print_style.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 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 """Holds the constants for pretty printing histograms.xml.""" 5 """Holds the constants for pretty printing histograms.xml."""
6 6
7 import os 7 import os
8 import sys 8 import sys
9 9
10 # Import the metrics/common module for pretty print xml. 10 # Import the metrics/common module for pretty print xml.
11 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common')) 11 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common'))
12 import pretty_print_xml 12 import pretty_print_xml
13 13
14 # Desired order for tag and tag attributes. The *_ATTRIBUTE_ORDER maps are also 14 # Desired order for tag and tag attributes. The *_ATTRIBUTE_ORDER maps are also
15 # used to determine the validity of tag names. 15 # used to determine the validity of tag names.
16 # { tag_name: [attribute_name, ...] } 16 # { tag_name: [attribute_name, ...] }
17 ATTRIBUTE_ORDER = { 17 ATTRIBUTE_ORDER = {
18 'affected-histogram': ['name'], 18 'affected-histogram': ['name'],
19 'details': [], 19 'details': [],
20 'enum': ['name', 'type'], 20 'enum': ['name'],
21 'enums': [], 21 'enums': [],
22 'histogram': ['base', 'name', 'enum', 'units'], 22 'histogram': ['base', 'name', 'enum', 'units'],
23 'histogram-configuration': ['logsource'], 23 'histogram-configuration': ['logsource'],
24 'histogram_suffixes': ['name', 'separator', 'ordering'], 24 'histogram-suffixes': ['name', 'separator', 'ordering'],
25 'histogram_suffixes_list': [], 25 'histogram-suffixes-list': [],
26 'histograms': [], 26 'histograms': [],
27 'int': ['value', 'label'], 27 'int': ['value', 'label'],
28 'obsolete': [], 28 'obsolete': [],
29 'owner': [], 29 'owner': [],
30 'suffix': ['base', 'name', 'label'], 30 'suffix': ['base', 'name', 'label'],
31 'summary': [], 31 'summary': [],
32 'with-suffix': ['name'], 32 'with-suffix': ['name'],
33 } 33 }
34 34
35 # Attribute names that must be explicitly specified on nodes that support them.
36 REQUIRED_ATTRIBUTES = [
37 # TODO(isherman): Make the 'label' attribute required as well. This requires
38 # fixing up existing suffixes that omit a label.
39 'name',
40 'separator',
41 'value',
42 ]
43
35 # Tag names for top-level nodes whose children we don't want to indent. 44 # Tag names for top-level nodes whose children we don't want to indent.
36 TAGS_THAT_DONT_INDENT = [ 45 TAGS_THAT_DONT_INDENT = [
37 'histogram-configuration', 46 'histogram-configuration',
38 'histograms', 47 'histograms',
39 'histogram_suffixes_list', 48 'histogram-suffixes-list',
40 'enums', 49 'enums',
41 ] 50 ]
42 51
43 # Extra vertical spacing rules for special tag names. 52 # Extra vertical spacing rules for special tag names.
44 # {tag_name: (newlines_after_open, newlines_before_close, newlines_after_close)} 53 # {tag_name: (newlines_after_open, newlines_before_close, newlines_after_close)}
45 TAGS_THAT_HAVE_EXTRA_NEWLINE = { 54 TAGS_THAT_HAVE_EXTRA_NEWLINE = {
46 'histogram-configuration': (2, 1, 1), 55 'histogram-configuration': (2, 1, 1),
47 'histograms': (2, 1, 1), 56 'histograms': (2, 1, 1),
48 'histogram_suffixes_list': (2, 1, 1), 57 'histogram-suffixes-list': (2, 1, 1),
49 'histogram_suffixes': (1, 1, 1), 58 'histogram-suffixes': (1, 1, 1),
50 'enums': (2, 1, 1), 59 'enums': (2, 1, 1),
51 'histogram': (1, 1, 1), 60 'histogram': (1, 1, 1),
52 'enum': (1, 1, 1), 61 'enum': (1, 1, 1),
53 } 62 }
54 63
55 # Tags that we allow to be squished into a single line for brevity. 64 # Tags that we allow to be squished into a single line for brevity.
56 TAGS_THAT_ALLOW_SINGLE_LINE = ['summary', 'int', 'owner'] 65 TAGS_THAT_ALLOW_SINGLE_LINE = ['summary', 'int', 'owner']
57 66
58 LOWERCASE_NAME_FN = lambda n: n.attributes['name'].value.lower() 67 LOWERCASE_NAME_FN = lambda n: n.attributes['name'].value.lower()
59 68
60 # Tags whose children we want to alphabetize. The key is the parent tag name, 69 # Tags whose children we want to alphabetize. The key is the parent tag name,
61 # and the value is a pair of the tag name of the children we want to sort, 70 # and the value is a pair of the tag name of the children we want to sort,
62 # and a key function that maps each child node to the desired sort key. 71 # and a key function that maps each child node to the desired sort key.
63 TAGS_ALPHABETIZATION_RULES = { 72 TAGS_ALPHABETIZATION_RULES = {
64 'histograms': ('histogram', LOWERCASE_NAME_FN), 73 'histograms': ('histogram', LOWERCASE_NAME_FN),
65 'enums': ('enum', LOWERCASE_NAME_FN), 74 'enums': ('enum', LOWERCASE_NAME_FN),
66 'enum': ('int', lambda n: int(n.attributes['value'].value)), 75 'enum': ('int', lambda n: int(n.attributes['value'].value)),
67 'histogram_suffixes_list': ('histogram_suffixes', LOWERCASE_NAME_FN), 76 'histogram-suffixes-list': ('histogram-suffixes', LOWERCASE_NAME_FN),
68 'histogram_suffixes': ('affected-histogram', LOWERCASE_NAME_FN), 77 'histogram-suffixes': ('affected-histogram', LOWERCASE_NAME_FN),
69 } 78 }
70 79
71 80
72 def GetPrintStyle(): 81 def GetPrintStyle():
73 """Returns an XmlStyle object for pretty printing histograms.""" 82 """Returns an XmlStyle object for pretty printing histograms."""
74 return pretty_print_xml.XmlStyle(ATTRIBUTE_ORDER, 83 return pretty_print_xml.XmlStyle(ATTRIBUTE_ORDER,
84 REQUIRED_ATTRIBUTES,
75 TAGS_THAT_HAVE_EXTRA_NEWLINE, 85 TAGS_THAT_HAVE_EXTRA_NEWLINE,
76 TAGS_THAT_DONT_INDENT, 86 TAGS_THAT_DONT_INDENT,
77 TAGS_THAT_ALLOW_SINGLE_LINE, 87 TAGS_THAT_ALLOW_SINGLE_LINE,
78 TAGS_ALPHABETIZATION_RULES) 88 TAGS_ALPHABETIZATION_RULES)
OLDNEW
« tools/metrics/common/pretty_print_xml.py ('K') | « tools/metrics/histograms/histograms.xml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698