Encapsulate performance init code in the same class.
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 13 Aug 2021 15:13:34 +0000 (17:13 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 13 Aug 2021 15:13:34 +0000 (17:13 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/utils/PerformanceStatistics.ts

index 4b6243731fc26689bcfd22ee883dbd235075f3be..2626a23353c0815cea003ea59787c7cc81b5b662 100644 (file)
@@ -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);
     }
   }
 
index 1e666fe9a025a41aa3cdce5dc6bbff6f24c6fb1f..c2d1527a1a7adcd1803c03e1e2fa18d64e1be860 100644 (file)
@@ -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);
   }