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.
5 from telemetry
.page
import page_test
7 from metrics
import cpu
8 from metrics
import media
9 from metrics
import memory
10 from metrics
import power
11 from metrics
import webrtc_stats
14 class WebRTC(page_test
.PageTest
):
15 """Gathers WebRTC-related metrics on a page set."""
18 super(WebRTC
, self
).__init
__()
19 self
._cpu
_metric
= None
20 self
._media
_metric
= None
21 self
._memory
_metric
= None
22 self
._power
_metric
= None
23 self
._webrtc
_stats
_metric
= None
25 def WillStartBrowser(self
, platform
):
26 self
._power
_metric
= power
.PowerMetric(platform
)
28 def DidStartBrowser(self
, browser
):
29 self
._cpu
_metric
= cpu
.CpuMetric(browser
)
30 self
._memory
_metric
= memory
.MemoryMetric(browser
)
31 self
._webrtc
_stats
_metric
= webrtc_stats
.WebRtcStatisticsMetric()
33 def DidNavigateToPage(self
, page
, tab
):
34 self
._cpu
_metric
.Start(page
, tab
)
35 self
._media
_metric
= media
.MediaMetric(tab
)
36 self
._media
_metric
.Start(page
, tab
)
37 self
._memory
_metric
.Start(page
, tab
)
38 self
._power
_metric
.Start(page
, tab
)
39 self
._webrtc
_stats
_metric
.Start(page
, tab
)
41 def CustomizeBrowserOptions(self
, options
):
42 memory
.MemoryMetric
.CustomizeBrowserOptions(options
)
43 options
.AppendExtraBrowserArgs('--use-fake-device-for-media-stream')
44 options
.AppendExtraBrowserArgs('--use-fake-ui-for-media-stream')
45 power
.PowerMetric
.CustomizeBrowserOptions(options
)
47 def ValidateAndMeasurePage(self
, page
, tab
, results
):
48 """Measure the page's performance."""
49 self
._cpu
_metric
.Stop(page
, tab
)
50 self
._cpu
_metric
.AddResults(tab
, results
)
52 # Add all media metrics except bytes (those aren't hooked up for WebRTC
54 exclude_metrics
= ['decoded_video_bytes', 'decoded_audio_bytes']
55 self
._media
_metric
.Stop(page
, tab
)
56 self
._media
_metric
.AddResults(tab
, results
, exclude_metrics
=exclude_metrics
)
58 self
._memory
_metric
.Stop(page
, tab
)
59 self
._memory
_metric
.AddResults(tab
, results
)
61 self
._power
_metric
.Stop(page
, tab
)
62 self
._power
_metric
.AddResults(tab
, results
)
64 self
._webrtc
_stats
_metric
.Stop(page
, tab
)
65 self
._webrtc
_stats
_metric
.AddResults(tab
, results
)