| OLD | NEW |
| (Empty) |
| 1 # Copyright 2014 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. | |
| 4 | |
| 5 from telemetry.page import legacy_page_test | |
| 6 | |
| 7 from metrics import cpu | |
| 8 from metrics import media | |
| 9 from metrics import power | |
| 10 from metrics import webrtc_stats | |
| 11 | |
| 12 | |
| 13 class WebRTC(legacy_page_test.LegacyPageTest): | |
| 14 """Gathers WebRTC-related metrics on a page set.""" | |
| 15 | |
| 16 def __init__(self, particular_metrics=None): | |
| 17 """Create the measurement and include selected stats. | |
| 18 | |
| 19 Args: | |
| 20 particular_metrics: A list of the stats to include (see webrtc_stats.py | |
| 21 for a list of valid names) or None to select all metrics. | |
| 22 """ | |
| 23 super(WebRTC, self).__init__() | |
| 24 self._cpu_metric = None | |
| 25 self._media_metric = None | |
| 26 self._power_metric = None | |
| 27 self._particular_metrics = particular_metrics | |
| 28 self._webrtc_stats_metric = None | |
| 29 | |
| 30 def WillStartBrowser(self, platform): | |
| 31 self._power_metric = power.PowerMetric(platform) | |
| 32 | |
| 33 def DidStartBrowser(self, browser): | |
| 34 self._cpu_metric = cpu.CpuMetric(browser) | |
| 35 self._webrtc_stats_metric = webrtc_stats.WebRtcStatisticsMetric( | |
| 36 self._particular_metrics) | |
| 37 | |
| 38 def DidNavigateToPage(self, page, tab): | |
| 39 self._cpu_metric.Start(page, tab) | |
| 40 self._media_metric = media.MediaMetric(tab) | |
| 41 self._media_metric.Start(page, tab) | |
| 42 self._power_metric.Start(page, tab) | |
| 43 self._webrtc_stats_metric.Start(page, tab) | |
| 44 | |
| 45 def CustomizeBrowserOptions(self, options): | |
| 46 options.AppendExtraBrowserArgs('--use-fake-device-for-media-stream') | |
| 47 options.AppendExtraBrowserArgs('--use-fake-ui-for-media-stream') | |
| 48 power.PowerMetric.CustomizeBrowserOptions(options) | |
| 49 | |
| 50 def ValidateAndMeasurePage(self, page, tab, results): | |
| 51 """Measure the page's performance.""" | |
| 52 self._cpu_metric.Stop(page, tab) | |
| 53 self._cpu_metric.AddResults(tab, results) | |
| 54 | |
| 55 # Add all media metrics except bytes (those aren't hooked up for WebRTC | |
| 56 # video tags). | |
| 57 exclude_metrics = ['decoded_video_bytes', 'decoded_audio_bytes'] | |
| 58 self._media_metric.Stop(page, tab) | |
| 59 self._media_metric.AddResults(tab, results, exclude_metrics=exclude_metrics) | |
| 60 | |
| 61 self._power_metric.Stop(page, tab) | |
| 62 self._power_metric.AddResults(tab, results) | |
| 63 | |
| 64 self._webrtc_stats_metric.Stop(page, tab) | |
| 65 self._webrtc_stats_metric.AddResults(tab, results) | |
| 66 | |
| 67 def DidRunPage(self, platform): | |
| 68 del platform # unused | |
| 69 self._power_metric.Close() | |
| OLD | NEW |