From: Jérôme Benoit Date: Fri, 13 Aug 2021 15:13:34 +0000 (+0200) Subject: Encapsulate performance init code in the same class. X-Git-Tag: v1.0.32~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a0ba4ced5cf822e9ff2ac192c17d1d954f32d139;p=e-mobility-charging-stations-simulator.git Encapsulate performance init code in the same class. Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 4b624373..2626a233 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -549,7 +549,6 @@ export default class ChargingStation { this.stationInfo.powerDivider = this.getPowerDivider(); if (this.getEnableStatistics()) { this.performanceStatistics = new PerformanceStatistics(this.stationInfo.chargingStationId); - PerformanceStatistics.initFunctionPerformanceObserver(this.performanceStatistics); } } diff --git a/src/utils/PerformanceStatistics.ts b/src/utils/PerformanceStatistics.ts index 1e666fe9..c2d1527a 100644 --- a/src/utils/PerformanceStatistics.ts +++ b/src/utils/PerformanceStatistics.ts @@ -13,19 +13,11 @@ export default class PerformanceStatistics { private commandsStatistics: CommandStatistics; public constructor(objId: string) { + this.initFunctionPerformanceObserver(); this.objId = objId; this.commandsStatistics = { id: this.objId ? this.objId : 'Object id not specified', commandsStatisticsData: {} }; } - public static initFunctionPerformanceObserver(performanceStatistics: PerformanceStatistics): PerformanceObserver { - const performanceObserver = new PerformanceObserver((list, observer) => { - performanceStatistics.logPerformance(list.getEntries()[0]); - observer.disconnect(); - }); - performanceObserver.observe({ entryTypes: ['function'] }); - return performanceObserver; - } - public static timedFunction(method: (...optionalParams: any[]) => any): (...optionalParams: any[]) => any { return performance.timerify(method); } @@ -78,13 +70,21 @@ export default class PerformanceStatistics { startTime: entry.startTime, duration: entry.duration }; - logger.debug(`${this.logPrefix()} Method or function '${entry.name}' performance entry: %j`, perfEntry); + logger.debug(`${this.logPrefix()} method or function '${entry.name}' performance entry: %j`, perfEntry); } public start(): void { this.displayInterval(); } + private initFunctionPerformanceObserver(): void { + const performanceObserver = new PerformanceObserver((list, observer) => { + this.logPerformance(list.getEntries()[0]); + observer.disconnect(); + }); + performanceObserver.observe({ entryTypes: ['function'] }); + } + private display(): void { logger.info(this.logPrefix() + ' %j', this.commandsStatistics); }