From 0c142310bb891fd23f2c40234af1fddd88ba71d5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 22 Nov 2021 18:00:17 +0100 Subject: [PATCH] Make the performance measurement time series actually a real time series 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 | 16 +++++++++++----- src/types/Statistics.ts | 7 ++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index 9f3b9482..f9be1922 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -3,7 +3,7 @@ import { CircularArray, DEFAULT_CIRCULAR_ARRAY_SIZE } from '../utils/CircularArray'; import { IncomingRequestCommand, RequestCommand } from '../types/ocpp/Requests'; import { PerformanceEntry, PerformanceObserver, performance } from 'perf_hooks'; -import Statistics, { StatisticsData } from '../types/Statistics'; +import Statistics, { StatisticsData, TimeSeries } from '../types/Statistics'; import { ChargingStationWorkerMessageEvents } from '../types/ChargingStationWorker'; import Configuration from '../utils/Configuration'; @@ -176,15 +176,21 @@ export default class PerformanceStatistics { this.statistics.statisticsData.get(entryName).maxTimeMeasurement = this.statistics.statisticsData.get(entryName)?.maxTimeMeasurement ? (this.statistics.statisticsData.get(entryName).maxTimeMeasurement < entry.duration ? entry.duration : this.statistics.statisticsData.get(entryName).maxTimeMeasurement) : entry.duration; this.statistics.statisticsData.get(entryName).totalTimeMeasurement = this.statistics.statisticsData.get(entryName)?.totalTimeMeasurement ? this.statistics.statisticsData.get(entryName).totalTimeMeasurement + entry.duration : entry.duration; this.statistics.statisticsData.get(entryName).avgTimeMeasurement = this.statistics.statisticsData.get(entryName).totalTimeMeasurement / this.statistics.statisticsData.get(entryName).countTimeMeasurement; - Array.isArray(this.statistics.statisticsData.get(entryName).timeMeasurementSeries) ? this.statistics.statisticsData.get(entryName).timeMeasurementSeries.push(entry.duration) : this.statistics.statisticsData.get(entryName).timeMeasurementSeries = new CircularArray(DEFAULT_CIRCULAR_ARRAY_SIZE, entry.duration); - this.statistics.statisticsData.get(entryName).medTimeMeasurement = this.median(this.statistics.statisticsData.get(entryName).timeMeasurementSeries); - this.statistics.statisticsData.get(entryName).ninetyFiveThPercentileTimeMeasurement = this.percentile(this.statistics.statisticsData.get(entryName).timeMeasurementSeries, 95); - this.statistics.statisticsData.get(entryName).stdDevTimeMeasurement = this.stdDeviation(this.statistics.statisticsData.get(entryName).timeMeasurementSeries); + Array.isArray(this.statistics.statisticsData.get(entryName).timeMeasurementSeries) + ? this.statistics.statisticsData.get(entryName).timeMeasurementSeries.push({ timestamp: entry.startTime, value: entry.duration }) + : this.statistics.statisticsData.get(entryName).timeMeasurementSeries = new CircularArray(DEFAULT_CIRCULAR_ARRAY_SIZE, { timestamp: entry.startTime, value: entry.duration }); + this.statistics.statisticsData.get(entryName).medTimeMeasurement = this.median(this.extractTimeSeriesValues(this.statistics.statisticsData.get(entryName).timeMeasurementSeries)); + this.statistics.statisticsData.get(entryName).ninetyFiveThPercentileTimeMeasurement = this.percentile(this.extractTimeSeriesValues(this.statistics.statisticsData.get(entryName).timeMeasurementSeries), 95); + this.statistics.statisticsData.get(entryName).stdDevTimeMeasurement = this.stdDeviation(this.extractTimeSeriesValues(this.statistics.statisticsData.get(entryName).timeMeasurementSeries)); if (Configuration.getPerformanceStorage().enabled) { parentPort.postMessage({ id: ChargingStationWorkerMessageEvents.PERFORMANCE_STATISTICS, data: this.statistics }); } } + private extractTimeSeriesValues(timeSeries: CircularArray): number[] { + return timeSeries.map((timeSeriesItem) => timeSeriesItem.value); + } + private logPrefix(): string { return Utils.logPrefix(` ${this.objId} | Performance statistics`); } diff --git a/src/types/Statistics.ts b/src/types/Statistics.ts index 00c73052..5a6db6d5 100644 --- a/src/types/Statistics.ts +++ b/src/types/Statistics.ts @@ -1,11 +1,16 @@ import { CircularArray } from '../utils/CircularArray'; +export interface TimeSeries { + timestamp: number; + value: number; +} + export interface StatisticsData { countRequest: number; countResponse: number; countError: number; countTimeMeasurement: number; - timeMeasurementSeries: CircularArray; + timeMeasurementSeries: CircularArray; currentTimeMeasurement: number; minTimeMeasurement: number; maxTimeMeasurement: number; -- 2.34.1