// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
+import type { URL } from 'node:url';
import { PerformanceEntry, PerformanceObserver, performance } from 'perf_hooks';
-import type { URL } from 'url';
import { parentPort } from 'worker_threads';
import { MessageChannelUtils } from '../charging-station/MessageChannelUtils';
import { MessageType } from '../types/ocpp/MessageType';
import type { IncomingRequestCommand, RequestCommand } from '../types/ocpp/Requests';
import type { Statistics, TimeSeries } from '../types/Statistics';
-import { CircularArray, DEFAULT_CIRCULAR_ARRAY_SIZE } from '../utils/CircularArray';
+import { CircularArray } from '../utils/CircularArray';
import Configuration from '../utils/Configuration';
+import Constants from '../utils/Constants';
import logger from '../utils/Logger';
import Utils from '../utils/Utils';
private readonly objId: string;
private readonly objName: string;
- private performanceObserver: PerformanceObserver;
+ private performanceObserver!: PerformanceObserver;
private readonly statistics: Statistics;
- private displayInterval: NodeJS.Timeout;
+ private displayInterval!: NodeJS.Timeout;
private constructor(objId: string, objName: string, uri: URL) {
this.objId = objId;
}
public static beginMeasure(id: string): string {
- const markId = `${id.charAt(0).toUpperCase() + id.slice(1)}~${Utils.generateUUID()}`;
+ const markId = `${id.charAt(0).toUpperCase()}${id.slice(1)}~${Utils.generateUUID()}`;
performance.mark(markId);
return markId;
}
);
} else {
logger.info(
- `${this.logPrefix()} log interval is set to ${Configuration.getLogStatisticsInterval().toString()}. Not logging statistics`
+ `${this.logPrefix()} log interval is set to ${Configuration.getLogStatisticsInterval()?.toString()}. Not logging statistics`
);
}
}
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) === true
+ this.statistics.statisticsData.get(entryName)?.timeMeasurementSeries instanceof CircularArray
? this.statistics.statisticsData
.get(entryName)
- .timeMeasurementSeries.push({ timestamp: entry.startTime, value: entry.duration })
+ ?.timeMeasurementSeries?.push({ timestamp: entry.startTime, value: entry.duration })
: (this.statistics.statisticsData.get(entryName).timeMeasurementSeries =
- new CircularArray<TimeSeries>(DEFAULT_CIRCULAR_ARRAY_SIZE, {
+ new CircularArray<TimeSeries>(Constants.DEFAULT_CIRCULAR_BUFFER_CAPACITY, {
timestamp: entry.startTime,
value: entry.duration,
}));
)
);
if (Configuration.getPerformanceStorage().enabled) {
- parentPort.postMessage(
+ parentPort?.postMessage(
MessageChannelUtils.buildPerformanceStatisticsMessage(this.statistics)
);
}
return timeSeries.map((timeSeriesItem) => timeSeriesItem.value);
}
- private logPrefix(): string {
+ private logPrefix = (): string => {
return Utils.logPrefix(` ${this.objName} | Performance statistics`);
- }
+ };
}