Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

Commit

Permalink
stats - stat - prevent 0ms timeDiff breaking movingAverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kumavis authored Apr 25, 2019
1 parent c73efba commit 8c922ea
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/stats/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class Stats extends EventEmitter {
* @returns {void}
*/
_updateFrequency (latestTime) {
const timeDiff = latestTime - this._frequencyLastTime
const timeDiff = (latestTime - this._frequencyLastTime) || 1

Object.keys(this._stats).forEach((key) => {
this._updateFrequencyFor(key, timeDiff, latestTime)
Expand All @@ -182,6 +182,8 @@ class Stats extends EventEmitter {
_updateFrequencyFor (key, timeDiffMS, latestTime) {
const count = this._frequencyAccumulators[key] || 0
this._frequencyAccumulators[key] = 0
// if `timeDiff` is zero, `hz` becomes Infinity, so we fallback to 1ms
const safeTimeDiff = timeDiffMS || 1
const hz = (count / timeDiffMS) * 1000

let movingAverages = this._movingAverages[key]
Expand Down

0 comments on commit 8c922ea

Please sign in to comment.