X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fperformance%2FPerformanceStatistics.ts;h=d3a174c076a2642ccaad247f4653d78bd48b8350;hb=7cb5b17fac198fe3ecd009ac4c692c0d88dd051e;hp=bec0f62e28099597ab5e4a46dc75c360cf4f408a;hpb=e7aeea18e189dd087c8f951cf77a253e2818ae90;p=e-mobility-charging-stations-simulator.git diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index bec0f62e..d3a174c0 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -1,23 +1,24 @@ // Partial Copyright Jerome Benoit. 2021. All Rights Reserved. -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, TimeSeries } from '../types/Statistics'; +import type { URL } from 'url'; +import { parentPort } from 'worker_threads'; -import { ChargingStationWorkerMessageEvents } from '../types/ChargingStationWorker'; -import Configuration from '../utils/Configuration'; +import { MessageChannelUtils } from '../charging-station/MessageChannelUtils'; import { MessageType } from '../types/ocpp/MessageType'; -import { URL } from 'url'; -import Utils from '../utils/Utils'; +import type { IncomingRequestCommand, RequestCommand } from '../types/ocpp/Requests'; +import type { Statistics, StatisticsData, TimeSeries } from '../types/Statistics'; +import { CircularArray, DEFAULT_CIRCULAR_ARRAY_SIZE } from '../utils/CircularArray'; +import Configuration from '../utils/Configuration'; import logger from '../utils/Logger'; -import { parentPort } from 'worker_threads'; +import Utils from '../utils/Utils'; export default class PerformanceStatistics { private static readonly instances: Map = new Map< string, PerformanceStatistics >(); + private readonly objId: string; private readonly objName: string; private performanceObserver: PerformanceObserver; @@ -37,7 +38,11 @@ export default class PerformanceStatistics { }; } - public static getInstance(objId: string, objName: string, uri: URL): PerformanceStatistics { + public static getInstance( + objId: string, + objName: string, + uri: URL + ): PerformanceStatistics | undefined { if (!PerformanceStatistics.instances.has(objId)) { PerformanceStatistics.instances.set(objId, new PerformanceStatistics(objId, objName, uri)); } @@ -100,6 +105,7 @@ export default class PerformanceStatistics { } break; default: + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions logger.error(`${this.logPrefix()} wrong message type ${messageType}`); break; } @@ -214,12 +220,7 @@ export default class PerformanceStatistics { } private addPerformanceEntryToStatistics(entry: PerformanceEntry): void { - let entryName = entry.name; - // Rename entry name - const MAP_NAME: Record = {}; - if (MAP_NAME[entryName]) { - entryName = MAP_NAME[entryName]; - } + const entryName = entry.name; // Initialize command statistics if (!this.statistics.statisticsData.has(entryName)) { this.statistics.statisticsData.set(entryName, {}); @@ -277,10 +278,9 @@ export default class PerformanceStatistics { ) ); if (Configuration.getPerformanceStorage().enabled) { - parentPort.postMessage({ - id: ChargingStationWorkerMessageEvents.PERFORMANCE_STATISTICS, - data: this.statistics, - }); + parentPort.postMessage( + MessageChannelUtils.buildPerformanceStatisticsMessage(this.statistics) + ); } }