"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _hiResTimestamp = _interopRequireDefault(require("../utils/hi-res-timestamp")); var Stat = function () { function Stat(name, type) { (0, _classCallCheck2.default)(this, Stat); (0, _defineProperty2.default)(this, "name", void 0); (0, _defineProperty2.default)(this, "type", void 0); (0, _defineProperty2.default)(this, "sampleSize", 1); (0, _defineProperty2.default)(this, "time", void 0); (0, _defineProperty2.default)(this, "count", void 0); (0, _defineProperty2.default)(this, "samples", void 0); (0, _defineProperty2.default)(this, "lastTiming", void 0); (0, _defineProperty2.default)(this, "lastSampleTime", void 0); (0, _defineProperty2.default)(this, "lastSampleCount", void 0); (0, _defineProperty2.default)(this, "_count", 0); (0, _defineProperty2.default)(this, "_time", 0); (0, _defineProperty2.default)(this, "_samples", 0); (0, _defineProperty2.default)(this, "_startTime", 0); (0, _defineProperty2.default)(this, "_timerPending", false); this.name = name; this.type = type; this.reset(); } (0, _createClass2.default)(Stat, [{ key: "setSampleSize", value: function setSampleSize(samples) { this.sampleSize = samples; return this; } }, { key: "incrementCount", value: function incrementCount() { this.addCount(1); return this; } }, { key: "decrementCount", value: function decrementCount() { this.subtractCount(1); return this; } }, { key: "addCount", value: function addCount(value) { this._count += value; this._samples++; this._checkSampling(); return this; } }, { key: "subtractCount", value: function subtractCount(value) { this._count -= value; this._samples++; this._checkSampling(); return this; } }, { key: "addTime", value: function addTime(time) { this._time += time; this.lastTiming = time; this._samples++; this._checkSampling(); return this; } }, { key: "timeStart", value: function timeStart() { this._startTime = (0, _hiResTimestamp.default)(); this._timerPending = true; return this; } }, { key: "timeEnd", value: function timeEnd() { if (!this._timerPending) { return this; } this.addTime((0, _hiResTimestamp.default)() - this._startTime); this._timerPending = false; this._checkSampling(); return this; } }, { key: "getSampleAverageCount", value: function getSampleAverageCount() { return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0; } }, { key: "getSampleAverageTime", value: function getSampleAverageTime() { return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0; } }, { key: "getSampleHz", value: function getSampleHz() { return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1000) : 0; } }, { key: "getAverageCount", value: function getAverageCount() { return this.samples > 0 ? this.count / this.samples : 0; } }, { key: "getAverageTime", value: function getAverageTime() { return this.samples > 0 ? this.time / this.samples : 0; } }, { key: "getHz", value: function getHz() { return this.time > 0 ? this.samples / (this.time / 1000) : 0; } }, { key: "reset", value: function reset() { this.time = 0; this.count = 0; this.samples = 0; this.lastTiming = 0; this.lastSampleTime = 0; this.lastSampleCount = 0; this._count = 0; this._time = 0; this._samples = 0; this._startTime = 0; this._timerPending = false; return this; } }, { key: "_checkSampling", value: function _checkSampling() { if (this._samples === this.sampleSize) { this.lastSampleTime = this._time; this.lastSampleCount = this._count; this.count += this._count; this.time += this._time; this.samples += this._samples; this._time = 0; this._count = 0; this._samples = 0; } } }]); return Stat; }(); exports.default = Stat; //# sourceMappingURL=stat.js.map