Commit 5fde3451 authored by adamta's avatar adamta Committed by Commit Bot

Filter obsolete metrics when generating apis

Filter out any event or metric in ukm.xml that has an <obsolete> tag.
Remove <obsolete> tags from in ukm.xml for metrics still being referenced.

Bug: 1055550
Change-Id: If6538ecd87ddc6a8456c40fe08edd61c77664c37
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2083603
Commit-Queue: Adam Trudeau-Arcaro <adamta@google.com>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746941}
parent 22bf6abb
...@@ -24,12 +24,35 @@ parser.add_argument('--output', help='Path to generated files.') ...@@ -24,12 +24,35 @@ parser.add_argument('--output', help='Path to generated files.')
def main(argv): def main(argv):
args = parser.parse_args() args = parser.parse_args()
data = ukm_model.UKM_XML_TYPE.Parse(open(args.input).read()) data = ReadFilteredData(args.input)
relpath = 'services/metrics/public/cpp/' relpath = 'services/metrics/public/cpp/'
builders_template.WriteFiles(args.output, relpath, data) builders_template.WriteFiles(args.output, relpath, data)
decode_template.WriteFiles(args.output, relpath, data) decode_template.WriteFiles(args.output, relpath, data)
return 0 return 0
def ReadFilteredData(path):
"""Reads data from path and filters out any obsolete metrics.
Parses data from given path and removes all nodes that contain an
<obsolete> tag. First iterates through <event> nodes, then <metric>
nodes within them.
Args:
path: The path of the XML data source.
Returns:
A dict of the data not including any obsolete events or metrics.
"""
with open(path) as ukm_file:
data = ukm_model.UKM_XML_TYPE.Parse(ukm_file.read())
event_tag = ukm_model._EVENT_TYPE.tag
metric_tag = ukm_model._METRIC_TYPE.tag
data[event_tag] = filter(ukm_model.IsNotObsolete, data[event_tag])
for event in data[event_tag]:
event[metric_tag] = filter(ukm_model.IsNotObsolete, event[metric_tag])
return data
if '__main__' == __name__: if '__main__' == __name__:
sys.exit(main(sys.argv)) sys.exit(main(sys.argv))
#!/usr/bin/env python
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import unittest import unittest
from ukm_model import UKM_XML_TYPE
from ukm_model import _EVENT_TYPE
from ukm_model import _METRIC_TYPE
from codegen import EventInfo from codegen import EventInfo
from codegen import MetricInfo from codegen import MetricInfo
from builders_template import HEADER as BUILDERS_HEADER_TEMPLATE from builders_template import HEADER as BUILDERS_HEADER_TEMPLATE
from builders_template import IMPL as BUILDERS_IMPL_TEMPLATE from builders_template import IMPL as BUILDERS_IMPL_TEMPLATE
from decode_template import HEADER as DECODE_HEADER_TEMPLATE from decode_template import HEADER as DECODE_HEADER_TEMPLATE
from decode_template import IMPL as DECODE_IMPL_TEMPLATE from decode_template import IMPL as DECODE_IMPL_TEMPLATE
import ukm_model
import gen_builders
class GenBuildersTest(unittest.TestCase): class GenBuildersTest(unittest.TestCase):
def testFilterObsoleteMetrics(self):
data = gen_builders.ReadFilteredData('../../tools/metrics/ukm/ukm.xml')
for event in data[ukm_model._EVENT_TYPE.tag]:
self.assertTrue(ukm_model.IsNotObsolete(event))
for metric in event[ukm_model._METRIC_TYPE.tag]:
self.assertTrue(ukm_model.IsNotObsolete(metric))
def testGenerateCode(self): def testGenerateCode(self):
relpath = '.' relpath = '.'
data = UKM_XML_TYPE.Parse(open('../../tools/metrics/ukm/ukm.xml').read()) data = ukm_model.UKM_XML_TYPE.Parse(
event = data[_EVENT_TYPE.tag][0] open('../../tools/metrics/ukm/ukm.xml').read())
metric = event[_METRIC_TYPE.tag][0] event = data[ukm_model._EVENT_TYPE.tag][0]
metric = event[ukm_model._METRIC_TYPE.tag][0]
self.assertIsNotNone(event) self.assertIsNotNone(event)
self.assertIsNotNone(metric) self.assertIsNotNone(metric)
eventInfo = EventInfo(event) eventInfo = EventInfo(event)
......
...@@ -1696,13 +1696,11 @@ be describing additional metrics about the same event. ...@@ -1696,13 +1696,11 @@ be describing additional metrics about the same event.
</summary> </summary>
</metric> </metric>
<metric name="ProxyCommit"> <metric name="ProxyCommit">
<obsolete>
Removed February 2020 in favor of separate metrics for the wait time and
the actual commit time.
</obsolete>
<summary> <summary>
The time spent committing main thread to impl layer tree information, The time spent committing main thread to impl layer tree information,
between navigation and First Contentful Paint, in microseconds. between navigation and First Contentful Paint, in microseconds.
TODO(crbug.com/1058065): Should be obsolete. Removed February 2020 in
favor of separate metrics for the wait time and the actual commit time.
</summary> </summary>
</metric> </metric>
<metric name="ScrollingCoordinator"> <metric name="ScrollingCoordinator">
...@@ -2394,13 +2392,11 @@ be describing additional metrics about the same event. ...@@ -2394,13 +2392,11 @@ be describing additional metrics about the same event.
</summary> </summary>
</metric> </metric>
<metric name="ProxyCommit"> <metric name="ProxyCommit">
<obsolete>
Removed February 2020 in favor of separate metrics for the wait time and
the actual commit time.
</obsolete>
<summary> <summary>
The time taken for the proxy to commit to the impl thread in microseconds The time taken for the proxy to commit to the impl thread in microseconds
during the sampled frame. during the sampled frame. TODO(crbug.com/1058065): Should be obsolete.
Removed February 2020 in favor of separate metrics for the wait time and
the actual commit time.
</summary> </summary>
<aggregation> <aggregation>
<history> <history>
...@@ -2412,13 +2408,11 @@ be describing additional metrics about the same event. ...@@ -2412,13 +2408,11 @@ be describing additional metrics about the same event.
</aggregation> </aggregation>
</metric> </metric>
<metric name="ProxyCommitPercentage"> <metric name="ProxyCommitPercentage">
<obsolete>
Removed February 2020 in favor of separate metrics for the wait time and
the actual commit time.
</obsolete>
<summary> <summary>
The percentage of the main frame time used to commit to the impl thread. The percentage of the main frame time used to commit to the impl thread.
An int in the range [0,100]. An int in the range [0,100]. TODO(crbug.com/1058065): Should be obsolete.
Removed February 2020 in favor of separate metrics for the wait time and
the actual commit time.
</summary> </summary>
</metric> </metric>
<metric name="ScrollingCoordinator"> <metric name="ScrollingCoordinator">
...@@ -7470,13 +7464,12 @@ be describing additional metrics about the same event. ...@@ -7470,13 +7464,12 @@ be describing additional metrics about the same event.
</summary> </summary>
</metric> </metric>
<metric name="Net.CacheBytes"> <metric name="Net.CacheBytes">
<obsolete>
Deprecated 06/2019 in favor of Net.CacheBytes2.
</obsolete>
<summary> <summary>
The total number of body bytes loaded from cache for all resources on the The total number of body bytes loaded from cache for all resources on the
page. This is rounded down to the nearest exponential bucket (with a page. This is rounded down to the nearest exponential bucket (with a
bucket spacing factor of 1.3). bucket spacing factor of 1.3). TODO(crbug.com/1058065): Should be
obsolete. Deprecated 06/2019 in favor of Net.CacheBytes2. (seems to be
used in Clang)
</summary> </summary>
</metric> </metric>
<metric name="Net.CacheBytes2"> <metric name="Net.CacheBytes2">
......
...@@ -132,3 +132,8 @@ def PrettifyXML(original_xml): ...@@ -132,3 +132,8 @@ def PrettifyXML(original_xml):
""" """
config = UKM_XML_TYPE.Parse(original_xml) config = UKM_XML_TYPE.Parse(original_xml)
return UKM_XML_TYPE.PrettyPrint(config) return UKM_XML_TYPE.PrettyPrint(config)
def IsNotObsolete(node):
"""Checks if the given node contains a child <obsolete> node."""
return _OBSOLETE_TYPE.tag not in node
...@@ -110,6 +110,25 @@ CONFIG_EVENT_NAMES_UNSORTED = """ ...@@ -110,6 +110,25 @@ CONFIG_EVENT_NAMES_UNSORTED = """
</ukm-configuration> </ukm-configuration>
""".strip() """.strip()
OBSOLETE_EVENTS_PARSED = {
'event': {
"obsolete": "Some message",
"metric": {
"summary": "Some summary",
},
"metric": {
"summary": "Some summary",
},
},
'event': {
"obsolete": "Some message",
"metric": {
"summary": "Some summary",
},
},
}
class UkmXmlTest(unittest.TestCase): class UkmXmlTest(unittest.TestCase):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
...@@ -142,5 +161,12 @@ class UkmXmlTest(unittest.TestCase): ...@@ -142,5 +161,12 @@ class UkmXmlTest(unittest.TestCase):
result = ukm_model.PrettifyXML(CONFIG_EVENT_NAMES_UNSORTED) result = ukm_model.PrettifyXML(CONFIG_EVENT_NAMES_UNSORTED)
self.assertMultiLineEqual(CONFIG_EVENT_NAMES_SORTED, result.strip()) self.assertMultiLineEqual(CONFIG_EVENT_NAMES_SORTED, result.strip())
def testIsNotObsolete(self):
for event in OBSOLETE_EVENTS_PARSED.values():
self.assertFalse(ukm_model.IsNotObsolete(event))
for metric in event.values():
self.assertTrue(ukm_model.IsNotObsolete(metric))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment