Fix OOP <webview> resize and autosize.
[chromium-blink-merge.git] / tools / perf / measurements / media.py
blob3537cdaa098b5eb3f6d7817c435db652de57e10f
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 telemetry.page import page_test
7 from metrics import cpu
8 from metrics import media
9 from metrics import power
10 from metrics import system_memory
13 class Media(page_test.PageTest):
14 """The MediaMeasurement class gathers media-related metrics on a page set.
16 Media metrics recorded are controlled by metrics/media.js. At the end of the
17 test each metric for every media element in the page are reported.
18 """
20 def __init__(self):
21 super(Media, self).__init__()
22 self._media_metric = None
23 # Used to add browser power and CPU metrics to results per test.
24 self._add_browser_metrics = False
25 self._cpu_metric = None
26 self._memory_metric = None
27 self._power_metric = None
29 def WillStartBrowser(self, platform):
30 self._power_metric = power.PowerMetric(platform)
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 power.PowerMetric.CustomizeBrowserOptions(options)
38 def DidNavigateToPage(self, page, tab):
39 """Override to do operations right after the page is navigated."""
40 self._media_metric = media.MediaMetric(tab)
41 self._media_metric.Start(page, tab)
43 # Reset to false for every page.
44 self._add_browser_metrics = (page.add_browser_metrics
45 if hasattr(page, 'add_browser_metrics') else False)
47 if self._add_browser_metrics:
48 self._cpu_metric = cpu.CpuMetric(tab.browser)
49 self._cpu_metric.Start(page, tab)
50 self._memory_metric = system_memory.SystemMemoryMetric(tab.browser)
51 self._memory_metric.Start(page, tab)
52 self._power_metric.Start(page, tab)
54 def ValidateAndMeasurePage(self, page, tab, results):
55 """Measure the page's performance."""
56 self._media_metric.Stop(page, tab)
57 trace_name = self._media_metric.AddResults(tab, results)
59 if self._add_browser_metrics:
60 self._cpu_metric.Stop(page, tab)
61 self._memory_metric.Stop(page, tab)
62 self._power_metric.Stop(page, tab)
63 self._cpu_metric.AddResults(tab, results, trace_name=trace_name)
64 exclude_metrics = ['WorkingSetSizePeak', 'SystemCommitCharge', 'VMPeak',
65 'VM']
66 self._memory_metric.AddResults(tab, results,
67 trace_name=trace_name,
68 exclude_metrics=exclude_metrics)
69 self._power_metric.AddResults(tab, results)