Chromium Code Reviews| Index: tools/metrics/histograms/extract_histograms.py |
| diff --git a/tools/metrics/histograms/extract_histograms.py b/tools/metrics/histograms/extract_histograms.py |
| index b8e49ad310e0a73b51870bf3f8d2693928cf87ed..95f989f6b981faf2e88194c2ebe18f9f1ddd807d 100644 |
| --- a/tools/metrics/histograms/extract_histograms.py |
| +++ b/tools/metrics/histograms/extract_histograms.py |
| @@ -63,6 +63,9 @@ OWNER_FIELD_PLACEHOLDER = ( |
| MAX_HISTOGRAM_SUFFIX_DEPENDENCY_DEPTH = 5 |
| +DEFAULT_BASE_HISTOGRAM_OBSOLETE_REASON = ( |
| + 'Base histogram. Use suffixes of this histogram instead.') |
| + |
| class Error(Exception): |
| pass |
| @@ -230,6 +233,14 @@ def _ExtractOwners(xml_node): |
| return owners |
| +def _ProcessBaseHistogramAttribute(node, histogram_entry): |
| + if node.hasAttribute('base'): |
| + is_base = node.getAttribute('base').lower() == 'true' |
| + histogram_entry['base'] = is_base |
| + if is_base and 'obsolete' not in histogram_entry: |
| + histogram_entry['obsolete'] = DEFAULT_BASE_HISTOGRAM_OBSOLETE_REASON |
| + |
| + |
| def _ExtractHistogramsFromXmlTree(tree, enums): |
| """Extract all <histogram> nodes in the tree into a dictionary.""" |
| @@ -288,6 +299,8 @@ def _ExtractHistogramsFromXmlTree(tree, enums): |
| else: |
| histogram_entry['enum'] = enums[enum_name] |
| + _ProcessBaseHistogramAttribute(histogram, histogram_entry) |
| + |
| return histograms, have_errors |
| @@ -398,8 +411,16 @@ def _UpdateHistogramsWithSuffixes(tree, histograms): |
| new_histogram_name = _ExpandHistogramNameWithSuffixes( |
| suffix_name, histogram_name, histogram_suffixes) |
| if new_histogram_name != histogram_name: |
| - histograms[new_histogram_name] = copy.deepcopy( |
| - histograms[histogram_name]) |
| + new_histogram = copy.deepcopy(histograms[histogram_name]) |
| + # Do not copy forward base histogram state to suffixed |
| + # histograms. Any suffixed histograms that wish to remain base |
| + # histogram must explicitly declare themselves as base histograms. |
|
Ilya Sherman
2016/10/18 21:05:58
nit: s/histogram/histograms
Bryan McQuade
2016/10/18 23:15:19
done, thanks!
|
| + if new_histogram.get('base', False): |
| + del new_histogram['base'] |
| + if (new_histogram.get('obsolete', '') == |
| + DEFAULT_BASE_HISTOGRAM_OBSOLETE_REASON): |
| + del new_histogram['obsolete'] |
| + histograms[new_histogram_name] = new_histogram |
| suffix_label = suffix_labels.get(suffix_name, '') |
| @@ -436,6 +457,8 @@ def _UpdateHistogramsWithSuffixes(tree, histograms): |
| if obsolete_reason: |
| histograms[new_histogram_name]['obsolete'] = obsolete_reason |
| + _ProcessBaseHistogramAttribute(suffix, histograms[new_histogram_name]) |
| + |
| except Error: |
| have_errors = True |