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