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.page_set, 'skip_basic_metrics'): |
29 self._skip_basic_metrics = page.page_set.skip_basic_metrics | 29 self._skip_basic_metrics = page.page_set.skip_basic_metrics |
30 # Page level attribute overrides page-set one. | |
31 if hasattr(page, 'skip_basic_metrics'): | |
32 self._skip_basic_metrics = page.skip_basic_metrics | |
dtu
2013/09/05 19:59:19
Pages inherit attributes from the page set. So you
shadi
2013/09/06 22:22:37
I wish we knew that earlier :) Thanks!
| |
30 tab.ExecuteJavaScript('window.__createMediaMetricsForDocument()') | 33 tab.ExecuteJavaScript('window.__createMediaMetricsForDocument()') |
31 | 34 |
32 def Stop(self, page, tab): | 35 def Stop(self, page, tab): |
33 self._results = tab.EvaluateJavaScript('window.__getAllMetrics()') | 36 self._results = tab.EvaluateJavaScript('window.__getAllMetrics()') |
34 | 37 |
35 def AddResults(self, tab, results): | 38 def AddResults(self, tab, results): |
36 """Reports all recorded metrics as Telemetry perf results.""" | 39 """Reports all recorded metrics as Telemetry perf results.""" |
37 assert self._results | 40 assert self._results |
38 for media_metric in self._results: | 41 for media_metric in self._results: |
39 self._AddResultsForMediaElement(media_metric, results) | 42 self._AddResultsForMediaElement(media_metric, results) |
(...skipping 18 matching lines...) Expand all Loading... | |
58 special_label = m[len(metric):] | 61 special_label = m[len(metric):] |
59 results.Add(trace + special_label, unit, str(metrics[m]), | 62 results.Add(trace + special_label, unit, str(metrics[m]), |
60 chart_name=metric, data_type='default') | 63 chart_name=metric, data_type='default') |
61 | 64 |
62 trace = media_metric['id'] | 65 trace = media_metric['id'] |
63 if not trace: | 66 if not trace: |
64 logging.error('Metrics ID is missing in results.') | 67 logging.error('Metrics ID is missing in results.') |
65 return | 68 return |
66 | 69 |
67 if not self._skip_basic_metrics: | 70 if not self._skip_basic_metrics: |
68 AddOneResult('avg_loop_time', 'sec') | |
69 AddOneResult('buffering_time', 'sec') | 71 AddOneResult('buffering_time', 'sec') |
70 AddOneResult('decoded_audio_bytes', 'bytes') | 72 AddOneResult('decoded_audio_bytes', 'bytes') |
71 AddOneResult('decoded_video_bytes', 'bytes') | 73 AddOneResult('decoded_video_bytes', 'bytes') |
72 AddOneResult('decoded_frame_count', 'frames') | 74 AddOneResult('decoded_frame_count', 'frames') |
73 AddOneResult('dropped_frame_count', 'frames') | 75 AddOneResult('dropped_frame_count', 'frames') |
74 AddOneResult('time_to_play', 'sec') | 76 AddOneResult('time_to_play', 'sec') |
75 | 77 |
78 AddOneResult('avg_loop_time', 'sec') | |
76 AddOneResult('seek', 'sec') | 79 AddOneResult('seek', 'sec') |
77 | 80 |
OLD | NEW |