/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../chunks/_rollupPluginBabelHelpers","../../../../core/CircularArray","../../../../core/Evented","../../../../core/has","../../../../core/maybe","../../../webgl/capabilities/DisjointTimerQuery"],(function(e,t,n,s,r,i,o){"use strict";const a=r("esri-2d-profiler");let m=function(){function e(e,t){if(this._events=new s,this._entries=new Map,this._timings=new n(10),!a)return;this._ext=o.createDisjointTimerQuery(e.gl,{}),this._debugOutput=t;const r=e.gl;if(this.enableCommandLogging)for(const n in r)if("function"==typeof r[n]){const e=r[n],t=n.includes("draw");r[n]=(...s)=>(this._events.emit("command",{container:this._currentContainer,pass:this._currentPass,brush:this._currentBrush,method:n,args:s,isDrawCommand:t}),this._currentSummary&&(this._currentSummary.commands++,t&&this._currentSummary.drawCommands++),e.apply(r,s))}}var r=e.prototype;return r.recordContainerStart=function(e){a&&(this._currentContainer=e)},r.recordContainerEnd=function(){a&&(this._currentContainer=null)},r.recordPassStart=function(e){a&&(this._currentPass=e,this._initSummary())},r.recordPassEnd=function(){a&&(this._currentPass=null,this._emitSummary())},r.recordBrushStart=function(e){a&&(this._currentBrush=e)},r.recordBrushEnd=function(){a&&(this._currentBrush=null)},r.recordStart=function(e){if(a&&i.isSome(this._ext)){if(this._entries.has(e)){const t=this._entries.get(e),n=this._ext.resultAvailable(t.query),s=this._ext.disjoint();if(n&&!s){const n=this._ext.getResult(t.query)/1e6;let s=0;if(i.isSome(this._timings.enqueue(n))){const e=this._timings.entries,t=e.length;let n=0;for(const s of e)n+=s;s=n/t}const r=n.toFixed(2),o=s?s.toFixed(2):"--";this.enableCommandLogging?(console.groupCollapsed(`Frame report for ${e}, ${r} ms (${o} last 10 avg)\n${t.commandsLen} Commands (${t.drawCommands} draw)`),console.log("RenderPass breakdown: "),console.table(t.summaries),console.log("Commands: ",t.commands),console.groupEnd()):console.log(`Frame report for ${e}, ${r} ms (${o} last 10 avg)`),this._debugOutput.innerHTML=`${r} (${o})`}for(const e of t.handles)e.remove();this._entries.delete(e)}const t={name:e,query:this._ext.createQuery(),commands:[],commandsLen:0,drawCommands:0,summaries:[],handles:[]};this.enableCommandLogging&&(t.handles.push(this._events.on("command",(e=>{t.commandsLen++,t.commands.push(e),e.isDrawCommand&&t.drawCommands++}))),t.handles.push(this._events.on("summary",(e=>{t.summaries.push(e)})))),this._ext.beginTimeElapsed(t.query),this._entries.set(e,t)}},r.recordEnd=function(e){a&&i.isSome(this._ext)&&this._entries.has(e)&&this._ext.endTimeElapsed()},r._initSummary=function(){this.enableCommandLogging&&(this._currentSummary={container:this._currentContainer,pass:this._currentPass,drawCommands:0,commands:0})},r._emitSummary=function(){this.enableCommandLogging&&this._events.emit("summary",this._currentSummary)},t._createClass(e,[{key:"enableCommandLogging",get:function(){return!("object"==typeof a&&a.disableCommands)}}]),e}();e.Profiler=m,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
