UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 1.32 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ class e{constructor(e){this._objectType=e,this._active=new Map}get _stack(){const e=(new Error).stack.split("\n");return e.shift(),e.shift(),e.shift(),e.join("\n")}add(e){this._active.set(e,new t(this._stack))}remove(e){this._active.delete(e)}addReference(e){const t=this._active.get(e);t&&t.retains.push(this._stack)}removeReference(e){const t=this._active.get(e);t&&t.releases.push(this._stack)}resetLog(){const e=new Map;let t="";this._active.forEach((s,{usedMemory:r})=>{e.has(s.from)||(e.set(s.from,new Map),s.retains.length>0&&(t+=` First reference count mismatch:\n Retain:\n ${s.retains.join("\n\n ")}\n\n Release: ${s.releases.join("\n\n ")}\n`));const n=e.get(s.from);n.set(r??0,n.get(r??0)??1)}),this._active.clear();let s=0;const r=new Array;return e.forEach((e,t)=>{let n=0;e.forEach((e,t)=>n+=e*t),e.set(-1,n),s+=n,r.push([t,e])}),e.clear(),r.sort((e,t)=>t[1].get(-1)-e[1].get(-1)),r.reduce((e,[t,s])=>{const r=Math.round(s.get(-1)/1024);s.delete(-1);return e+=` ${r}KB from ${Array.from(s.values()).reduce((e,t)=>e+t,0)} allocations at ${t}\n`},`Total ${this._objectType} memory: ${Math.round(s/1024)}KB\n${t}`)}}class t{constructor(e){this.from=e,this.retains=new Array,this.releases=new Array}}export{e as AllocationTracer};