UNPKG

@itwin/core-frontend

Version:
83 lines 3.15 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Rendering */ export class FrameStatsCollector { _onFrameStatsReady; _frameStats = FrameStatsCollector._createStats(); _shouldRecordFrame = false; static _createStats() { return { frameId: 0, totalSceneTime: 0, animationTime: 0, setupViewTime: 0, createChangeSceneTime: 0, validateRenderPlanTime: 0, decorationsTime: 0, onBeforeRenderTime: 0, totalFrameTime: 0, opaqueTime: 0, onRenderOpaqueTime: 0, translucentTime: 0, overlaysTime: 0, shadowsTime: 0, classifiersTime: 0, screenspaceEffectsTime: 0, backgroundTime: 0, }; } _clearStats() { this._frameStats.totalSceneTime = 0; this._frameStats.animationTime = 0; this._frameStats.setupViewTime = 0; this._frameStats.createChangeSceneTime = 0; this._frameStats.validateRenderPlanTime = 0; this._frameStats.decorationsTime = 0; this._frameStats.onBeforeRenderTime = 0; this._frameStats.totalFrameTime = 0; this._frameStats.opaqueTime = 0; this._frameStats.onRenderOpaqueTime = 0; this._frameStats.translucentTime = 0; this._frameStats.overlaysTime = 0; this._frameStats.shadowsTime = 0; this._frameStats.classifiersTime = 0; this._frameStats.screenspaceEffectsTime = 0; this._frameStats.backgroundTime = 0; } constructor(onFrameStatsReady) { this._onFrameStatsReady = onFrameStatsReady; } _begin(entry) { const prevSpan = this._frameStats[entry]; this._frameStats[entry] = Date.now() - prevSpan; } _end(entry) { const beginTime = this._frameStats[entry]; this._frameStats[entry] = Date.now() - beginTime; } beginFrame() { this._shouldRecordFrame = undefined !== this._onFrameStatsReady && this._onFrameStatsReady.numberOfListeners > 0; } endFrame(wasFrameDrawn = false) { if (this._shouldRecordFrame) { if (wasFrameDrawn) { if (undefined !== this._onFrameStatsReady) this._onFrameStatsReady.raiseEvent(this._frameStats); // transmit this frame's statistics to any listeners this._frameStats.frameId++; // increment frame counter for next pending frame } this._clearStats(); this._shouldRecordFrame = false; } } beginTime(entry) { if (this._shouldRecordFrame) this._begin(entry); } endTime(entry) { if (this._shouldRecordFrame) this._end(entry); } } //# sourceMappingURL=FrameStatsCollector.js.map