OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 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 | 4 |
5 """Media Metrics class injects and calls JS responsible for recording metrics. | 5 """Media Metrics class injects and calls JS responsible for recording metrics. |
6 | 6 |
7 Default media metrics are collected for every media element in the page, such as | 7 Default media metrics are collected for every media element in the page, such as |
8 decoded_frame_count, dropped_frame_count, decoded_video_bytes, and | 8 decoded_frame_count, dropped_frame_count, decoded_video_bytes, and |
9 decoded_audio_bytes. | 9 decoded_audio_bytes. |
10 """ | 10 """ |
11 | 11 |
(...skipping 10 matching lines...) Expand all Loading... |
22 self.tab = tab | 22 self.tab = tab |
23 | 23 |
24 def Start(self): | 24 def Start(self): |
25 """Create the media metrics for all media elements in the document.""" | 25 """Create the media metrics for all media elements in the document.""" |
26 self.tab.ExecuteJavaScript('window.__createMediaMetricsForDocument()') | 26 self.tab.ExecuteJavaScript('window.__createMediaMetricsForDocument()') |
27 | 27 |
28 def StopAndGetResults(self, results): | 28 def StopAndGetResults(self, results): |
29 """Reports all recorded metrics as Telemetry perf results.""" | 29 """Reports all recorded metrics as Telemetry perf results.""" |
30 media_metrics = self.tab.EvaluateJavaScript('window.__getAllMetrics()') | 30 media_metrics = self.tab.EvaluateJavaScript('window.__getAllMetrics()') |
31 for media_metric in media_metrics: | 31 for media_metric in media_metrics: |
32 self.AddResultForMediaElement(media_metric, results) | 32 self.AddResultsForMediaElement(media_metric, results) |
33 | 33 |
34 def AddResultForMediaElement(self, media_metric, results): | 34 def AddResultsForMediaElement(self, media_metric, results): |
35 """Reports metrics for one media element. | 35 """Reports metrics for one media element. |
36 | 36 |
37 Media metrics contain an ID identifying the media element and values: | 37 Media metrics contain an ID identifying the media element and values: |
38 media_metric = { | 38 media_metric = { |
39 'id': 'video_1', | 39 'id': 'video_1', |
40 'metrics': { | 40 'metrics': { |
41 'time_to_play': 120, | 41 'time_to_play': 120, |
42 'decoded_bytes': 13233, | 42 'decoded_bytes': 13233, |
43 ... | 43 ... |
44 } | 44 } |
45 } | 45 } |
46 """ | 46 """ |
47 def AddResult(metric, unit): | 47 def AddResults(metric, unit): |
48 metrics = media_metric['metrics'] | 48 metrics = media_metric['metrics'] |
49 if metric in metrics: | 49 for m in metrics: |
50 results.Add(trace, unit, str(metrics[metric]), chart_name=metric, | 50 if m.startswith(metric): |
51 data_type='default') | 51 special_label = m[len(metric):] |
| 52 results.Add(trace + special_label, unit, str(metrics[m]), |
| 53 chart_name=metric, data_type='default') |
52 | 54 |
53 trace = media_metric['id'] | 55 trace = media_metric['id'] |
54 if not trace: | 56 if not trace: |
55 logging.error('Metrics ID is missing in results.') | 57 logging.error('Metrics ID is missing in results.') |
56 return | 58 return |
57 | 59 AddResults('decoded_audio_bytes', 'bytes') |
58 AddResult('time_to_play', 'sec') | 60 AddResults('decoded_video_bytes', 'bytes') |
59 AddResult('playback_time', 'sec') | 61 AddResults('decoded_frame_count', 'frames') |
60 AddResult('decoded_audio_bytes', 'bytes') | 62 AddResults('dropped_frame_count', 'frames') |
61 AddResult('decoded_video_bytes', 'bytes') | 63 AddResults('playback_time', 'sec') |
62 AddResult('decoded_frame_count', 'frames') | 64 AddResults('seek', 'sec') |
63 AddResult('dropped_frame_count', 'frames') | 65 AddResults('time_to_play', 'sec') |
OLD | NEW |