66 lines
2.1 KiB
JavaScript
66 lines
2.1 KiB
JavaScript
// Metro module 5478 (f5479).
|
|
import _classCallCheck from "./_classCallCheck_5425";
|
|
import _createClass from "./_createClass_5426";
|
|
import { ErrorMessages } from "./Module5413";
|
|
import { roundToDecimalPlaces } from "./Module5479";
|
|
let env3365 = {};
|
|
const JSFPSMonitor = function JSFPSMonitor() {
|
|
_classCallCheck(this, JSFPSMonitor);
|
|
this.startTime = 0;
|
|
this.frameCount = 0;
|
|
this.timeWindow = {
|
|
frameCount: 0,
|
|
startTime: 0
|
|
};
|
|
this.minFPS = Number.MAX_SAFE_INTEGER;
|
|
this.maxFPS = 0;
|
|
this.averageFPS = 0;
|
|
this.clearAnimationNumber = 0;
|
|
this.updateLoopCompute = () => {
|
|
this.frameCount = this.frameCount + 1;
|
|
const r2 = (Date.now() - this.startTime) / 1000;
|
|
this.averageFPS = 0 < r2 ? this.frameCount / r2 : 0;
|
|
const timeWindow = this.timeWindow;
|
|
timeWindow.frameCount = timeWindow.frameCount + 1;
|
|
const r26 = (Date.now() - this.timeWindow.startTime) / 1000;
|
|
if (1 <= r26) {
|
|
const r30 = this.timeWindow.frameCount / r26;
|
|
this.minFPS = Math.min(this.minFPS, r30);
|
|
this.maxFPS = Math.max(this.maxFPS, r30);
|
|
this.timeWindow.frameCount = 0;
|
|
this.timeWindow.startTime = Date.now();
|
|
}
|
|
this.measureLoop();
|
|
};
|
|
};
|
|
exports.JSFPSMonitor = _createClass(JSFPSMonitor, [{
|
|
key: "measureLoop",
|
|
value: function measureLoop() {
|
|
this.clearAnimationNumber = requestAnimationFrame(this.updateLoopCompute);
|
|
}
|
|
}, {
|
|
key: "startTracking",
|
|
value: function startTracking() {
|
|
if (this.startTime !== 0) {
|
|
throw new Error(ErrorMessages.fpsMonitorAlreadyRunning);
|
|
}
|
|
this.startTime = Date.now();
|
|
this.timeWindow.startTime = Date.now();
|
|
this.measureLoop();
|
|
}
|
|
}, {
|
|
key: "stopAndGetData",
|
|
value: function stopAndGetData() {
|
|
cancelAnimationFrame(this.clearAnimationNumber);
|
|
if (this.minFPS === Number.MAX_SAFE_INTEGER) {
|
|
this.minFPS = this.averageFPS;
|
|
this.maxFPS = this.averageFPS;
|
|
}
|
|
return {
|
|
minFPS: roundToDecimalPlaces(this.minFPS, 1),
|
|
maxFPS: roundToDecimalPlaces(this.maxFPS, 1),
|
|
averageFPS: roundToDecimalPlaces(this.averageFPS, 1)
|
|
};
|
|
}
|
|
}]);
|