| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from measurements import PageTestMeasurement |
| 5 from metrics import cpu | 6 from metrics import cpu |
| 6 from metrics import media | 7 from metrics import media |
| 7 from metrics import system_memory | 8 from metrics import system_memory |
| 8 from metrics import power | 9 from metrics import power |
| 9 from telemetry.page import page_test | |
| 10 | 10 |
| 11 | 11 |
| 12 class Media(page_test.PageTest): | 12 class Media(PageTestMeasurement): |
| 13 """The MediaMeasurement class gathers media-related metrics on a page set. | 13 """The MediaMeasurement class gathers media-related metrics on a page set. |
| 14 | 14 |
| 15 Media metrics recorded are controlled by metrics/media.js. At the end of the | 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. | 16 test each metric for every media element in the page are reported. |
| 17 """ | 17 """ |
| 18 | 18 |
| 19 def __init__(self): | 19 def __init__(self): |
| 20 super(Media, self).__init__('RunPageInteractions') | 20 super(Media, self).__init__('RunPageInteractions') |
| 21 self._media_metric = None | 21 self._media_metric = None |
| 22 # Used to add browser power and CPU metrics to results per test. | 22 # Used to add browser power and CPU metrics to results per test. |
| 23 self._add_browser_metrics = False | 23 self._add_browser_metrics = False |
| 24 self._cpu_metric = None | 24 self._cpu_metric = None |
| 25 self._memory_metric = None | 25 self._memory_metric = None |
| 26 self._power_metric = None | 26 self._power_metric = None |
| 27 | 27 |
| 28 def WillStartBrowser(self, platform): | 28 def WillStartBrowser(self, platform): |
| 29 self._power_metric = power.PowerMetric(platform) | 29 self._power_metric = power.PowerMetric(platform) |
| 30 | 30 |
| 31 def CustomizeBrowserOptions(self, options): | 31 def CustomizeBrowserOptions(self, options): |
| 32 # Needed to run media actions in JS on touch-based devices as on Android. | 32 # Needed to run media actions in JS on touch-based devices as on Android. |
| 33 super(Media, self).CustomizeBrowserOptions(options) |
| 33 options.AppendExtraBrowserArgs( | 34 options.AppendExtraBrowserArgs( |
| 34 '--disable-gesture-requirement-for-media-playback') | 35 '--disable-gesture-requirement-for-media-playback') |
| 35 power.PowerMetric.CustomizeBrowserOptions(options) | 36 power.PowerMetric.CustomizeBrowserOptions(options) |
| 36 | 37 |
| 37 def DidNavigateToPage(self, page, tab): | 38 def DidNavigateToPage(self, page, tab): |
| 38 """Override to do operations right after the page is navigated.""" | 39 """Override to do operations right after the page is navigated.""" |
| 39 self._media_metric = media.MediaMetric(tab) | 40 self._media_metric = media.MediaMetric(tab) |
| 40 self._media_metric.Start(page, tab) | 41 self._media_metric.Start(page, tab) |
| 41 | 42 |
| 42 # Reset to false for every page. | 43 # Reset to false for every page. |
| 43 self._add_browser_metrics = (page.add_browser_metrics | 44 self._add_browser_metrics = (page.add_browser_metrics |
| 44 if hasattr(page, 'add_browser_metrics') else False) | 45 if hasattr(page, 'add_browser_metrics') else False) |
| 45 | 46 |
| 46 if self._add_browser_metrics: | 47 if self._add_browser_metrics: |
| 47 self._cpu_metric = cpu.CpuMetric(tab.browser) | 48 self._cpu_metric = cpu.CpuMetric(tab.browser) |
| 48 self._cpu_metric.Start(page, tab) | 49 self._cpu_metric.Start(page, tab) |
| 49 self._memory_metric = system_memory.SystemMemoryMetric(tab.browser) | 50 self._memory_metric = system_memory.SystemMemoryMetric(tab.browser) |
| 50 self._memory_metric.Start(page, tab) | 51 self._memory_metric.Start(page, tab) |
| 51 self._power_metric.Start(page, tab) | 52 self._power_metric.Start(page, tab) |
| 52 | 53 |
| 53 def ValidateAndMeasurePage(self, page, tab, results): | 54 def ValidateAndMeasurePage(self, page, tab, results): |
| 54 """Measure the page's performance.""" | 55 """Measure the page's performance.""" |
| 56 super(Media, self).ValidateAndMeasurePage(page, tab, results) |
| 55 self._media_metric.Stop(page, tab) | 57 self._media_metric.Stop(page, tab) |
| 56 trace_name = self._media_metric.AddResults(tab, results) | 58 trace_name = self._media_metric.AddResults(tab, results) |
| 57 | 59 |
| 58 if self._add_browser_metrics: | 60 if self._add_browser_metrics: |
| 59 self._cpu_metric.Stop(page, tab) | 61 self._cpu_metric.Stop(page, tab) |
| 60 self._memory_metric.Stop(page, tab) | 62 self._memory_metric.Stop(page, tab) |
| 61 self._power_metric.Stop(page, tab) | 63 self._power_metric.Stop(page, tab) |
| 62 self._cpu_metric.AddResults(tab, results, trace_name=trace_name) | 64 self._cpu_metric.AddResults(tab, results, trace_name=trace_name) |
| 63 exclude_metrics = ['WorkingSetSizePeak', 'SystemCommitCharge', 'VMPeak', | 65 exclude_metrics = ['WorkingSetSizePeak', 'SystemCommitCharge', 'VMPeak', |
| 64 'VM'] | 66 'VM'] |
| 65 self._memory_metric.AddResults(tab, results, | 67 self._memory_metric.AddResults(tab, results, |
| 66 trace_name=trace_name, | 68 trace_name=trace_name, |
| 67 exclude_metrics=exclude_metrics) | 69 exclude_metrics=exclude_metrics) |
| 68 self._power_metric.AddResults(tab, results) | 70 self._power_metric.AddResults(tab, results) |
| OLD | NEW |