From c60af6ca67ad2599e7e3e886f219da6323ead61b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 28 Dec 2022 21:47:47 +0100 Subject: [PATCH] Fixes to performance: MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit + Clear measure after usage + Log statistics map properly Signed-off-by: Jérôme Benoit --- src/performance/PerformanceStatistics.ts | 11 ++++++++--- src/utils/Utils.ts | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index f3cc9e5f..8dae1bea 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -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 { diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index f1744075..08e87320 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -259,7 +259,7 @@ export default class Utils { } public static JSONStringifyWithMapSupport( - obj: Record | Record[], + obj: Record | Record[] | Map, space?: number ): string { return JSON.stringify( -- 2.34.1