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 from telemetry.value import list_of_scalar_values | 8 from telemetry.value import list_of_scalar_values |
9 from telemetry.value import scalar | 9 from telemetry.value import scalar |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 def Start(self, page, tab): | 28 def Start(self, page, tab): |
29 """Create the media metrics for all media elements in the document.""" | 29 """Create the media metrics for all media elements in the document.""" |
30 if hasattr(page, 'skip_basic_metrics'): | 30 if hasattr(page, 'skip_basic_metrics'): |
31 self._skip_basic_metrics = page.skip_basic_metrics | 31 self._skip_basic_metrics = page.skip_basic_metrics |
32 tab.ExecuteJavaScript('window.__createMediaMetricsForDocument()') | 32 tab.ExecuteJavaScript('window.__createMediaMetricsForDocument()') |
33 | 33 |
34 def Stop(self, page, tab): | 34 def Stop(self, page, tab): |
35 self._results = tab.EvaluateJavaScript('window.__getAllMetrics()') | 35 self._results = tab.EvaluateJavaScript('window.__getAllMetrics()') |
36 | 36 |
37 def AddResults(self, tab, results): | 37 # Optional |exclude_metrics| args are not in base class Metric. |
| 38 # pylint: disable=W0221 |
| 39 def AddResults(self, tab, results, exclude_metrics=None): |
38 """Reports all recorded metrics as Telemetry perf results.""" | 40 """Reports all recorded metrics as Telemetry perf results.""" |
| 41 exclude_metrics = exclude_metrics or [] |
39 trace_names = [] | 42 trace_names = [] |
40 for media_metric in self._results: | 43 for media_metric in self._results: |
41 trace_names.append(self._AddResultsForMediaElement(media_metric, results)) | 44 trace_names.append(self._AddResultsForMediaElement(media_metric, results, |
| 45 exclude_metrics)) |
42 | 46 |
43 return '_'.join(trace_names) or tab.url | 47 return '_'.join(trace_names) or tab.url |
44 | 48 |
45 def _AddResultsForMediaElement(self, media_metric, results): | 49 def _AddResultsForMediaElement(self, media_metric, results, exclude_metrics): |
46 """Reports metrics for one media element. | 50 """Reports metrics for one media element. |
47 | 51 |
48 Media metrics contain an ID identifying the media element and values: | 52 Media metrics contain an ID identifying the media element and values: |
49 media_metric = { | 53 media_metric = { |
50 'id': 'video_1', | 54 'id': 'video_1', |
51 'metrics': { | 55 'metrics': { |
52 'time_to_play': 120, | 56 'time_to_play': 120, |
53 'decoded_bytes': 13233, | 57 'decoded_bytes': 13233, |
54 ... | 58 ... |
55 } | 59 } |
56 } | 60 } |
57 """ | 61 """ |
58 def AddOneResult(metric, unit): | 62 def AddOneResult(metric, unit): |
| 63 if metric in exclude_metrics: |
| 64 return |
| 65 |
59 metrics = media_metric['metrics'] | 66 metrics = media_metric['metrics'] |
60 for m in metrics: | 67 for m in metrics: |
61 if m.startswith(metric): | 68 if m.startswith(metric): |
62 special_label = m[len(metric):] | 69 special_label = m[len(metric):] |
63 trace_name = '%s.%s%s' % (metric, trace, special_label) | 70 trace_name = '%s.%s%s' % (metric, trace, special_label) |
64 if isinstance(metrics[m], list): | 71 if isinstance(metrics[m], list): |
65 results.AddValue(list_of_scalar_values.ListOfScalarValues( | 72 results.AddValue(list_of_scalar_values.ListOfScalarValues( |
66 results.current_page, trace_name, unit, | 73 results.current_page, trace_name, unit, |
67 values=[float(v) for v in metrics[m]], | 74 values=[float(v) for v in metrics[m]], |
68 important=True)) | 75 important=True)) |
(...skipping 11 matching lines...) Expand all Loading... |
80 AddOneResult('buffering_time', 'ms') | 87 AddOneResult('buffering_time', 'ms') |
81 AddOneResult('decoded_audio_bytes', 'bytes') | 88 AddOneResult('decoded_audio_bytes', 'bytes') |
82 AddOneResult('decoded_video_bytes', 'bytes') | 89 AddOneResult('decoded_video_bytes', 'bytes') |
83 AddOneResult('decoded_frame_count', 'frames') | 90 AddOneResult('decoded_frame_count', 'frames') |
84 AddOneResult('dropped_frame_count', 'frames') | 91 AddOneResult('dropped_frame_count', 'frames') |
85 AddOneResult('time_to_play', 'ms') | 92 AddOneResult('time_to_play', 'ms') |
86 | 93 |
87 AddOneResult('avg_loop_time', 'ms') | 94 AddOneResult('avg_loop_time', 'ms') |
88 AddOneResult('seek', 'ms') | 95 AddOneResult('seek', 'ms') |
89 return trace | 96 return trace |
OLD | NEW |