{"version":3,"sources":["../../src/lib/stat.ts"],"names":["getHiResTimestamp","Stat","constructor","name","type","sampleSize","time","count","samples","lastTiming","lastSampleTime","lastSampleCount","_count","_time","_samples","_startTime","_timerPending","reset","setSampleSize","incrementCount","addCount","decrementCount","subtractCount","value","_checkSampling","addTime","timeStart","timeEnd","getSampleAverageCount","getSampleAverageTime","getSampleHz","getAverageCount","getAverageTime","getHz"],"mappings":"OAAOA,iB;AAEP,eAAe,MAAMC,IAAN,CAAW;AAiBxBC,EAAAA,WAAW,CAACC,IAAD,EAAeC,IAAf,EAA8B;AAAA,SAhBhCD,IAgBgC;AAAA,SAfhCC,IAegC;AAAA,SAdzCC,UAcyC,GAdpB,CAcoB;AAAA,SAbzCC,IAayC,GAb1B,CAa0B;AAAA,SAZzCC,KAYyC,GAZzB,CAYyB;AAAA,SAXzCC,OAWyC,GAXvB,CAWuB;AAAA,SAVzCC,UAUyC,GAVpB,CAUoB;AAAA,SATzCC,cASyC,GAThB,CASgB;AAAA,SARzCC,eAQyC,GARf,CAQe;AAAA,SANzCC,MAMyC,GANxB,CAMwB;AAAA,SALzCC,KAKyC,GALzB,CAKyB;AAAA,SAJzCC,QAIyC,GAJtB,CAIsB;AAAA,SAHzCC,UAGyC,GAHpB,CAGoB;AAAA,SAFzCC,aAEyC,GAFhB,KAEgB;AACvC,SAAKb,IAAL,GAAYA,IAAZ;AACA,SAAKC,IAAL,GAAYA,IAAZ;AACA,SAAKa,KAAL;AACD;;AAEDA,EAAAA,KAAK,GAAS;AACZ,SAAKX,IAAL,GAAY,CAAZ;AACA,SAAKC,KAAL,GAAa,CAAb;AACA,SAAKC,OAAL,GAAe,CAAf;AACA,SAAKC,UAAL,GAAkB,CAAlB;AACA,SAAKC,cAAL,GAAsB,CAAtB;AACA,SAAKC,eAAL,GAAuB,CAAvB;AACA,SAAKC,MAAL,GAAc,CAAd;AACA,SAAKC,KAAL,GAAa,CAAb;AACA,SAAKC,QAAL,GAAgB,CAAhB;AACA,SAAKC,UA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UAAlD,GAA+D,CAAtE;AACD;;AAGDwB,EAAAA,oBAAoB,GAAW;AAC7B,WAAO,KAAKxB,UAAL,GAAkB,CAAlB,GAAsB,KAAKK,cAAL,GAAsB,KAAKL,UAAjD,GAA8D,CAArE;AACD;;AAGDyB,EAAAA,WAAW,GAAW;AACpB,WAAO,KAAKpB,cAAL,GAAsB,CAAtB,GAA0B,KAAKL,UAAL,IAAmB,KAAKK,cAAL,GAAsB,IAAzC,CAA1B,GAA2E,CAAlF;AACD;;AAEDqB,EAAAA,eAAe,GAAW;AACxB,WAAO,KAAKvB,OAAL,GAAe,CAAf,GAAmB,KAAKD,KAAL,GAAa,KAAKC,OAArC,GAA+C,CAAtD;AACD;;AAGDwB,EAAAA,cAAc,GAAW;AACvB,WAAO,KAAKxB,OAAL,GAAe,CAAf,GAAmB,KAAKF,IAAL,GAAY,KAAKE,OAApC,GAA8C,CAArD;AACD;;AAGDyB,EAAAA,KAAK,GAAW;AACd,WAAO,KAAK3B,IAAL,GAAY,CAAZ,GAAgB,KAAKE,OAAL,IAAgB,KAAKF,IAAL,GAAY,IAA5B,CAAhB,GAAoD,CAA3D;AACD;;AAEDkB,EAAAA,cAAc,GAAS;AACrB,QAAI,KAAKV,QAAL,KAAkB,KAAKT,UAA3B,EAAuC;AACrC,WAAKK,cAAL,GAAsB,KAAKG,KAA3B;AACA,WAAKF,eAAL,GAAuB,KAAKC,MAA5B;AACA,WAAKL,KAAL,IAAc,KAAKK,MAAnB;AACA,WAAKN,IAAL,IAAa,KAAKO,KAAlB;AACA,WAAKL,OAAL,IAAgB,KAAKM,QAArB;AACA,WAAKD,KAAL,GAAa,CAAb;AACA,WAAKD,MAAL,GAAc,CAAd;AACA,WAAKE,QAAL,GAAgB,CAAhB;AACD;AACF;;AAjJuB","sourcesContent":["import getHiResTimestamp from '../utils/hi-res-timestamp';\n\nexport default class Stat {\n readonly name: string;\n readonly type: string | undefined;\n sampleSize: number = 1;\n time: number = 0;\n count: number = 0;\n samples: number = 0;\n lastTiming: number = 0;\n lastSampleTime: number = 0;\n lastSampleCount: number = 0;\n\n _count: number = 0;\n _time: number = 0;\n _samples: number = 0;\n _startTime: number = 0;\n _timerPending: boolean = false;\n\n constructor(name: string, type?: string) {\n this.name = name;\n this.type = type;\n this.reset();\n }\n\n reset(): this {\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\n return this;\n }\n\n setSampleSize(samples: number): this {\n this.sampleSize = samples;\n return this;\n }\n\n /** Call to increment count (+1) */\n incrementCount(): this {\n this.addCount(1);\n\n return this;\n }\n\n /** Call to decrement count (-1) */\n decrementCount(): this {\n this.subtractCount(1);\n\n return this;\n }\n\n /** Increase count */\n addCount(value: number): this {\n this._count += value;\n this._samples++;\n this._checkSampling();\n\n return this;\n }\n\n /** Decrease count */\n subtractCount(value: number): this {\n this._count -= value;\n this._samples++;\n this._checkSampling();\n\n return this;\n }\n\n /** Add an arbitrary timing and bump the count */\n addTime(time: number): this {\n this._time += time;\n this.lastTiming = time;\n this._samples++;\n this._checkSampling();\n\n return this;\n }\n\n /** Start a timer */\n timeStart(): this {\n this._startTime = getHiResTimestamp();\n this._timerPending = true;\n\n return this;\n }\n\n /** End a timer. Adds to time and bumps the timing count. */\n timeEnd(): this {\n if (!this._timerPending) {\n return this;\n }\n this.addTime(getHiResTimestamp() - this._startTime);\n this._timerPending = false;\n this._checkSampling();\n\n return this;\n }\n\n getSampleAverageCount(): number {\n return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;\n }\n\n /** Calculate average time / count for the previous window */\n getSampleAverageTime(): number {\n return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;\n }\n\n /** Calculate counts per second for the previous window */\n getSampleHz(): number {\n return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1000) : 0;\n }\n\n getAverageCount(): number {\n return this.samples > 0 ? this.count / this.samples : 0;\n }\n\n /** Calculate average time / count */\n getAverageTime(): number {\n return this.samples > 0 ? this.time / this.samples : 0;\n }\n\n /** Calculate counts per second */\n getHz(): number {\n return this.time > 0 ? this.samples / (this.time / 1000) : 0;\n }\n\n _checkSampling(): void {\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"],"file":"stat.js"}