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

Side by Side Diff: remoting/webapp/base/js/stats_accumulator.js

Issue 1811833002: Show max latency on client's status bar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Client code for uploading stats to telemetry server Created 4 years, 9 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * The webapp reads the plugin's connection statistics frequently (once per 7 * The webapp reads the plugin's connection statistics frequently (once per
8 * second). It logs statistics to the server less frequently, to keep 8 * second). It logs statistics to the server less frequently, to keep
9 * bandwidth and storage costs down. This class bridges that gap, by 9 * bandwidth and storage costs down. This class bridges that gap, by
10 * accumulating high-frequency numeric data, and providing statistics 10 * accumulating high-frequency numeric data, and providing statistics
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 var sum = 0; 87 var sum = 0;
88 for (var i = 0; i < values.length; i++) { 88 for (var i = 0; i < values.length; i++) {
89 sum += values[i]; 89 sum += values[i];
90 } 90 }
91 return sum / values.length; 91 return sum / values.length;
92 }; 92 };
93 return this.map(key, calcMean); 93 return this.map(key, calcMean);
94 }; 94 };
95 95
96 /** 96 /**
97 * Finds the max of the values for a given key.
98 *
99 * @param {string} key
100 * @return {number} the max of the values for that key
101 */
102 remoting.StatsAccumulator.prototype.calcMax = function(key) {
103 /**
104 * @param {Array<number>} values
105 * @return {number}
106 */
107 var calcMax = function(values) {
108 if (values.length == 0) {
kelvinp 2016/03/21 19:14:36 can be simplified as var calcMax = function(valu
Yuwei 2016/03/21 19:29:25 Acknowledged. Interesting that Math.max doesn't ha
109 return 0.0;
110 }
111 var max = -1;
112 for (var i = 0; i < values.length; i++) {
113 if (max < values[i]) {
114 max = values[i];
115 }
116 }
117 return max;
118 };
119 return this.map(key, calcMax);
120 };
121
122 // Can refactor calcMean and calcMax in functional way
Sergey Ulanov 2016/03/21 19:35:06 If there is a good reason to refactor them then th
Yuwei 2016/03/21 19:59:40 Acknowledged.
123
124 /**
97 * Applies a given map to the list of values for a given key. 125 * Applies a given map to the list of values for a given key.
98 * 126 *
99 * @param {string} key 127 * @param {string} key
100 * @param {function(Array<number>): number} map 128 * @param {function(Array<number>): number} map
101 * @return {number} the result of applying that map to the list of values for 129 * @return {number} the result of applying that map to the list of values for
102 * that key 130 * that key
103 */ 131 */
104 remoting.StatsAccumulator.prototype.map = function(key, map) { 132 remoting.StatsAccumulator.prototype.map = function(key, map) {
105 return map(this.getValueList(key)); 133 return map(this.getValueList(key));
106 }; 134 };
(...skipping 22 matching lines...) Expand all
129 */ 157 */
130 remoting.StatsAccumulator.prototype.getPerfStats = function() { 158 remoting.StatsAccumulator.prototype.getPerfStats = function() {
131 var stats = new remoting.ClientSession.PerfStats(); 159 var stats = new remoting.ClientSession.PerfStats();
132 stats.videoBandwidth = this.calcMean('videoBandwidth'); 160 stats.videoBandwidth = this.calcMean('videoBandwidth');
133 stats.captureLatency = this.calcMean('captureLatency'); 161 stats.captureLatency = this.calcMean('captureLatency');
134 stats.encodeLatency = this.calcMean('encodeLatency'); 162 stats.encodeLatency = this.calcMean('encodeLatency');
135 stats.decodeLatency = this.calcMean('decodeLatency'); 163 stats.decodeLatency = this.calcMean('decodeLatency');
136 stats.renderLatency = this.calcMean('renderLatency'); 164 stats.renderLatency = this.calcMean('renderLatency');
137 stats.roundtripLatency = this.calcMean('roundtripLatency'); 165 stats.roundtripLatency = this.calcMean('roundtripLatency');
138 166
167 stats.maxCaptureLatency = this.calcMax('maxCaptureLatency');
168 stats.maxEncodeLatency = this.calcMax('maxEncodeLatency');
169 stats.maxDecodeLatency = this.calcMax('maxDecodeLatency');
170 stats.maxRenderLatency = this.calcMax('maxRenderLatency');
171 stats.maxRoundtripLatency = this.calcMax('maxRoundtripLatency');
172
139 for (var key in stats) { 173 for (var key in stats) {
140 if (stats[key] !== 0) { 174 if (stats[key] !== 0) {
141 return stats; 175 return stats;
142 } 176 }
143 } 177 }
144 return null; 178 return null;
145 }; 179 };
OLDNEW
« remoting/client/plugin/chromoting_instance.cc ('K') | « remoting/webapp/base/js/session_logger.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698