Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: chrome/browser/resources/media_internals/metrics.js

Issue 12153002: Move chrome://media-internals to content. This allows us to hide implementation details from the pu… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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] = {
59 count: 0,
60 total: 0,
61 start: null,
62 last: last,
63 avg: avg
64 };
65 var row = document.createElement('tr');
66 row.appendChild(media.makeElement('td', metric + ':'));
67 row.appendChild(last);
68 row.appendChild(avg);
69 this.table_.appendChild(row);
70 }
71 },
72
73 /**
74 * An event has occurred. Update any metrics that refer to this type
75 * of event. Can be called multiple times by addEvent below if the metrics
76 * refer to specific parameters.
77 * @param {Object} event The MediaLogEvent that has occurred.
78 * @param {string} type The type of event.
79 */
80 addEventInternal: function(event, type) {
81 var timeInMs = event.time * 1000; // Work with milliseconds.
82
83 for (var metric in metrics) {
84 var m = this[metric];
85 if (type == metrics[metric].start && !m.start) {
86 m.start = timeInMs;
87 } else if (type == metrics[metric].end && m.start != null) {
88 var last = timeInMs - m.start;
89 m.last.textContent = last.toFixed(1);
90 m.total += last;
91 m.count++;
92 if (m.count > 1)
93 m.avg.textContent = (m.total / m.count).toFixed(1);
94 m.start = null;
95 }
96 }
97 },
98
99 /**
100 * An event has occurred. Update any metrics that refer to events of this
101 * type or with this event's parameters.
102 * @param {Object} event The MediaLogEvent that has occurred.
103 */
104 addEvent: function(event) {
105 this.addEventInternal(event, event.type);
106 for (var p in event.params) {
107 if (p in metricProperties) {
108 var type = p + '=' + event.params[p];
109 this.addEventInternal(event, type);
110 }
111 }
112 },
113 };
114
115 return {
116 Metrics: Metrics,
117 };
118 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698