UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 3.36 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{disposeMaybe as t}from"../../../../core/maybe.js";import{recordPerformance as e}from"../../../../core/performance.js";import r from"../../../../core/PerformanceSampler.js";import{Milliseconds as i}from"../../../../core/time.js";import{RenderNodeOutput as s,InternalRenderCategory as a}from"../../webgl.js";import{createElapsedTimerPool as m}from"../../../webgl/TimerPool.js";const o={OVERLAY:"overlay",PREPARE:"prepare",SHADOW_MAP:"shadow map",DEPTH:"depth",ACCUMULATED_SHADOWS:"accumulated shadows",APPLY_ACCUMULATED_SHADOWS:"apply accumulated shadows",OBJECT_AND_LAYER_ID_COLOR:"object/layer id color",NORMALS:"normals",SSAO:"SSAO",HIGHLIGHTS:"highlights",OPAQUE_EDGES:"opaque edges",VOXEL:"voxel",TRANSPARENT:"transparent",TRANSPARENT_EDGES:"transparent edges",HUD_VISIBILITY:"HUD visibility",TRANSPARENT_TERRAIN:"transparent terrain",TRANSPARENT_MATERIAL_WITHOUT_DEPTH:"transparent material without depth",OPAQUE_ENVIRONMENT:"opaque environment",TRANSPARENT_ENVIRONMENT:"transparent environment",OCCLUDED:"occluded",HUD:"HUD",HUD_OCCLUDED:"HUD occluded",FINISH:"finish",FOCUS_AREA_MASK:"focus area mask"},l=Object.values(s).concat(Object.values(a)).concat(Object.values(o)),p="Total";class T{constructor(t){this._rctx=t,this._startTimeStampCPU=i(0),this._lastTimeStampCPU=i(0),this._totalCPUTime=new r(p),this._cpuTimeSamplers=new Map(l.map(t=>[t,new r(t)])),this._enableGPUTimer=0,this._totalGPUTime=new r("GPU"),this._gpuTimeSamplers=new Map(l.map(t=>[t,new r(t)])),this._totalTime=i(0),this._totalFrameCount=0}get totalCPUTimeSampler(){return this._totalCPUTime}get cpuTimeSamplers(){return Array.from(this._cpuTimeSamplers.values())}get totalGPUTimeSampler(){return this._totalGPUTime}get gpuTimeSamplers(){return Array.from(this._gpuTimeSamplers.values())}get gpuSamplingEnabled(){return null!=this._gpuTimerPool}get totalTime(){return this._totalTime}get totalFrameCount(){return this._totalFrameCount}get elapsedTime(){return i(performance.now()-this._startTimeStampCPU)}enableGPUPerformanceInfo(){if(null==this._gpuTimerPool){const t=[...l,p];this._gpuTimerPool=m(this._rctx,t)}if(null==this._gpuTimerPool)return{hasGPUTimerSupport:!1,remove:()=>{}};++this._enableGPUTimer;let e=!1;return{hasGPUTimerSupport:!0,remove:()=>{e||(e=!0,--this._enableGPUTimer,0===this._enableGPUTimer&&(this._gpuTimerPool=t(this._gpuTimerPool)))}}}startFrame(){this._startTimeStampCPU=this._lastTimeStampCPU=i(performance.now()),this._gpuTimerPool&&(this._gpuTimeSamplers.forEach(t=>t.push(0)),this._gpuTimerPool.start())}advance(t){const r=i(performance.now());if(this._cpuTimeSamplers.get(t).push(r-this._lastTimeStampCPU),e(t,this._lastTimeStampCPU,r,"Maps SDK","Scheduling"),this._lastTimeStampCPU=r,this._gpuTimerPool){const e=this._gpuTimerPool.stop(t);this._gpuTimeSamplers.get(t).set(e),this._gpuTimerPool.start()}}finishFrame(){if(this._gpuTimerPool){const t=this._gpuTimerPool.stop(o.FINISH);this._gpuTimeSamplers.get(o.FINISH).set(t),this._rctx.gl.flush()}const t=i(performance.now()-this._startTimeStampCPU);this._totalTime=i(this._totalTime+t),this._totalCPUTime.push(t),this._gpuTimerPool&&this._totalGPUTime.push(this.gpuTimeSamplers.reduce((t,e)=>t+(e.last||0),0)),++this._totalFrameCount}}export{l as PerformanceCategories,o as PerformanceCategory,T as RendererPerformanceInfo};