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

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

Issue 1020313002: Add support for obsoleting individual histogram suffixes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 enum_name = histogram.getAttribute('enum') 284 enum_name = histogram.getAttribute('enum')
285 if enum_name not in enums: 285 if enum_name not in enums:
286 logging.error('Unknown enum %s in histogram %s', enum_name, name) 286 logging.error('Unknown enum %s in histogram %s', enum_name, name)
287 have_errors = True 287 have_errors = True
288 else: 288 else:
289 histogram_entry['enum'] = enums[enum_name] 289 histogram_entry['enum'] = enums[enum_name]
290 290
291 return histograms, have_errors 291 return histograms, have_errors
292 292
293 293
294 # Finds an <obsolete> node amongst |node|'s immediate children and returns its
295 # content as a string. Returns None if no such node exists.
296 def _GetObsoleteReason(node):
297 for child in node.childNodes:
298 if child.localName == 'obsolete':
299 # There can be at most 1 obsolete element per node.
300 return _JoinChildNodes(child)
301 return None
302
303
294 def _UpdateHistogramsWithSuffixes(tree, histograms): 304 def _UpdateHistogramsWithSuffixes(tree, histograms):
295 """Process <histogram_suffixes> tags and combine with affected histograms. 305 """Process <histogram_suffixes> tags and combine with affected histograms.
296 306
297 The histograms dictionary will be updated in-place by adding new histograms 307 The histograms dictionary will be updated in-place by adding new histograms
298 created by combining histograms themselves with histogram_suffixes targeting 308 created by combining histograms themselves with histogram_suffixes targeting
299 these histograms. 309 these histograms.
300 310
301 Args: 311 Args:
302 tree: XML dom tree. 312 tree: XML dom tree.
303 histograms: a dictionary of histograms previously extracted from the tree; 313 histograms: a dictionary of histograms previously extracted from the tree;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 if reprocess_count < MAX_HISTOGRAM_SUFFIX_DEPENDENCY_DEPTH: 358 if reprocess_count < MAX_HISTOGRAM_SUFFIX_DEPENDENCY_DEPTH:
349 reprocess_queue.append((reprocess_count + 1, histogram_suffixes)) 359 reprocess_queue.append((reprocess_count + 1, histogram_suffixes))
350 continue 360 continue
351 else: 361 else:
352 logging.error('histogram_suffixes %s is missing its dependency %s', 362 logging.error('histogram_suffixes %s is missing its dependency %s',
353 histogram_suffixes.getAttribute('name'), 363 histogram_suffixes.getAttribute('name'),
354 missing_dependency) 364 missing_dependency)
355 have_errors = True 365 have_errors = True
356 continue 366 continue
357 367
358 obsolete_nodes = histogram_suffixes.getElementsByTagName('obsolete') 368 # If the suffix group has an obsolete tag, all suffixes it generates inherit
359 obsolete_reason = None 369 # its reason.
360 if obsolete_nodes: 370 group_obsolete_reason = _GetObsoleteReason(histogram_suffixes)
361 # There can be at most 1 obsolete element per histogram_suffixes node
362 obsolete_reason = _JoinChildNodes(obsolete_nodes[0])
363 371
364 name = histogram_suffixes.getAttribute('name') 372 name = histogram_suffixes.getAttribute('name')
365 suffix_nodes = histogram_suffixes.getElementsByTagName(suffix_tag) 373 suffix_nodes = histogram_suffixes.getElementsByTagName(suffix_tag)
366 suffix_labels = {} 374 suffix_labels = {}
367 for suffix in suffix_nodes: 375 for suffix in suffix_nodes:
368 suffix_labels[suffix.getAttribute('name')] = suffix.getAttribute('label') 376 suffix_labels[suffix.getAttribute('name')] = suffix.getAttribute('label')
369 # Find owners list under current histogram_suffixes tag. 377 # Find owners list under current histogram_suffixes tag.
370 owners = _ExtractOwners(histogram_suffixes) 378 owners = _ExtractOwners(histogram_suffixes)
371 379
372 last_histogram_name = None 380 last_histogram_name = None
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 if 'fieldtrial_labels' not in histograms[new_histogram_name]: 417 if 'fieldtrial_labels' not in histograms[new_histogram_name]:
410 histograms[new_histogram_name]['fieldtrial_labels'] = [] 418 histograms[new_histogram_name]['fieldtrial_labels'] = []
411 histograms[new_histogram_name]['fieldtrial_labels'].append( 419 histograms[new_histogram_name]['fieldtrial_labels'].append(
412 suffix_label) 420 suffix_label)
413 421
414 # If no owners are added for this histogram-suffixes, it inherits the 422 # If no owners are added for this histogram-suffixes, it inherits the
415 # owners of its parents. 423 # owners of its parents.
416 if owners: 424 if owners:
417 histograms[new_histogram_name]['owners'] = owners 425 histograms[new_histogram_name]['owners'] = owners
418 426
427 # If a suffix has an obsolete node, it's marked as obsolete for the
428 # specified reason, overwriting its group's obsoletion reason if the
429 # group itself was obsolete as well.
430 obsolete_reason = _GetObsoleteReason(suffix)
431 if not obsolete_reason:
432 obsolete_reason = group_obsolete_reason
433
419 # If the suffix has an obsolete tag, all histograms it generates 434 # If the suffix has an obsolete tag, all histograms it generates
420 # inherit it. 435 # inherit it.
421 if obsolete_reason: 436 if obsolete_reason:
422 histograms[new_histogram_name]['obsolete'] = obsolete_reason 437 histograms[new_histogram_name]['obsolete'] = obsolete_reason
423 438
424 except Error: 439 except Error:
425 have_errors = True 440 have_errors = True
426 441
427 return have_errors 442 return have_errors
428 443
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 with open(filename, 'r') as f: 478 with open(filename, 'r') as f:
464 histograms, had_errors = ExtractHistogramsFromFile(f) 479 histograms, had_errors = ExtractHistogramsFromFile(f)
465 if had_errors: 480 if had_errors:
466 logging.error('Error parsing %s', filename) 481 logging.error('Error parsing %s', filename)
467 raise Error() 482 raise Error()
468 return histograms 483 return histograms
469 484
470 485
471 def ExtractNames(histograms): 486 def ExtractNames(histograms):
472 return sorted(histograms.keys()) 487 return sorted(histograms.keys())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698