Chromium Code Reviews| Index: tools/perf/measurements/timeline_based_measurement.py |
| diff --git a/tools/perf/measurements/timeline_based_measurement.py b/tools/perf/measurements/timeline_based_measurement.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fbe18d1bf1baf72b1e37929af767d265fc260200 |
| --- /dev/null |
| +++ b/tools/perf/measurements/timeline_based_measurement.py |
| @@ -0,0 +1,99 @@ |
| +# 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 metrics import timeline as timeline_module |
| +from metrics import timeline_interaction_record as tir_module |
| +from telemetry.page import page_measurement |
| +from telemetry.core.timeline import model as model_module |
| + |
| + |
| + |
| +# TimelineBasedMeasurement 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 _TimelineBasedMetrics(object): |
| + def __init__(self, model, renderer_thread): |
| + self._model = model |
| + self._renderer_thread = renderer_thread |
| + |
| + def FindTimelineInteractionRecords(self): |
| + # TODO(nduca): Add support for page-load interaction record. |
| + return [tir_module.TimelineInteractionRecord(event) for |
| + event in self._renderer_thread.IterAllAsyncSlices() |
| + if tir_module.IsTimelineInteractionRecord(event.name)] |
| + |
| + def CreateMetricsForTimelineInteractionRecord(self, interaction): |
| + res = [] |
| + if interaction.is_smooth: |
| + pass # TODO(nduca): res.append smoothness metric instance. |
| + return res |
| + |
| + def AddResults(self, results): |
| + interactions = self.FindTimelineInteractionRecords() |
| + if len(interactions) == 0: |
| + raise Exception('Expected at least one Interaction on the page') |
| + for interaction in interactions: |
| + metrics = self.CreateMetricsForTimelineInteractionRecord(interaction) |
| + for m in metrics: |
| + m.AddResults(self._model, self._renderer_thread, |
| + interaction, results) |
| + |
| + |
| +class TimelineBasedMeasurement(page_measurement.PageMeasurement): |
| + """A timeline measurement shifts the burden of what metrics to collect onto |
| + the page under test, or the pageset running that page. Instead of the |
| + measurement having a fixed set of values it collects about the page, the page |
| + being tested issues a set of standard calls to the user timing API specifying |
| + time spans of interest during which interactions are running, and for each, a |
| + standardized set of flags describing the work being done in that time range. |
| + This measurement object then collects a trace alongside these interaction |
| + records, and passes the recorded timeline to different TimelineBasedMetrics |
| + based on those flags. |
|
nednguyen
2014/03/04 15:38:47
Add examples of the interaction marker that the pa
|
| + |
| + """ |
| + def __init__(self): |
| + super(TimelineBasedMeasurement, self).__init__('smoothness') |
| + |
| + def AddCommandLineOptions(self, parser): |
| + parser.add_option( |
| + '--overhead-level', type='choice', |
| + choices=ALL_OVERHEAD_LEVELS, |
| + default=NO_OVERHEAD_LEVEL, |
| + help='How much overhead to incur during the measurement.') |
| + |
| + def CanRunForPage(self, page): |
| + return hasattr(page, 'smoothness') |
| + |
| + def WillNavigateToPage(self, page, tab): |
| + if not tab.browser.supports_tracing: |
| + raise Exception('Not supported') |
| + assert self.options.overhead_level in ALL_OVERHEAD_LEVELS |
| + if self.options.overhead_level == NO_OVERHEAD_LEVEL: |
| + categories = timeline_module.MINIMAL_TRACE_CATEGORIES |
| + elif self.options.overhead_level == \ |
| + MINIMAL_OVERHEAD_LEVEL: |
| + categories = '' |
| + else: |
| + categories = '*,disabled-by-default-cc.debug' |
| + tab.browser.StartTracing(categories) |
| + |
| + def MeasurePage(self, page, tab, results): |
| + """ Collect all possible metrics and added them to results. """ |
| + trace_result = tab.browser.StopTracing() |
| + model = model_module.TimelineModel(trace_result) |
| + renderer_thread = model.GetRendererThreadFromTab(tab) |
| + meta_metrics = _TimelineBasedMetrics(model, renderer_thread) |
| + meta_metrics.AddResults(results) |