OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 cr.define('media', function() { | |
6 'use strict'; | |
7 | |
8 // A set of parameter names. An entry of 'abc' allows metrics to specify | |
9 // events with specific values of 'abc'. | |
10 var metricProperties = { | |
11 'pipeline_state': true, | |
12 }; | |
13 | |
14 // A set of metrics to measure. The user will see the most recent and average | |
15 // measurement of the time between each metric's start and end events. | |
16 var metrics = { | |
17 'seek': { | |
18 'start': 'SEEK', | |
19 'end': 'pipeline_state=started' | |
20 }, | |
21 'first frame': { | |
22 'start': 'WEBMEDIAPLAYER_CREATED', | |
23 'end': 'pipeline_state=started' | |
24 }, | |
25 }; | |
26 | |
27 /** | |
28 * This class measures times between the events specified above. It inherits | |
29 * <li> and contains a table that displays the measurements. | |
30 */ | |
31 var Metrics = cr.ui.define('li'); | |
32 | |
33 Metrics.prototype = { | |
34 __proto__: HTMLLIElement.prototype, | |
35 | |
36 /** | |
37 * Decorate this <li> as a Metrics. | |
38 */ | |
39 decorate: function() { | |
40 this.table_ = document.createElement('table'); | |
41 var details = document.createElement('details'); | |
42 var summary = media.makeElement('summary', 'Metrics:'); | |
43 details.appendChild(summary); | |
44 details.appendChild(this.table_); | |
45 this.appendChild(details); | |
46 | |
47 var hRow = document.createElement('tr'); | |
48 hRow.appendChild(media.makeElement('th', 'Metric:')); | |
49 hRow.appendChild(media.makeElement('th', 'Last Measure:')); | |
50 hRow.appendChild(media.makeElement('th', 'Average:')); | |
51 var header = document.createElement('thead'); | |
52 header.appendChild(hRow); | |
53 this.table_.appendChild(header); | |
54 | |
55 for (var metric in metrics) { | |
56 var last = document.createElement('td'); | |
57 var avg = document.createElement('td'); | |
58 this[metric] = {'count': 0, 'total': 0, 'start': null, | |
arv (Not doing code reviews)
2011/09/23 15:59:01
this[metric] = {
count: 0,
total: 0,
start:
scherkus (not reviewing)
2011/09/23 17:43:23
Done.
| |
59 'last': last, 'avg': avg}; | |
60 var row = document.createElement('tr'); | |
61 row.appendChild(media.makeElement('td', metric + ':')); | |
62 row.appendChild(last); | |
63 row.appendChild(avg); | |
64 this.table_.appendChild(row); | |
65 } | |
66 }, | |
67 | |
68 /** | |
69 * An event has occurred. Update any metrics that refer to this type | |
70 * of event. Can be called multiple times by addEvent below if the metrics | |
71 * refer to specific parameters. | |
72 * @param {Object} event The MediaLogEvent that has occurred. | |
73 * @param {string} type The type of event. | |
74 */ | |
75 addEventInternal: function(event, type) { | |
76 for (var metric in metrics) { | |
77 var m = this[metric]; | |
78 if (type == metrics[metric].start && !m.start) { | |
79 m.start = event.time; | |
80 } else if (type == metrics[metric].end && m.start != null) { | |
81 var last = event.time - m.start; | |
82 m.last.textContent = media.round(last); | |
83 m.total += last; | |
84 m.count++; | |
85 if (m.count > 1) | |
86 m.avg.textContent = media.round(m.total / m.count); | |
87 m.start = null; | |
88 } | |
89 } | |
90 }, | |
91 | |
92 /** | |
93 * An event has occurred. Update any metrics that refer to events of this | |
94 * type or with this event's parameters. | |
95 * @param {Object} event The MediaLogEvent that has occurred. | |
96 */ | |
97 addEvent: function(event) { | |
98 this.addEventInternal(event, event.type); | |
99 for (var p in event.params) { | |
100 if (p in metricProperties) { | |
101 var type = p + '=' + event.params[p]; | |
102 this.addEventInternal(event, type); | |
103 } | |
104 } | |
105 }, | |
106 }; | |
107 | |
108 return { | |
109 Metrics: Metrics, | |
110 }; | |
111 }); | |
OLD | NEW |