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 class MediaMetric(Metric): | 10 class MediaMetric(Metric): |
10 """MediaMetric class injects and calls JS responsible for recording metrics. | 11 """MediaMetric class injects and calls JS responsible for recording metrics. |
11 | 12 |
12 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, |
13 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 |
14 decoded_audio_bytes. | 15 decoded_audio_bytes. |
15 """ | 16 """ |
| 17 |
16 def __init__(self, tab): | 18 def __init__(self, tab): |
17 super(MediaMetric, self).__init__() | 19 super(MediaMetric, self).__init__() |
18 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: |
19 js = f.read() | 21 js = f.read() |
20 tab.ExecuteJavaScript(js) | 22 tab.ExecuteJavaScript(js) |
21 self._results = None | 23 self._results = None |
| 24 self._skip_basic_metrics = False |
22 | 25 |
23 def Start(self, page, tab): | 26 def Start(self, page, tab): |
24 """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'): |
| 29 self._skip_basic_metrics = page.page_set.skip_basic_metrics |
25 tab.ExecuteJavaScript('window.__createMediaMetricsForDocument()') | 30 tab.ExecuteJavaScript('window.__createMediaMetricsForDocument()') |
26 | 31 |
27 def Stop(self, page, tab): | 32 def Stop(self, page, tab): |
28 self._results = tab.EvaluateJavaScript('window.__getAllMetrics()') | 33 self._results = tab.EvaluateJavaScript('window.__getAllMetrics()') |
29 | 34 |
30 def AddResults(self, tab, results): | 35 def AddResults(self, tab, results): |
31 """Reports all recorded metrics as Telemetry perf results.""" | 36 """Reports all recorded metrics as Telemetry perf results.""" |
32 assert self._results | 37 assert self._results |
33 for media_metric in self._results: | 38 for media_metric in self._results: |
34 self._AddResultsForMediaElement(media_metric, results) | 39 self._AddResultsForMediaElement(media_metric, results) |
(...skipping 16 matching lines...) Expand all Loading... |
51 for m in metrics: | 56 for m in metrics: |
52 if m.startswith(metric): | 57 if m.startswith(metric): |
53 special_label = m[len(metric):] | 58 special_label = m[len(metric):] |
54 results.Add(trace + special_label, unit, str(metrics[m]), | 59 results.Add(trace + special_label, unit, str(metrics[m]), |
55 chart_name=metric, data_type='default') | 60 chart_name=metric, data_type='default') |
56 | 61 |
57 trace = media_metric['id'] | 62 trace = media_metric['id'] |
58 if not trace: | 63 if not trace: |
59 logging.error('Metrics ID is missing in results.') | 64 logging.error('Metrics ID is missing in results.') |
60 return | 65 return |
61 AddOneResult('decoded_audio_bytes', 'bytes') | 66 |
62 AddOneResult('decoded_video_bytes', 'bytes') | 67 if not self._skip_basic_metrics: |
63 AddOneResult('decoded_frame_count', 'frames') | 68 AddOneResult('decoded_audio_bytes', 'bytes') |
64 AddOneResult('dropped_frame_count', 'frames') | 69 AddOneResult('decoded_video_bytes', 'bytes') |
65 AddOneResult('playback_time', 'sec') | 70 AddOneResult('decoded_frame_count', 'frames') |
| 71 AddOneResult('dropped_frame_count', 'frames') |
| 72 AddOneResult('time_to_play', 'sec') |
| 73 AddOneResult('playback_time', 'sec') |
| 74 |
66 AddOneResult('seek', 'sec') | 75 AddOneResult('seek', 'sec') |
67 AddOneResult('time_to_play', 'sec') | |
68 | 76 |
OLD | NEW |