From: Jérôme Benoit Date: Mon, 22 Nov 2021 17:00:17 +0000 (+0100) Subject: Make the performance measurement time series actually a real time series X-Git-Tag: v1.1.33~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0c142310bb891fd23f2c40234af1fddd88ba71d5;p=e-mobility-charging-stations-simulator.git Make the performance measurement time series actually a real time series Signed-off-by: Jérôme Benoit --- 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;