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 import logging | 4 import logging |
5 import os | 5 import os |
6 | 6 |
7 from metrics import Metric | 7 from metrics import Metric |
8 | 8 |
9 | 9 |
10 class MediaMetric(Metric): | 10 class MediaMetric(Metric): |
11 """MediaMetric class injects and calls JS responsible for recording metrics. | 11 """MediaMetric class injects and calls JS responsible for recording metrics. |
12 | 12 |
13 Default media metrics are collected for every media element in the page, | 13 Default media metrics are collected for every media element in the page, |
14 such as decoded_frame_count, dropped_frame_count, decoded_video_bytes, and | 14 such as decoded_frame_count, dropped_frame_count, decoded_video_bytes, and |
15 decoded_audio_bytes. | 15 decoded_audio_bytes. |
16 """ | 16 """ |
17 | 17 |
18 def __init__(self, tab): | 18 def __init__(self, tab): |
19 super(MediaMetric, self).__init__() | 19 super(MediaMetric, self).__init__() |
20 with open(os.path.join(os.path.dirname(__file__), 'media.js')) as f: | 20 with open(os.path.join(os.path.dirname(__file__), 'media.js')) as f: |
21 js = f.read() | 21 js = f.read() |
22 tab.ExecuteJavaScript(js) | 22 tab.ExecuteJavaScript(js) |
23 self._results = None | 23 self._results = None |
24 self._skip_basic_metrics = False | 24 self._skip_basic_metrics = False |
25 | 25 |
26 def Start(self, page, tab): | 26 def Start(self, page, tab): |
27 """Create the media metrics for all media elements in the document.""" | 27 """Create the media metrics for all media elements in the document.""" |
28 if hasattr(page.page_set, 'skip_basic_metrics'): | 28 if hasattr(page, 'skip_basic_metrics'): |
29 self._skip_basic_metrics = page.page_set.skip_basic_metrics | 29 self._skip_basic_metrics = page.skip_basic_metrics |
30 tab.ExecuteJavaScript('window.__createMediaMetricsForDocument()') | 30 tab.ExecuteJavaScript('window.__createMediaMetricsForDocument()') |
31 | 31 |
32 def Stop(self, page, tab): | 32 def Stop(self, page, tab): |
33 self._results = tab.EvaluateJavaScript('window.__getAllMetrics()') | 33 self._results = tab.EvaluateJavaScript('window.__getAllMetrics()') |
34 | 34 |
35 def AddResults(self, tab, results): | 35 def AddResults(self, tab, results): |
36 """Reports all recorded metrics as Telemetry perf results.""" | 36 """Reports all recorded metrics as Telemetry perf results.""" |
37 assert self._results | 37 assert self._results |
38 for media_metric in self._results: | 38 for media_metric in self._results: |
39 self._AddResultsForMediaElement(media_metric, results) | 39 self._AddResultsForMediaElement(media_metric, results) |
(...skipping 27 matching lines...) Expand all Loading... |
67 if not self._skip_basic_metrics: | 67 if not self._skip_basic_metrics: |
68 AddOneResult('buffering_time', 'ms') | 68 AddOneResult('buffering_time', 'ms') |
69 AddOneResult('decoded_audio_bytes', 'bytes') | 69 AddOneResult('decoded_audio_bytes', 'bytes') |
70 AddOneResult('decoded_video_bytes', 'bytes') | 70 AddOneResult('decoded_video_bytes', 'bytes') |
71 AddOneResult('decoded_frame_count', 'frames') | 71 AddOneResult('decoded_frame_count', 'frames') |
72 AddOneResult('dropped_frame_count', 'frames') | 72 AddOneResult('dropped_frame_count', 'frames') |
73 AddOneResult('time_to_play', 'ms') | 73 AddOneResult('time_to_play', 'ms') |
74 | 74 |
75 AddOneResult('avg_loop_time', 'ms') | 75 AddOneResult('avg_loop_time', 'ms') |
76 AddOneResult('seek', 'ms') | 76 AddOneResult('seek', 'ms') |
77 | |
OLD | NEW |