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

Side by Side Diff: tools/metrics/histograms/update_histogram_enum.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: made update_use_counter_css.py executable 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
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 """Updates enums in histograms.xml file with values read from provided C++ enum. 5 """Updates enums in histograms.xml file with values read from provided C++ enum.
6 6
7 If the file was pretty-printed, the updated version is pretty-printed too. 7 If the file was pretty-printed, the updated version is pretty-printed too.
8 """ 8 """
9 9
10 import logging 10 import logging
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 new_children.append( 129 new_children.append(
130 CreateEnumItemNode(document, value, source_enum_values[value])) 130 CreateEnumItemNode(document, value, source_enum_values[value]))
131 131
132 # Update |enum_node|. 132 # Update |enum_node|.
133 while enum_node.hasChildNodes(): 133 while enum_node.hasChildNodes():
134 enum_node.removeChild(enum_node.lastChild) 134 enum_node.removeChild(enum_node.lastChild)
135 for child in new_children: 135 for child in new_children:
136 enum_node.appendChild(child) 136 enum_node.appendChild(child)
137 137
138 138
139 def UpdateHistogramEnum(histogram_enum_name, source_enum_path, 139 def UpdateHistogramFromDict(histogram_enum_name, source_enum_values,
140 start_marker, end_marker): 140 source_enum_path):
141 """Updates |histogram_enum_name| enum in histograms.xml file with values 141 """Updates |histogram_enum_name| enum in histograms.xml file with values
142 read from |source_enum_path|, where |start_marker| and |end_marker| indicate 142 from the {value: 'key'} dictionary |source_enum_values|. A comment is added
143 the beginning and end of the source enum definition, respectively. 143 to histograms.xml citing that the values in |histogram_enum_name| were
144 sourced from |source_enum_path|.
144 """ 145 """
145 # TODO(ahernandez.miralles): The line below is present in nearly every 146 # TODO(ahernandez.miralles): The line below is present in nearly every
146 # file in this directory; factor out into a central location 147 # file in this directory; factor out into a central location
147 HISTOGRAMS_PATH = 'histograms.xml' 148 HISTOGRAMS_PATH = 'histograms.xml'
148 149
149 Log('Reading histogram enum definition from "{0}".'.format(source_enum_path))
150 source_enum_values = ReadHistogramValues(source_enum_path, start_marker,
151 end_marker)
152
153 Log('Reading existing histograms from "{0}".'.format(HISTOGRAMS_PATH)) 150 Log('Reading existing histograms from "{0}".'.format(HISTOGRAMS_PATH))
154 with open(HISTOGRAMS_PATH, 'rb') as f: 151 with open(HISTOGRAMS_PATH, 'rb') as f:
155 histograms_doc = minidom.parse(f) 152 histograms_doc = minidom.parse(f)
156 f.seek(0) 153 f.seek(0)
157 xml = f.read() 154 xml = f.read()
158 155
159 Log('Comparing histograms enum with new enum definition.') 156 Log('Comparing histograms enum with new enum definition.')
160 UpdateHistogramDefinitions(histogram_enum_name, source_enum_values, 157 UpdateHistogramDefinitions(histogram_enum_name, source_enum_values,
161 source_enum_path, histograms_doc) 158 source_enum_path, histograms_doc)
162 159
163 Log('Writing out new histograms file.') 160 Log('Writing out new histograms file.')
164 new_xml = print_style.GetPrintStyle().PrettyPrintNode(histograms_doc) 161 new_xml = print_style.GetPrintStyle().PrettyPrintNode(histograms_doc)
165 if not PromptUserToAcceptDiff( 162 if not PromptUserToAcceptDiff(
166 xml, new_xml, 'Is the updated version acceptable?'): 163 xml, new_xml, 'Is the updated version acceptable?'):
167 Log('Cancelled.') 164 Log('Cancelled.')
168 return 165 return
169 166
170 with open(HISTOGRAMS_PATH, 'wb') as f: 167 with open(HISTOGRAMS_PATH, 'wb') as f:
171 f.write(new_xml) 168 f.write(new_xml)
172 169
173 Log('Done.') 170 Log('Done.')
171
172
173 def UpdateHistogramEnum(histogram_enum_name, source_enum_path,
174 start_marker, end_marker):
175 """Updates |histogram_enum_name| enum in histograms.xml file with values
176 read from |source_enum_path|, where |start_marker| and |end_marker| indicate
177 the beginning and end of the source enum definition, respectively.
178 """
179
180 Log('Reading histogram enum definition from "{0}".'.format(source_enum_path))
181 source_enum_values = ReadHistogramValues(source_enum_path, start_marker,
182 end_marker)
183
184 UpdateHistogramFromDict(histogram_enum_name, source_enum_values,
185 source_enum_path)
OLDNEW
« no previous file with comments | « tools/metrics/histograms/histograms.xml ('k') | tools/metrics/histograms/update_use_counter_css.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698