| Index: tools/telemetry/telemetry/web_perf/tracing_based_measurement.py
|
| diff --git a/tools/telemetry/telemetry/web_perf/tracing_based_measurement.py b/tools/telemetry/telemetry/web_perf/tracing_based_measurement.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fbcd232580e136fc4170554e25c0822886627058
|
| --- /dev/null
|
| +++ b/tools/telemetry/telemetry/web_perf/tracing_based_measurement.py
|
| @@ -0,0 +1,108 @@
|
| +# Copyright 2014 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.
|
| +from telemetry.timeline import tracing_category_filter
|
| +from telemetry.timeline import tracing_options
|
| +from telemetry.value import trace
|
| +from telemetry.web_perf import story_test
|
| +
|
| +# TracingBasedMeasurement considers all instrumentation as producing a single
|
| +# timeline. But, depending on the amount of instrumentation that is enabled,
|
| +# overhead increases. The user of the measurement must therefore chose between
|
| +# a few levels of instrumentation.
|
| +NO_OVERHEAD_LEVEL = 'no-overhead'
|
| +MINIMAL_OVERHEAD_LEVEL = 'minimal-overhead'
|
| +DEBUG_OVERHEAD_LEVEL = 'debug-overhead'
|
| +
|
| +ALL_OVERHEAD_LEVELS = [
|
| + NO_OVERHEAD_LEVEL,
|
| + MINIMAL_OVERHEAD_LEVEL,
|
| + DEBUG_OVERHEAD_LEVEL
|
| +]
|
| +
|
| +
|
| +class Options(object):
|
| + """A class to be used to configure TracingBasedMeasurement.
|
| +
|
| + This is created and returned by
|
| + Benchmark.CreateTimelineBasedMeasurementOptions.
|
| + """
|
| +
|
| + def __init__(self, overhead_level=NO_OVERHEAD_LEVEL):
|
| + """As the amount of instrumentation increases, so does the overhead.
|
| + The user of the measurement chooses the overhead level that is appropriate,
|
| + and the tracing is filtered accordingly.
|
| +
|
| + overhead_level: Can either be a custom TracingCategoryFilter object or
|
| + one of NO_OVERHEAD_LEVEL, MINIMAL_OVERHEAD_LEVEL or
|
| + DEBUG_OVERHEAD_LEVEL.
|
| + """
|
| + self._category_filter = None
|
| + if isinstance(overhead_level,
|
| + tracing_category_filter.TracingCategoryFilter):
|
| + self._category_filter = overhead_level
|
| + elif overhead_level in ALL_OVERHEAD_LEVELS:
|
| + if overhead_level == NO_OVERHEAD_LEVEL:
|
| + self._category_filter = tracing_category_filter.CreateNoOverheadFilter()
|
| + elif overhead_level == MINIMAL_OVERHEAD_LEVEL:
|
| + self._category_filter = (
|
| + tracing_category_filter.CreateMinimalOverheadFilter())
|
| + else:
|
| + self._category_filter = (
|
| + tracing_category_filter.CreateDebugOverheadFilter())
|
| + else:
|
| + raise Exception("Overhead level must be a TracingCategoryFilter object"
|
| + " or valid overhead level string."
|
| + " Given overhead level: %s" % overhead_level)
|
| +
|
| + self._tracing_options = tracing_options.TracingOptions()
|
| + self._tracing_options.enable_chrome_trace = True
|
| + self._tracing_options.enable_platform_display_trace = True
|
| +
|
| +
|
| + def ExtendTraceCategoryFilter(self, filters):
|
| + for new_category_filter in filters:
|
| + self._category_filter.AddIncludedCategory(new_category_filter)
|
| +
|
| + @property
|
| + def category_filter(self):
|
| + return self._category_filter
|
| +
|
| + @property
|
| + def tracing_options(self):
|
| + return self._tracing_options
|
| +
|
| + @tracing_options.setter
|
| + def tracing_options(self, value):
|
| + self._tracing_options = value
|
| +
|
| +
|
| +class TracingBasedMeasurement(story_test.StoryTest):
|
| + """Collects multiple metrics of story runs based on produced traces.
|
| +
|
| + Args:
|
| + options: an instance of timeline_based_measurement.Options.
|
| + """
|
| + def __init__(self, options):
|
| + self._options = options
|
| +
|
| + def WillRunStory(self, platform):
|
| + if not platform.tracing_controller.IsChromeTracingSupported():
|
| + raise Exception('Not supported')
|
| + platform.tracing_controller.Start(self._options.tracing_options,
|
| + self._options.category_filter)
|
| +
|
| +
|
| + def Measure(self, platform, results):
|
| + """Collect all possible metrics and added them to results."""
|
| + trace_result = platform.tracing_controller.Stop()
|
| + results.AddValue(trace.TraceValue(results.current_page, trace_result))
|
| + self.ComputeMetricsForTrace(trace_result, results)
|
| +
|
| + def ComputeMetricsForTrace(self, trace_result, results):
|
| + raise NotImplementedError()
|
| +
|
| + def DidRunStory(self, platform):
|
| + """Clean up after running the story."""
|
| + if platform.tracing_controller.is_tracing_running:
|
| + platform.tracing_controller.Stop()
|
|
|