| 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 |
| 11 * summarising that data. | 11 * summarising that data. |
| 12 */ | 12 */ |
| 13 | 13 |
| 14 'use strict'; | 14 'use strict'; |
| 15 | 15 |
| 16 /** @suppress {duplicate} */ | 16 /** @suppress {duplicate} */ |
| 17 var remoting = remoting || {}; | 17 var remoting = remoting || {}; |
| 18 | 18 |
| 19 (function() { |
| 20 |
| 19 /** | 21 /** |
| 20 * @constructor | 22 * @constructor |
| 21 */ | 23 */ |
| 22 remoting.StatsAccumulator = function() { | 24 remoting.StatsAccumulator = function() { |
| 23 /** | 25 /** |
| 24 * A map from names to lists of values. | 26 * A map from names to lists of values. |
| 25 * @private {Object<Array<number>>} | 27 * @private {Object<Array<number>>} |
| 26 */ | 28 */ |
| 27 this.valueLists_ = {}; | 29 this.valueLists_ = {}; |
| 28 | 30 |
| 29 /** | 31 /** |
| 30 * The first time, after this object was most recently initialized or emptied, | 32 * The first time, after this object was most recently initialized or emptied, |
| 31 * at which a value was added to this object. | 33 * at which a value was added to this object. |
| 32 * @private {?number} | 34 * @private {?number} |
| 33 */ | 35 */ |
| 34 this.timeOfFirstValue_ = null; | 36 this.timeOfFirstValue_ = null; |
| 35 }; | 37 }; |
| 36 | 38 |
| 37 /** | 39 /** |
| 38 * Adds values to this object. | 40 * @param {Object<number>} stats |
| 41 * @return {boolean} true if there is any non-zero value in stats, false |
| 42 * otherwise. |
| 43 */ |
| 44 function hasValidField(stats) { |
| 45 for (var key in stats) { |
| 46 if (stats[key] !== 0) { |
| 47 return true; |
| 48 } |
| 49 } |
| 50 return false; |
| 51 } |
| 52 |
| 53 /** |
| 54 * Adds values to this object. Do nothing if newValues has no valid field. |
| 39 * | 55 * |
| 40 * @param {Object<number>} newValues | 56 * @param {Object<number>} newValues |
| 41 */ | 57 */ |
| 42 remoting.StatsAccumulator.prototype.add = function(newValues) { | 58 remoting.StatsAccumulator.prototype.add = function(newValues) { |
| 59 if (!hasValidField(newValues)) { |
| 60 return; |
| 61 } |
| 43 for (var key in newValues) { | 62 for (var key in newValues) { |
| 44 this.getValueList(key).push(newValues[key]); | 63 this.getValueList(key).push(newValues[key]); |
| 45 } | 64 } |
| 46 if (this.timeOfFirstValue_ === null) { | 65 if (this.timeOfFirstValue_ === null) { |
| 47 this.timeOfFirstValue_ = new Date().getTime(); | 66 this.timeOfFirstValue_ = new Date().getTime(); |
| 48 } | 67 } |
| 49 }; | 68 }; |
| 50 | 69 |
| 51 /** | 70 /** |
| 52 * Empties this object. | 71 * Empties this object. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 stats.maxCaptureLatency = this.calcMax('maxCaptureLatency'); | 173 stats.maxCaptureLatency = this.calcMax('maxCaptureLatency'); |
| 155 stats.encodeLatency = this.calcMean('encodeLatency'); | 174 stats.encodeLatency = this.calcMean('encodeLatency'); |
| 156 stats.maxEncodeLatency = this.calcMax('maxEncodeLatency'); | 175 stats.maxEncodeLatency = this.calcMax('maxEncodeLatency'); |
| 157 stats.decodeLatency = this.calcMean('decodeLatency'); | 176 stats.decodeLatency = this.calcMean('decodeLatency'); |
| 158 stats.maxDecodeLatency = this.calcMax('maxDecodeLatency'); | 177 stats.maxDecodeLatency = this.calcMax('maxDecodeLatency'); |
| 159 stats.renderLatency = this.calcMean('renderLatency'); | 178 stats.renderLatency = this.calcMean('renderLatency'); |
| 160 stats.maxRenderLatency = this.calcMax('maxRenderLatency'); | 179 stats.maxRenderLatency = this.calcMax('maxRenderLatency'); |
| 161 stats.roundtripLatency = this.calcMean('roundtripLatency'); | 180 stats.roundtripLatency = this.calcMean('roundtripLatency'); |
| 162 stats.maxRoundtripLatency = this.calcMax('maxRoundtripLatency'); | 181 stats.maxRoundtripLatency = this.calcMax('maxRoundtripLatency'); |
| 163 | 182 |
| 164 for (var key in stats) { | 183 return hasValidField(stats) ? stats : null; |
| 165 if (stats[key] !== 0) { | 184 }; |
| 166 return stats; | 185 |
| 167 } | 186 })(); |
| 168 } | |
| 169 return null; | |
| 170 }; | |
| OLD | NEW |