@itwin/frontend-devtools
Version:
Debug menu and supporting UI widgets
63 lines • 2.81 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Tools
*/
import { StopWatch } from "@itwin/core-bentley";
import { IModelApp, NotifyMessageDetails, OutputMessagePriority, Tool } from "@itwin/core-frontend";
class TileLoadTimer {
_vp;
_stopwatch;
_cleanup;
constructor(vp) {
this._vp = vp;
this._stopwatch = new StopWatch();
// Purge tile trees for all models.
IModelApp.viewManager.refreshForModifiedModels(undefined);
const removeOnRender = vp.onRender.addListener(() => this.onRender());
const removeOnClose = vp.iModel.onClose.addOnce(() => this.cancel());
this._cleanup = () => {
removeOnRender();
removeOnClose();
};
IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, "Tile loading timer started."));
this._stopwatch.start();
}
cancel() {
IModelApp.notifications.outputMessage(new NotifyMessageDetails(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();
IModelApp.notifications.outputMessage(new NotifyMessageDetails(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
*/
export class MeasureTileLoadTimeTool extends 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 = IModelApp.viewManager.selectedView;
if (undefined !== vp)
new TileLoadTimer(vp);
return true;
}
}
//# sourceMappingURL=MeasureTileLoadTime.js.map