@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 939 B
JavaScript
import{AllocationTracer as t}from"../support/AllocationTracer.js";import{ResourceType as r}from"./enums.js";const e={RECORD_ALLOCATIONS:!1};class s{constructor(){for(this._current=new Array,this._max=new Array,this._allocations=new t(e.RECORD_ALLOCATIONS);this._current.length<r.COUNT;)this._current.push(0),this._max.push(0)}resetMax(){for(this._max.length=0;this._max.length<this._current.length;)this._max.push(0)}increment(t,r){const e=++this._current[t];this._max[t]=Math.max(e,this._max[t]),this._allocations.add(r)}decrement(t,r){--this._current[t],this._allocations.remove(r)}get max(){return this._max}get current(){return this._current}get total(){return this.current.reduce(((t,r)=>t+r),0)}get resourceInformation(){let t="";if(this.total>0){t+="Live objects:\n";for(let e=0;e<r.COUNT;++e){const s=this._current[e];s>0&&(t+=`${r[e]}: ${s}\n`)}}return t+=this._allocations.information,t}}export{s as InstanceCounter,e as test};