{"version":3,"sources":["../../src/lib/stats.ts"],"names":["Stat","Stats","constructor","options","id","stats","_initializeStats","Object","seal","get","name","type","_getOrCreate","size","keys","length","reset","stat","values","forEach","fn","getTable","table","time","count","average","getAverageTime","hz","getHz","result"],"mappings":"OAEOA,I;AAUP,eAAe,MAAMC,KAAN,CAAY;AAIzBC,EAAAA,WAAW,CAACC,OAAD,EAAkF;AAAA,SAHpFC,EAGoF;AAAA,SAFpFC,KAEoF,GAFtD,EAEsD;AAC3F,SAAKD,EAAL,GAAUD,OAAO,CAACC,EAAlB;AACA,SAAKC,KAAL,GAAa,EAAb;;AAEA,SAAKC,gBAAL,CAAsBH,OAAO,CAACE,KAA9B;;AAEAE,IAAAA,MAAM,CAACC,IAAP,CAAY,IAAZ;AACD;;AAGDC,EAAAA,GAAG,CAACC,IAAD,EAA6C;AAAA,QAA9BC,IAA8B,uEAAf,OAAe;AAC9C,WAAO,KAAKC,YAAL,CAAkB;AAACF,MAAAA,IAAD;AAAOC,MAAAA;AAAP,KAAlB,CAAP;AACD;;AAEO,MAAJE,IAAI,GAAW;AACjB,WAAON,MAAM,CAACO,IAAP,CAAY,KAAKT,KAAjB,EAAwBU,MAA/B;AACD;;AAGDC,EAAAA,KAAK,GAAS;AACZ,SAAK,MAAMC,IAAX,IAAmBV,MAAM,CAACW,MAAP,CAAc,KAAKb,KAAnB,CAAnB,EAA8C;AAC5CY,MAAAA,IAAI,CAACD,KAAL;AACD;;AAED,WAAO,IAAP;AACD;;AAEDG,EAAAA,OAAO,CAACC,EAAD,EAAiC;AACtC,SAAK,MAAMH,IAAX,IAAmBV,MAAM,CAACW,MAAP,CAAc,KAAKb,KAAnB,CAAnB,EAA8C;AAC5Ce,MAAAA,EAAE,CAACH,IAAD,CAAF;AACD;AACF;;AAEDI,EAAAA,QAAQ,GAA+B;AACrC,UAAMC,KAAiC,GAAG,EAA1C;AACA,SAAKH,OAAL,CAAaF,IAAI,IAAI;AACnBK,MAAAA,KAAK,CAACL,IAAI,CAACP,IAAN,CAAL,GAAmB;AACjBa,QAAAA,IAAI,EAAEN,IAAI,CAACM,IAAL,IAAa,CADF;AAEjBC,QAAAA,KAAK,EAAEP,IAAI,CAACO,KAAL,IAAc,CAFJ;AAGjBC,QAAAA,OAAO,EAAER,IAAI,CAACS,cAAL,MAAyB,CAHjB;AAIjBC,QAAAA,EAAE,EAAEV,IAAI,CAACW,KAAL,MAAgB;AAJH,OAAnB;AAMD,KAPD;AASA,WAAON,KAAP;AACD;;AAEDhB,EAAAA,gBAAgB,GAAqE;AAAA,QAApED,KAAoE,uEAAV,EAAU;AACnFA,IAAAA,KAAK,CAACc,OAAN,CAAcF,IAAI,IAAI,KAAKL,YAAL,CAAkBK,IAAlB,CAAtB;AACD;;AAEDL,EAAAA,YAAY,CAACK,IAAD,EAAmD;AAC7D,UAAM;AAACP,MAAAA,IAAD;AAAOC,MAAAA;AAAP,QAAeM,IAArB;AACA,QAAIY,MAAM,GAAG,KAAKxB,KAAL,CAAWK,IAAX,CAAb;;AACA,QAAI,CAACmB,MAAL,EAAa;AACX,UAAIZ,IAAI,YAAYjB,IAApB,EAA0B;AACxB6B,QAAAA,MAAM,GAAGZ,IAAT;AACD,OAFD,MAEO;AACLY,QAAAA,MAAM,GAAG,IAAI7B,IAAJ,CAASU,IAAT,EAAeC,IAAf,CAAT;AACD;;AACD,WAAKN,KAAL,CAAWK,IAAX,IAAmBmB,MAAnB;AACD;;AACD,WAAOA,MAAP;AACD;;AAnEwB","sourcesContent":["// probe.gl, MIT license\n\nimport Stat from './stat';\n\ntype TableEntry = {\n time: number;\n count: number;\n average: number;\n hz: number;\n};\n\n/** A \"bag\" of `Stat` objects, can be visualized using `StatsWidget` */\nexport default class Stats {\n readonly id: string;\n readonly stats: Record = {};\n\n constructor(options: {id: string; stats?: Stats | Stat[] | {name: string; type?: string}[]}) {\n this.id = options.id;\n this.stats = {};\n\n this._initializeStats(options.stats);\n\n Object.seal(this);\n }\n\n /** Acquire a stat. Create if it doesn't exist. */\n get(name: string, type: string = 'count'): Stat {\n return this._getOrCreate({name, type});\n }\n\n get size(): number {\n return Object.keys(this.stats).length;\n }\n\n /** Reset all stats */\n reset(): this {\n for (const stat of Object.values(this.stats)) {\n stat.reset();\n }\n\n return this;\n }\n\n forEach(fn: (stat: Stat) => void): void {\n for (const stat of Object.values(this.stats)) {\n fn(stat);\n }\n }\n\n getTable(): Record {\n const table: Record = {};\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\n return table;\n }\n\n _initializeStats(stats: Stats | Stat[] | {name: string; type?: string}[] = []): void {\n stats.forEach(stat => this._getOrCreate(stat));\n }\n\n _getOrCreate(stat: Stat | {name: string, type?: string}): Stat {\n const {name, type} = stat;\n let result = this.stats[name];\n if (!result) {\n if (stat instanceof Stat) {\n result = stat;\n } else {\n result = new Stat(name, type);\n }\n this.stats[name] = result;\n }\n return result;\n }\n}\n"],"file":"stats.js"}