From a0ba4ced5cf822e9ff2ac192c17d1d954f32d139 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 13 Aug 2021 17:13:34 +0200 Subject: [PATCH] Encapsulate performance init code in the same class. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 1 - src/utils/PerformanceStatistics.ts | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) 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); } -- 2.34.1