| OLD | NEW |
| 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 Loading... |
| 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 || !values.length) { | |
| 109 return 0; | |
| 110 } | |
| 111 return Math.max.apply(null, values); | |
| 112 }; | |
| 113 return this.map(key, calcMax); | |
| 114 }; | |
| 115 | |
| 116 /** | |
| 117 * Applies a given map to the list of values for a given key. | 97 * Applies a given map to the list of values for a given key. |
| 118 * | 98 * |
| 119 * @param {string} key | 99 * @param {string} key |
| 120 * @param {function(Array<number>): number} map | 100 * @param {function(Array<number>): number} map |
| 121 * @return {number} the result of applying that map to the list of values for | 101 * @return {number} the result of applying that map to the list of values for |
| 122 * that key | 102 * that key |
| 123 */ | 103 */ |
| 124 remoting.StatsAccumulator.prototype.map = function(key, map) { | 104 remoting.StatsAccumulator.prototype.map = function(key, map) { |
| 125 return map(this.getValueList(key)); | 105 return map(this.getValueList(key)); |
| 126 }; | 106 }; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 144 }; | 124 }; |
| 145 | 125 |
| 146 /** | 126 /** |
| 147 * @return {?remoting.ClientSession.PerfStats} returns null if all fields are | 127 * @return {?remoting.ClientSession.PerfStats} returns null if all fields are |
| 148 * zero. | 128 * zero. |
| 149 */ | 129 */ |
| 150 remoting.StatsAccumulator.prototype.getPerfStats = function() { | 130 remoting.StatsAccumulator.prototype.getPerfStats = function() { |
| 151 var stats = new remoting.ClientSession.PerfStats(); | 131 var stats = new remoting.ClientSession.PerfStats(); |
| 152 stats.videoBandwidth = this.calcMean('videoBandwidth'); | 132 stats.videoBandwidth = this.calcMean('videoBandwidth'); |
| 153 stats.captureLatency = this.calcMean('captureLatency'); | 133 stats.captureLatency = this.calcMean('captureLatency'); |
| 154 stats.maxCaptureLatency = this.calcMax('maxCaptureLatency'); | |
| 155 stats.encodeLatency = this.calcMean('encodeLatency'); | 134 stats.encodeLatency = this.calcMean('encodeLatency'); |
| 156 stats.maxEncodeLatency = this.calcMax('maxEncodeLatency'); | |
| 157 stats.decodeLatency = this.calcMean('decodeLatency'); | 135 stats.decodeLatency = this.calcMean('decodeLatency'); |
| 158 stats.maxDecodeLatency = this.calcMax('maxDecodeLatency'); | |
| 159 stats.renderLatency = this.calcMean('renderLatency'); | 136 stats.renderLatency = this.calcMean('renderLatency'); |
| 160 stats.maxRenderLatency = this.calcMax('maxRenderLatency'); | |
| 161 stats.roundtripLatency = this.calcMean('roundtripLatency'); | 137 stats.roundtripLatency = this.calcMean('roundtripLatency'); |
| 162 stats.maxRoundtripLatency = this.calcMax('maxRoundtripLatency'); | |
| 163 | 138 |
| 164 for (var key in stats) { | 139 for (var key in stats) { |
| 165 if (stats[key] !== 0) { | 140 if (stats[key] !== 0) { |
| 166 return stats; | 141 return stats; |
| 167 } | 142 } |
| 168 } | 143 } |
| 169 return null; | 144 return null; |
| 170 }; | 145 }; |
| OLD | NEW |