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

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

Issue 7653001: Display active media players on chrome://media-internals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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
7 // A set of parameter names. An entry of 'abc' allows metrics to specify
8 // events with specific values of 'abc'.
9 metricProperties = {
arv (Not doing code reviews) 2011/08/16 19:29:03 missing vars again
Scott Franklin 2011/08/16 23:33:52 Done.
10 'pipeline_state': true,
11 };
12
13 // A set of metrics to measure. The user will see the most recent and average
14 // measurement of the time between each metric's start and end events.
15 metrics = {
16 'seek': {'start': 'SEEK',
17 'end': 'pipeline_state=started'},
18 'first frame': {'start': 'WEBMEDIAPLAYER_CREATED',
19 'end': 'pipeline_state=started'},
20 };
21
22 /**
23 * This class measures times between the events specified above. It exposes
24 * this.li, a <li> element containing a table that displays the measurements.
25 */
26 function Metrics() {
27 this.table_ = document.createElement('table');
28 this.li = createDetailsLi();
29 this.li.details.appendChild(this.table_);
30 this.li.summary.textContent = 'Metrics:';
31
32 var hrow = document.createElement('tr');
33 hrow.appendChild(makeElement('th', 'Metric:'));
34 hrow.appendChild(makeElement('th', 'Last Measure:'));
35 hrow.appendChild(makeElement('th', 'Average:'));
36 var header = document.createElement('thead');
37 header.appendChild(hrow);
38 this.table_.appendChild(header);
39
40 for (var metric in metrics) {
41 var last = document.createElement('td');
42 var avg = document.createElement('td');
43 this[metric] = {'count': 0, 'total': 0, 'start': null,
44 'last': last, 'avg': avg};
45 var row = document.createElement('tr');
46 row.appendChild(makeElement('td', metric + ':'));
47 row.appendChild(last);
48 row.appendChild(avg);
49 this.table_.appendChild(row);
50 }
51 };
52
53 Metrics.prototype = {
54
55 /**
56 * An event has occurred. Update any metrics that refer to this type
57 * of event. Can be called multiple times by addEvent below if the metrics
58 * refer to specific parameters.
59 * @param {Object} event The MediaLogEvent that has occurred.
60 * @param {string} type The type of event.
61 */
62 addEventInternal: function(event, type) {
63 for (var metric in metrics) {
64 var m = this[metric];
65 if (type == metrics[metric].start && !m.start) {
66 m.start = event.time;
67 } else if (type == metrics[metric].end && m.start != null) {
68 var last = event.time - m.start;
69 m.last.textContent = media.round(last);
70 m.total += last;
71 m.count++;
72 if (m.count > 1)
73 m.avg.textContent = round(m.total / m.count);
74 m.start = null;
75 }
76 }
77 },
78
79 /**
80 * An event has occurred. Update any metrics that refer to events of this
81 * type or with this events parameters.
82 * @param {Object} event The MediaLogEvent that has occurred.
83 */
84 addEvent: function(event) {
85 this.addEventInternal(event, event.type);
86 for (var p in event.params) {
87 if (p in metricProperties) {
88 var type = p + '=' + event.params[p];
89 this.addEventInternal(event, type);
90 }
91 }
92 },
93 };
94
95 return {
96 Metrics: Metrics,
97 };
98 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698