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
3 # found in the LICENSE file.
5 from metrics import cpu
6 from metrics import media
7 from metrics import memory
8 from metrics import power
9 from telemetry.page import page_measurement
12 class Media(page_measurement.PageMeasurement):
13 """The MediaMeasurement class gathers media-related metrics on a page set.
15 Media metrics recorded are controlled by metrics/media.js. At the end of the
16 test each metric for every media element in the page are reported.
20 super(Media, self).__init__('media_metrics')
21 self._media_metric = None
22 # Used to add browser memory and CPU metrics to results per test.
23 self._add_browser_metrics = False
24 self._cpu_metric = None
25 self._memory_metric = None
26 self._power_metric = power.PowerMetric()
28 def results_are_the_same_on_every_page(self):
29 """Results can vary from page to page based on media events taking place."""
32 def CustomizeBrowserOptions(self, options):
33 # Needed to run media actions in JS on touch-based devices as on Android.
34 options.AppendExtraBrowserArgs(
35 '--disable-gesture-requirement-for-media-playback')
36 memory.MemoryMetric.CustomizeBrowserOptions(options)
37 power.PowerMetric.CustomizeBrowserOptions(options)
39 def DidNavigateToPage(self, page, tab):
40 """Override to do operations right after the page is navigated."""
41 self._media_metric = media.MediaMetric(tab)
42 self._media_metric.Start(page, tab)
43 self._power_metric.Start(page, tab)
45 # Reset to false for every page.
46 self._add_browser_metrics = False
47 if hasattr(page, 'add_browser_metrics'):
48 self._add_browser_metrics = page.add_browser_metrics
50 # Start browser metrics at page level to isolate startup CPU usage.
51 if self._add_browser_metrics:
52 self._cpu_metric = cpu.CpuMetric(tab.browser)
53 self._cpu_metric.Start(page, tab)
54 self._memory_metric = memory.MemoryMetric(tab.browser)
55 self._memory_metric.Start(page, tab)
57 def MeasurePage(self, page, tab, results):
58 """Measure the page's performance."""
59 self._power_metric.Stop(page, tab)
60 self._media_metric.Stop(page, tab)
61 trace_name = self._media_metric.AddResults(tab, results)
62 self._power_metric.AddResults(tab, results)
63 if self._add_browser_metrics:
64 self._cpu_metric.Stop(page, tab)
65 self._cpu_metric.AddResults(tab, results, trace_name=trace_name)
66 self._memory_metric.Stop(page, tab)
67 self._memory_metric.AddResults(tab, results, trace_name=trace_name)