@itwin/ecschema-metadata
Version:
ECObjects core concepts in typescript
82 lines • 3.35 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.PerformanceLogger = void 0;
/**
* Utility class used to log query load times for Schema and
* SchemaItem queries.
* @internal
*/
class PerformanceLogger {
_iModelItems = new Map();
_label;
// flag that controls if logging is enabled.
disableLogging = false;
/**
* Initializes a new PerformanceLogger instance.
* @param label Arbitrary label used to tag this logging session (ex. IModel name)
*/
constructor(label) {
this._label = label || "";
}
/**
* Gets the Map of logged Schema entries. The Map key is the iModel name. The Map
* value is a second Map whose key is a Schema name and value is a SchemaLoadData
* object.
*/
get logItems() {
return this._iModelItems;
}
/**
* Adds a new log entry to the Schema Map.
* @param startTime The start time of the entry to be logged (end time/duration is handled in this method).
* @param schemaName The Schema being queried.
*/
logSchema(startTime, schemaName) {
if (this.disableLogging)
return;
const loadTime = new Date().getTime() - startTime;
const schemaMap = this.getSchemaMap(this._label);
const schemaLoadData = this.getSchemaLoadData(schemaMap, schemaName);
schemaLoadData.loadTime = loadTime;
}
/**
* Adds a new log entry to the SchemaItem Map.
* @param startTime The start time of the entry to be logged (end time/duration is handled in this method).
* @param schemaName The name of the Schema being queried.
* @param schemaItemType The SchemaItemType name of the type being queried.
* @param itemCount The number of items retrieved in the query.
*/
logSchemaItem(startTime, schemaName, schemaItemType, itemCount) {
if (this.disableLogging)
return;
const loadTime = new Date().getTime() - startTime;
const schemaMap = this.getSchemaMap(this._label);
const schemaLoadData = this.getSchemaLoadData(schemaMap, schemaName);
if (schemaLoadData.schemaItemMap.has(schemaItemType))
throw new Error("There should not be a multiple load times for a given iModel, Schema, SchemaItemType combination.");
schemaLoadData.schemaItemMap.set(schemaItemType, { loadTime, itemCount });
}
/**
* Clears all log entries from the Map.
*/
clearLogs() {
this._iModelItems.clear();
}
getSchemaMap(iModel) {
if (!this._iModelItems.has(iModel)) {
this._iModelItems.set(iModel, new Map());
}
return this._iModelItems.get(iModel);
}
getSchemaLoadData(schemaMap, schemaName) {
if (!schemaMap.has(schemaName))
schemaMap.set(schemaName, { schemaItemMap: new Map() });
return schemaMap.get(schemaName);
}
}
exports.PerformanceLogger = PerformanceLogger;
//# sourceMappingURL=PerformanceLogger.js.map