UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 3.4 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{disposeMaybe as t}from"../../../../core/maybe.js";import e from"../../../../core/PerformanceSampler.js";import{Milliseconds as r}from"../../../../core/time.js";import{RenderCategory as i,InternalRenderCategory as a}from"../../webgl.js";import{createElapsedTimerPool as s}from"../../../webgl/TimerPool.js";var m;!function(t){t.OVERLAY="overlay",t.PREPARE="prepare",t.SHADOW_MAP="shadow map",t.DEPTH="depth",t.ACCUMULATED_SHADOWS="accumulated shadows",t.APPLY_ACCUMULATED_SHADOWS="apply accumulated shadows",t.OBJECT_AND_LAYER_ID_COLOR="object/layer id color",t.NORMALS="normals",t.SSAO="SSAO",t.HIGHLIGHTS="highlights",t.OPAQUE_EDGES="opaque edges",t.VOXEL="voxel",t.TRANSPARENT="transparent",t.TRANSPARENT_EDGES="transparent edges",t.HUD_VISIBILITY="HUD visibility",t.TRANSPARENT_TERRAIN="transparent terrain",t.TRANSPARENT_MATERIAL_WITHOUT_DEPTH="transparent material without depth",t.OPAQUE_ENVIRONMENT="opaque environment",t.TRANSPARENT_ENVIRONMENT="transparent environment",t.OCCLUDED="occluded",t.HUD="HUD",t.HUD_OCCLUDED="HUD occluded",t.FINISH="finish",t.FOCUS_AREA_MASK="focus area mask"}(m||(m={}));const o=Object.values(i).concat(Object.values(a)).concat(Object.values(m)),l="Total";class p{constructor(t){this._rctx=t,this._startTimeStampCPU=r(0),this._lastTimeStampCPU=r(0),this._totalCPUTime=new e(l),this._cpuTimeSamplers=new Map(o.map((t=>[t,new e(t)]))),this._enableGPUTimer=0,this._totalGPUTime=new e("GPU"),this._gpuTimeSamplers=new Map(o.map((t=>[t,new e(t)]))),this._totalTime=r(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 r(performance.now()-this._startTimeStampCPU)}enableGPUPerformanceInfo(){if(null==this._gpuTimerPool){const t=[...o,l];this._gpuTimerPool=s(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=r(performance.now()),this._gpuTimerPool&&(this._gpuTimeSamplers.forEach((t=>t.push(0))),this._gpuTimerPool.start())}advance(t){const e=r(performance.now());if(this._cpuTimeSamplers.get(t).push(e-this._lastTimeStampCPU),this._lastTimeStampCPU=e,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(m.FINISH);this._gpuTimeSamplers.get(m.FINISH).set(t),this._rctx.gl.flush()}const t=r(performance.now()-this._startTimeStampCPU);this._totalTime=r(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{o as PerformanceCategories,m as PerformanceCategory,p as RendererPerformanceInfo};