Chromium Code Reviews| Index: remoting/webapp/base/js/stats_accumulator.js |
| diff --git a/remoting/webapp/base/js/stats_accumulator.js b/remoting/webapp/base/js/stats_accumulator.js |
| index e0edd49653807203dd25b333d7c5f2af697fc45f..8c50a92e2b56ce699ac9cdbaf013c3ad04f7c295 100644 |
| --- a/remoting/webapp/base/js/stats_accumulator.js |
| +++ b/remoting/webapp/base/js/stats_accumulator.js |
| @@ -94,6 +94,34 @@ remoting.StatsAccumulator.prototype.calcMean = function(key) { |
| }; |
| /** |
| + * Finds the max of the values for a given key. |
| + * |
| + * @param {string} key |
| + * @return {number} the max of the values for that key |
| + */ |
| +remoting.StatsAccumulator.prototype.calcMax = function(key) { |
| + /** |
| + * @param {Array<number>} values |
| + * @return {number} |
| + */ |
| + var calcMax = function(values) { |
| + 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
|
| + return 0.0; |
| + } |
| + var max = -1; |
| + for (var i = 0; i < values.length; i++) { |
| + if (max < values[i]) { |
| + max = values[i]; |
| + } |
| + } |
| + return max; |
| + }; |
| + return this.map(key, calcMax); |
| +}; |
| + |
| +// 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.
|
| + |
| +/** |
| * Applies a given map to the list of values for a given key. |
| * |
| * @param {string} key |
| @@ -136,6 +164,12 @@ remoting.StatsAccumulator.prototype.getPerfStats = function() { |
| stats.renderLatency = this.calcMean('renderLatency'); |
| stats.roundtripLatency = this.calcMean('roundtripLatency'); |
| + stats.maxCaptureLatency = this.calcMax('maxCaptureLatency'); |
| + stats.maxEncodeLatency = this.calcMax('maxEncodeLatency'); |
| + stats.maxDecodeLatency = this.calcMax('maxDecodeLatency'); |
| + stats.maxRenderLatency = this.calcMax('maxRenderLatency'); |
| + stats.maxRoundtripLatency = this.calcMax('maxRoundtripLatency'); |
| + |
| for (var key in stats) { |
| if (stats[key] !== 0) { |
| return stats; |