@itwin/frontend-devtools
Version:
Debug menu and supporting UI widgets
67 lines • 3.15 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.MeasureTileLoadTimeTool = void 0;
/** @packageDocumentation
* @module Tools
*/
const core_bentley_1 = require("@itwin/core-bentley");
const core_frontend_1 = require("@itwin/core-frontend");
class TileLoadTimer {
_vp;
_stopwatch;
_cleanup;
constructor(vp) {
this._vp = vp;
this._stopwatch = new core_bentley_1.StopWatch();
// Purge tile trees for all models.
core_frontend_1.IModelApp.viewManager.refreshForModifiedModels(undefined);
const removeOnRender = vp.onRender.addListener(() => this.onRender());
const removeOnClose = vp.iModel.onClose.addOnce(() => this.cancel());
this._cleanup = () => {
removeOnRender();
removeOnClose();
};
core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, "Tile loading timer started."));
this._stopwatch.start();
}
cancel() {
core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, "Tile loading timer canceled."));
this.stop();
}
stop() {
if (undefined !== this._cleanup) {
this._cleanup();
this._cleanup = undefined;
}
}
onRender() {
// ###TODO: May be intermediate frames during which children props have been asynchronously requested but no outstanding tile requests.
if (!this._vp.areAllTileTreesLoaded || 0 < this._vp.numRequestedTiles)
return;
this._stopwatch.stop();
core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, `Tiles loaded in ${this._stopwatch.elapsedSeconds.toFixed(4)} seconds.`));
this.stop();
}
}
/** Unloads all tile trees, then starts a timer that stops when all tile trees and tiles required for the view are ready.
* Outputs the elapsed time to notifications manager.
* @beta
*/
class MeasureTileLoadTimeTool extends core_frontend_1.Tool {
static toolId = "MeasureTileLoadTime";
/** This method runs the tool, unloading all tile trees, then starts a timer that stops when all tile trees and tiles required for the view are ready. It will then output the elapsed time to notifications manager.
* @param _args this parameter is unused
*/
async run(_args) {
const vp = core_frontend_1.IModelApp.viewManager.selectedView;
if (undefined !== vp)
new TileLoadTimer(vp);
return true;
}
}
exports.MeasureTileLoadTimeTool = MeasureTileLoadTimeTool;
//# sourceMappingURL=MeasureTileLoadTime.js.map