Fixes to performance:
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 28 Dec 2022 20:47:47 +0000 (21:47 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 28 Dec 2022 20:47:47 +0000 (21:47 +0100)
+ Clear measure after usage
+ Log statistics map properly

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/performance/PerformanceStatistics.ts
src/utils/Utils.ts

index f3cc9e5fb67a132476cbba261739f9c450befa89..8dae1bea1712ee44b3f098106d4e064f286acbae 100644 (file)
@@ -58,6 +58,7 @@ export default class PerformanceStatistics {
   public static endMeasure(name: string, markId: string): void {
     performance.measure(name, markId);
     performance.clearMarks(markId);
+    performance.clearMeasures(name);
   }
 
   public addRequestStatistic(
@@ -127,6 +128,7 @@ export default class PerformanceStatistics {
       clearInterval(this.displayInterval);
     }
     performance.clearMarks();
+    performance.clearMeasures();
     this.performanceObserver?.disconnect();
   }
 
@@ -136,8 +138,8 @@ export default class PerformanceStatistics {
   }
 
   private initializePerformanceObserver(): void {
-    this.performanceObserver = new PerformanceObserver((list) => {
-      const lastPerformanceEntry = list.getEntries()[0];
+    this.performanceObserver = new PerformanceObserver((performanceObserverList) => {
+      const lastPerformanceEntry = performanceObserverList.getEntries()[0];
       this.addPerformanceEntryToStatistics(lastPerformanceEntry);
       logger.debug(
         `${this.logPrefix()} '${lastPerformanceEntry.name}' performance entry: %j`,
@@ -148,7 +150,10 @@ export default class PerformanceStatistics {
   }
 
   private logStatistics(): void {
-    logger.info(this.logPrefix() + ' %j', this.statistics);
+    logger.info(`${this.logPrefix()}`, {
+      ...this.statistics,
+      statisticsData: Utils.JSONStringifyWithMapSupport(this.statistics.statisticsData),
+    });
   }
 
   private startLogStatisticsInterval(): void {
index f174407500db95556d6d1c04fb0b4c95355923b7..08e87320ce2c83f9ab563c46e53ec01718723cb1 100644 (file)
@@ -259,7 +259,7 @@ export default class Utils {
   }
 
   public static JSONStringifyWithMapSupport(
-    obj: Record<string, unknown> | Record<string, unknown>[],
+    obj: Record<string, unknown> | Record<string, unknown>[] | Map<string, unknown>,
     space?: number
   ): string {
     return JSON.stringify(