Chromium Code Reviews| 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, | |
|
arv (Not doing code reviews)
2011/09/22 19:26:04
no underscores in JS?
arv (Not doing code reviews)
2011/09/22 19:26:04
Don't quote property names unless you have to
scherkus (not reviewing)
2011/09/23 06:52:41
I believe this is a string identifier for an event
| |
| 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': {'start': 'SEEK', | |
|
arv (Not doing code reviews)
2011/09/22 19:26:04
The indentation of this is strange. Please line br
scherkus (not reviewing)
2011/09/23 06:52:41
Done.
| |
| 18 'end': 'pipeline_state=started'}, | |
| 19 'first frame': {'start': 'WEBMEDIAPLAYER_CREATED', | |
| 20 'end': 'pipeline_state=started'}, | |
| 21 }; | |
| 22 | |
| 23 /** | |
| 24 * This class measures times between the events specified above. It inherits | |
| 25 * <li> and contains a table that displays the measurements. | |
| 26 */ | |
| 27 var Metrics = cr.ui.define('li'); | |
| 28 | |
| 29 Metrics.prototype = { | |
| 30 __proto__: HTMLLIElement.prototype, | |
| 31 | |
| 32 /** | |
| 33 * Decorate this <li> as a Metrics. | |
| 34 */ | |
| 35 decorate: function() { | |
| 36 this.table_ = document.createElement('table'); | |
| 37 var details = document.createElement('details'); | |
| 38 var summary = media.makeElement('summary', 'Metrics:'); | |
| 39 details.appendChild(summary); | |
| 40 details.appendChild(this.table_); | |
| 41 this.appendChild(details); | |
| 42 | |
| 43 var hRow = document.createElement('tr'); | |
| 44 hRow.appendChild(media.makeElement('th', 'Metric:')); | |
| 45 hRow.appendChild(media.makeElement('th', 'Last Measure:')); | |
| 46 hRow.appendChild(media.makeElement('th', 'Average:')); | |
| 47 var header = document.createElement('thead'); | |
| 48 header.appendChild(hRow); | |
| 49 this.table_.appendChild(header); | |
| 50 | |
| 51 for (var metric in metrics) { | |
| 52 var last = document.createElement('td'); | |
| 53 var avg = document.createElement('td'); | |
| 54 this[metric] = {'count': 0, 'total': 0, 'start': null, | |
| 55 'last': last, 'avg': avg}; | |
| 56 var row = document.createElement('tr'); | |
| 57 row.appendChild(media.makeElement('td', metric + ':')); | |
| 58 row.appendChild(last); | |
| 59 row.appendChild(avg); | |
| 60 this.table_.appendChild(row); | |
| 61 } | |
| 62 }, | |
| 63 | |
| 64 /** | |
| 65 * An event has occurred. Update any metrics that refer to this type | |
| 66 * of event. Can be called multiple times by addEvent below if the metrics | |
| 67 * refer to specific parameters. | |
| 68 * @param {Object} event The MediaLogEvent that has occurred. | |
| 69 * @param {string} type The type of event. | |
| 70 */ | |
| 71 addEventInternal: function(event, type) { | |
| 72 for (var metric in metrics) { | |
| 73 var m = this[metric]; | |
| 74 if (type == metrics[metric].start && !m.start) { | |
| 75 m.start = event.time; | |
| 76 } else if (type == metrics[metric].end && m.start != null) { | |
| 77 var last = event.time - m.start; | |
| 78 m.last.textContent = media.round(last); | |
| 79 m.total += last; | |
| 80 m.count++; | |
| 81 if (m.count > 1) | |
| 82 m.avg.textContent = round(m.total / m.count); | |
|
arv (Not doing code reviews)
2011/09/22 19:26:04
Math.round?
scherkus (not reviewing)
2011/09/23 06:52:41
I wonder whether this was supposed to be media.rou
| |
| 83 m.start = null; | |
| 84 } | |
| 85 } | |
| 86 }, | |
| 87 | |
| 88 /** | |
| 89 * An event has occurred. Update any metrics that refer to events of this | |
| 90 * type or with this event's parameters. | |
| 91 * @param {Object} event The MediaLogEvent that has occurred. | |
| 92 */ | |
| 93 addEvent: function(event) { | |
| 94 this.addEventInternal(event, event.type); | |
| 95 for (var p in event.params) { | |
| 96 if (p in metricProperties) { | |
| 97 var type = p + '=' + event.params[p]; | |
| 98 this.addEventInternal(event, type); | |
| 99 } | |
| 100 } | |
| 101 }, | |
| 102 }; | |
| 103 | |
| 104 return { | |
| 105 Metrics: Metrics, | |
| 106 }; | |
| 107 }); | |
| OLD | NEW |