From d71b025f891fc5f0dd3ef45d6bf371eb6d5900bd Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 10 Sep 2023 12:19:03 +0200 Subject: [PATCH] refactor: cleanup performance statistics code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/performance/PerformanceStatistics.ts | 41 ++++++++++++------------ 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index 7ff27723..b7bc5d27 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -213,46 +213,45 @@ export class PerformanceStatistics { } private addPerformanceEntryToStatistics(entry: PerformanceEntry): void { - const entryName = entry.name; // Initialize command statistics - if (!this.statistics.statisticsData.has(entryName)) { - this.statistics.statisticsData.set(entryName, {}); + if (!this.statistics.statisticsData.has(entry.name)) { + this.statistics.statisticsData.set(entry.name, {}); } // Update current statistics - this.statistics.statisticsData.get(entryName)!.timeMeasurementCount = - (this.statistics.statisticsData.get(entryName)?.timeMeasurementCount ?? 0) + 1; - this.statistics.statisticsData.get(entryName)!.currentTimeMeasurement = entry.duration; - this.statistics.statisticsData.get(entryName)!.minTimeMeasurement = min( + this.statistics.statisticsData.get(entry.name)!.timeMeasurementCount = + (this.statistics.statisticsData.get(entry.name)?.timeMeasurementCount ?? 0) + 1; + this.statistics.statisticsData.get(entry.name)!.currentTimeMeasurement = entry.duration; + this.statistics.statisticsData.get(entry.name)!.minTimeMeasurement = min( entry.duration, - this.statistics.statisticsData.get(entryName)?.minTimeMeasurement ?? Infinity, + this.statistics.statisticsData.get(entry.name)?.minTimeMeasurement ?? Infinity, ); - this.statistics.statisticsData.get(entryName)!.maxTimeMeasurement = max( + this.statistics.statisticsData.get(entry.name)!.maxTimeMeasurement = max( entry.duration, - this.statistics.statisticsData.get(entryName)?.maxTimeMeasurement ?? -Infinity, + this.statistics.statisticsData.get(entry.name)?.maxTimeMeasurement ?? -Infinity, ); - this.statistics.statisticsData.get(entryName)!.totalTimeMeasurement = - (this.statistics.statisticsData.get(entryName)?.totalTimeMeasurement ?? 0) + entry.duration; - this.statistics.statisticsData.get(entryName)?.measurementTimeSeries instanceof CircularArray + this.statistics.statisticsData.get(entry.name)!.totalTimeMeasurement = + (this.statistics.statisticsData.get(entry.name)?.totalTimeMeasurement ?? 0) + entry.duration; + this.statistics.statisticsData.get(entry.name)?.measurementTimeSeries instanceof CircularArray ? this.statistics.statisticsData - .get(entryName) + .get(entry.name) ?.measurementTimeSeries?.push({ timestamp: entry.startTime, value: entry.duration }) - : (this.statistics.statisticsData.get(entryName)!.measurementTimeSeries = + : (this.statistics.statisticsData.get(entry.name)!.measurementTimeSeries = new CircularArray(Constants.DEFAULT_CIRCULAR_BUFFER_CAPACITY, { timestamp: entry.startTime, value: entry.duration, })); const timeMeasurementValues = extractTimeSeriesValues( - this.statistics.statisticsData.get(entryName)!.measurementTimeSeries!, + this.statistics.statisticsData.get(entry.name)!.measurementTimeSeries!, ); - this.statistics.statisticsData.get(entryName)!.avgTimeMeasurement = + this.statistics.statisticsData.get(entry.name)!.avgTimeMeasurement = average(timeMeasurementValues); - this.statistics.statisticsData.get(entryName)!.medTimeMeasurement = + this.statistics.statisticsData.get(entry.name)!.medTimeMeasurement = median(timeMeasurementValues); - this.statistics.statisticsData.get(entryName)!.ninetyFiveThPercentileTimeMeasurement = + this.statistics.statisticsData.get(entry.name)!.ninetyFiveThPercentileTimeMeasurement = nthPercentile(timeMeasurementValues, 95); - this.statistics.statisticsData.get(entryName)!.stdDevTimeMeasurement = stdDeviation( + this.statistics.statisticsData.get(entry.name)!.stdDevTimeMeasurement = stdDeviation( timeMeasurementValues, - this.statistics.statisticsData.get(entryName)!.avgTimeMeasurement, + this.statistics.statisticsData.get(entry.name)!.avgTimeMeasurement, ); this.statistics.updatedAt = new Date(); if ( -- 2.34.1