| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394 |
- function _defineProperty(obj, key, value) {
- if (key in obj) {
- Object.defineProperty(obj, key, {
- value,
- enumerable: true,
- configurable: true,
- writable: true
- });
- } else {
- obj[key] = value;
- }
- return obj;
- }
- function defaultSetTimout() {
- throw new Error("setTimeout has not been defined");
- }
- function defaultClearTimeout() {
- throw new Error("clearTimeout has not been defined");
- }
- var cachedSetTimeout = defaultSetTimout;
- var cachedClearTimeout = defaultClearTimeout;
- var globalContext;
- if (typeof window !== "undefined") {
- globalContext = window;
- } else if (typeof self !== "undefined") {
- globalContext = self;
- } else {
- globalContext = {};
- }
- if (typeof globalContext.setTimeout === "function") {
- cachedSetTimeout = setTimeout;
- }
- if (typeof globalContext.clearTimeout === "function") {
- cachedClearTimeout = clearTimeout;
- }
- function runTimeout(fun) {
- if (cachedSetTimeout === setTimeout) {
- return setTimeout(fun, 0);
- }
- if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
- cachedSetTimeout = setTimeout;
- return setTimeout(fun, 0);
- }
- try {
- return cachedSetTimeout(fun, 0);
- } catch (e) {
- try {
- return cachedSetTimeout.call(null, fun, 0);
- } catch (e2) {
- return cachedSetTimeout.call(this, fun, 0);
- }
- }
- }
- function runClearTimeout(marker) {
- if (cachedClearTimeout === clearTimeout) {
- return clearTimeout(marker);
- }
- if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
- cachedClearTimeout = clearTimeout;
- return clearTimeout(marker);
- }
- try {
- return cachedClearTimeout(marker);
- } catch (e) {
- try {
- return cachedClearTimeout.call(null, marker);
- } catch (e2) {
- return cachedClearTimeout.call(this, marker);
- }
- }
- }
- var queue = [];
- var draining = false;
- var currentQueue;
- var queueIndex = -1;
- function cleanUpNextTick() {
- if (!draining || !currentQueue) {
- return;
- }
- draining = false;
- if (currentQueue.length) {
- queue = currentQueue.concat(queue);
- } else {
- queueIndex = -1;
- }
- if (queue.length) {
- drainQueue();
- }
- }
- function drainQueue() {
- if (draining) {
- return;
- }
- var timeout = runTimeout(cleanUpNextTick);
- draining = true;
- var len = queue.length;
- while (len) {
- currentQueue = queue;
- queue = [];
- while (++queueIndex < len) {
- if (currentQueue) {
- currentQueue[queueIndex].run();
- }
- }
- queueIndex = -1;
- len = queue.length;
- }
- currentQueue = null;
- draining = false;
- runClearTimeout(timeout);
- }
- function nextTick(fun) {
- var args = new Array(arguments.length - 1);
- if (arguments.length > 1) {
- for (var i = 1; i < arguments.length; i++) {
- args[i - 1] = arguments[i];
- }
- }
- queue.push(new Item(fun, args));
- if (queue.length === 1 && !draining) {
- runTimeout(drainQueue);
- }
- }
- function Item(fun, array) {
- this.fun = fun;
- this.array = array;
- }
- Item.prototype.run = function() {
- this.fun.apply(null, this.array);
- };
- var title = "browser";
- var platform = "browser";
- var browser = true;
- var argv = [];
- var version = "";
- var versions = {};
- var release = {};
- var config = {};
- function noop() {
- }
- var on = noop;
- var addListener = noop;
- var once = noop;
- var off = noop;
- var removeListener = noop;
- var removeAllListeners = noop;
- var emit = noop;
- function binding(name) {
- throw new Error("process.binding is not supported");
- }
- function cwd() {
- return "/";
- }
- function chdir(dir) {
- throw new Error("process.chdir is not supported");
- }
- function umask() {
- return 0;
- }
- var performance = globalContext.performance || {};
- var performanceNow = performance.now || performance.mozNow || performance.msNow || performance.oNow || performance.webkitNow || function() {
- return new Date().getTime();
- };
- function hrtime(previousTimestamp) {
- var clocktime = performanceNow.call(performance) * 1e-3;
- var seconds = Math.floor(clocktime);
- var nanoseconds = Math.floor(clocktime % 1 * 1e9);
- if (previousTimestamp) {
- seconds = seconds - previousTimestamp[0];
- nanoseconds = nanoseconds - previousTimestamp[1];
- if (nanoseconds < 0) {
- seconds--;
- nanoseconds += 1e9;
- }
- }
- return [seconds, nanoseconds];
- }
- var startTime = new Date();
- function uptime() {
- var currentTime = new Date();
- var dif = currentTime - startTime;
- return dif / 1e3;
- }
- var process = {
- nextTick,
- title,
- browser,
- env: {NODE_ENV: "production"},
- argv,
- version,
- versions,
- on,
- addListener,
- once,
- off,
- removeListener,
- removeAllListeners,
- emit,
- binding,
- cwd,
- chdir,
- umask,
- hrtime,
- platform,
- release,
- config,
- uptime
- };
- function getHiResTimestamp() {
- let timestamp;
- if (typeof window !== "undefined" && window.performance) {
- timestamp = window.performance.now();
- } else if (typeof process !== "undefined" && process.hrtime) {
- const timeParts = process.hrtime();
- timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
- } else {
- timestamp = Date.now();
- }
- return timestamp;
- }
- class Stat {
- constructor(name, type) {
- _defineProperty(this, "name", void 0);
- _defineProperty(this, "type", void 0);
- _defineProperty(this, "sampleSize", 1);
- _defineProperty(this, "time", void 0);
- _defineProperty(this, "count", void 0);
- _defineProperty(this, "samples", void 0);
- _defineProperty(this, "lastTiming", void 0);
- _defineProperty(this, "lastSampleTime", void 0);
- _defineProperty(this, "lastSampleCount", void 0);
- _defineProperty(this, "_count", 0);
- _defineProperty(this, "_time", 0);
- _defineProperty(this, "_samples", 0);
- _defineProperty(this, "_startTime", 0);
- _defineProperty(this, "_timerPending", false);
- this.name = name;
- this.type = type;
- this.reset();
- }
- setSampleSize(samples) {
- this.sampleSize = samples;
- return this;
- }
- incrementCount() {
- this.addCount(1);
- return this;
- }
- decrementCount() {
- this.subtractCount(1);
- return this;
- }
- addCount(value) {
- this._count += value;
- this._samples++;
- this._checkSampling();
- return this;
- }
- subtractCount(value) {
- this._count -= value;
- this._samples++;
- this._checkSampling();
- return this;
- }
- addTime(time) {
- this._time += time;
- this.lastTiming = time;
- this._samples++;
- this._checkSampling();
- return this;
- }
- timeStart() {
- this._startTime = getHiResTimestamp();
- this._timerPending = true;
- return this;
- }
- timeEnd() {
- if (!this._timerPending) {
- return this;
- }
- this.addTime(getHiResTimestamp() - this._startTime);
- this._timerPending = false;
- this._checkSampling();
- return this;
- }
- getSampleAverageCount() {
- return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;
- }
- getSampleAverageTime() {
- return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;
- }
- getSampleHz() {
- return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1e3) : 0;
- }
- getAverageCount() {
- return this.samples > 0 ? this.count / this.samples : 0;
- }
- getAverageTime() {
- return this.samples > 0 ? this.time / this.samples : 0;
- }
- getHz() {
- return this.time > 0 ? this.samples / (this.time / 1e3) : 0;
- }
- 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;
- }
- _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;
- }
- }
- }
- class Stats {
- constructor(options) {
- _defineProperty(this, "id", void 0);
- _defineProperty(this, "stats", {});
- this.id = options.id;
- this.stats = {};
- this._initializeStats(options.stats);
- Object.seal(this);
- }
- get(name, type = "count") {
- return this._getOrCreate({
- name,
- type
- });
- }
- get size() {
- return Object.keys(this.stats).length;
- }
- reset() {
- for (const key in this.stats) {
- this.stats[key].reset();
- }
- return this;
- }
- forEach(fn) {
- for (const key in this.stats) {
- fn(this.stats[key]);
- }
- }
- getTable() {
- const table = {};
- this.forEach((stat) => {
- table[stat.name] = {
- time: stat.time || 0,
- count: stat.count || 0,
- average: stat.getAverageTime() || 0,
- hz: stat.getHz() || 0
- };
- });
- return table;
- }
- _initializeStats(stats = []) {
- stats.forEach((stat) => this._getOrCreate(stat));
- }
- _getOrCreate(stat) {
- if (!stat || !stat.name) {
- return null;
- }
- const {
- name,
- type
- } = stat;
- if (!this.stats[name]) {
- if (stat instanceof Stat) {
- this.stats[name] = stat;
- } else {
- this.stats[name] = new Stat(name, type);
- }
- }
- return this.stats[name];
- }
- }
- export {Stat, Stats, getHiResTimestamp as _getHiResTimestamp};
- export default null;
|