{ "version": 3, "sources": ["index.js", "utils/hi-res-timestamp.js", "lib/stat.js", "lib/stats.js"], "sourcesContent": ["export { default as Stats } from \"./lib/stats.js\";\nexport { default as Stat } from \"./lib/stat.js\";\n// UTILITIES\nexport { default as _getHiResTimestamp } from \"./utils/hi-res-timestamp.js\";\n", "// Copyright (c) 2017 Uber Technologies, Inc.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\nexport default function getHiResTimestamp() {\n let timestamp;\n // Get best timer available.\n if (typeof window !== 'undefined' && window.performance) {\n timestamp = window.performance.now();\n }\n else if (typeof process !== 'undefined' && process.hrtime) {\n const timeParts = process.hrtime();\n timestamp = timeParts[0] * 1000 + timeParts[1] / 1e6;\n }\n else {\n timestamp = Date.now();\n }\n return timestamp;\n}\n", "import getHiResTimestamp from \"../utils/hi-res-timestamp.js\";\nexport default class Stat {\n constructor(name, type) {\n this.sampleSize = 1;\n this.time = 0;\n this.count = 0;\n this.samples = 0;\n this.lastTiming = 0;\n this.lastSampleTime = 0;\n this.lastSampleCount = 0;\n this._count = 0;\n this._time = 0;\n this._samples = 0;\n this._startTime = 0;\n this._timerPending = false;\n this.name = name;\n this.type = type;\n this.reset();\n }\n reset() {\n this.time = 0;\n this.count = 0;\n this.samples = 0;\n this.lastTiming = 0;\n this.lastSampleTime = 0;\n this.lastSampleCount = 0;\n this._count = 0;\n this._time = 0;\n this._samples = 0;\n this._startTime = 0;\n this._timerPending = false;\n return this;\n }\n setSampleSize(samples) {\n this.sampleSize = samples;\n return this;\n }\n /** Call to increment count (+1) */\n incrementCount() {\n this.addCount(1);\n return this;\n }\n /** Call to decrement count (-1) */\n decrementCount() {\n this.subtractCount(1);\n return this;\n }\n /** Increase count */\n addCount(value) {\n this._count += value;\n this._samples++;\n this._checkSampling();\n return this;\n }\n /** Decrease count */\n subtractCount(value) {\n this._count -= value;\n this._samples++;\n this._checkSampling();\n return this;\n }\n /** Add an arbitrary timing and bump the count */\n addTime(time) {\n this._time += time;\n this.lastTiming = time;\n this._samples++;\n this._checkSampling();\n return this;\n }\n /** Start a timer */\n timeStart() {\n this._startTime = getHiResTimestamp();\n this._timerPending = true;\n return this;\n }\n /** End a timer. Adds to time and bumps the timing count. */\n timeEnd() {\n if (!this._timerPending) {\n return this;\n }\n this.addTime(getHiResTimestamp() - this._startTime);\n this._timerPending = false;\n this._checkSampling();\n return this;\n }\n getSampleAverageCount() {\n return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;\n }\n /** Calculate average time / count for the previous window */\n getSampleAverageTime() {\n return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;\n }\n /** Calculate counts per second for the previous window */\n getSampleHz() {\n return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1000) : 0;\n }\n getAverageCount() {\n return this.samples > 0 ? this.count / this.samples : 0;\n }\n /** Calculate average time / count */\n getAverageTime() {\n return this.samples > 0 ? this.time / this.samples : 0;\n }\n /** Calculate counts per second */\n getHz() {\n return this.time > 0 ? this.samples / (this.time / 1000) : 0;\n }\n _checkSampling() {\n if (this._samples === this.sampleSize) {\n this.lastSampleTime = this._time;\n this.lastSampleCount = this._count;\n this.count += this._count;\n this.time += this._time;\n this.samples += this._samples;\n this._time = 0;\n this._count = 0;\n this._samples = 0;\n }\n }\n}\n", "// probe.gl, MIT license\nimport Stat from \"./stat.js\";\n/** A \"bag\" of `Stat` objects, can be visualized using `StatsWidget` */\nexport default class Stats {\n constructor(options) {\n this.stats = {};\n this.id = options.id;\n this.stats = {};\n this._initializeStats(options.stats);\n Object.seal(this);\n }\n /** Acquire a stat. Create if it doesn't exist. */\n get(name, type = 'count') {\n return this._getOrCreate({ name, type });\n }\n get size() {\n return Object.keys(this.stats).length;\n }\n /** Reset all stats */\n reset() {\n for (const stat of Object.values(this.stats)) {\n stat.reset();\n }\n return this;\n }\n forEach(fn) {\n for (const stat of Object.values(this.stats)) {\n fn(stat);\n }\n }\n getTable() {\n const table = {};\n this.forEach(stat => {\n table[stat.name] = {\n time: stat.time || 0,\n count: stat.count || 0,\n average: stat.getAverageTime() || 0,\n hz: stat.getHz() || 0\n };\n });\n return table;\n }\n _initializeStats(stats = []) {\n stats.forEach(stat => this._getOrCreate(stat));\n }\n _getOrCreate(stat) {\n const { name, type } = stat;\n let result = this.stats[name];\n if (!result) {\n if (stat instanceof Stat) {\n result = stat;\n }\n else {\n result = new Stat(name, type);\n }\n this.stats[name] = result;\n }\n return result;\n }\n}\n"], "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmBe,SAAR,oBAAqC;AACxC,MAAI;AAEJ,MAAI,OAAO,WAAW,eAAe,OAAO,aAAa;AACrD,gBAAY,OAAO,YAAY,IAAI;AAAA,EACvC,WACS,OAAO,YAAY,eAAe,QAAQ,QAAQ;AACvD,UAAM,YAAY,QAAQ,OAAO;AACjC,gBAAY,UAAU,CAAC,IAAI,MAAO,UAAU,CAAC,IAAI;AAAA,EACrD,OACK;AACD,gBAAY,KAAK,IAA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