From 42a3eee7406d9ebfe5afd43c3065345701542d67 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 15 Mar 2022 15:56:52 +0100 Subject: [PATCH] Measure performance of template or configuration file operations MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 32d4542a..118805fe 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -771,7 +771,10 @@ export default class ChargingStation { private getTemplateFromFile(): ChargingStationTemplate | null { let template: ChargingStationTemplate = null; try { + const measureId = `${FileType.ChargingStationTemplate} read`; + const beginId = PerformanceStatistics.beginMeasure(measureId); template = JSON.parse(fs.readFileSync(this.templateFile, 'utf8')) as ChargingStationTemplate; + PerformanceStatistics.endMeasure(measureId, beginId); } catch (error) { FileUtils.handleFileException( this.logPrefix(), @@ -1157,9 +1160,14 @@ export default class ChargingStation { let configuration: ChargingStationConfiguration = null; if (this.configurationFile && fs.existsSync(this.configurationFile)) { try { + const measureId = `${FileType.ChargingStationConfiguration} read`; + const beginId = PerformanceStatistics.beginMeasure( + `${FileType.ChargingStationConfiguration} read` + ); configuration = JSON.parse( fs.readFileSync(this.configurationFile, 'utf8') ) as ChargingStationConfiguration; + PerformanceStatistics.endMeasure(measureId, beginId); } catch (error) { FileUtils.handleFileException( this.logPrefix(), @@ -1192,9 +1200,12 @@ export default class ChargingStation { configurationData.stationInfo = this.stationInfo; break; } + const measureId = `${FileType.ChargingStationConfiguration} write`; + const beginId = PerformanceStatistics.beginMeasure(measureId); const fileDescriptor = fs.openSync(this.configurationFile, 'w'); fs.writeFileSync(fileDescriptor, JSON.stringify(configurationData, null, 2), 'utf8'); fs.closeSync(fileDescriptor); + PerformanceStatistics.endMeasure(measureId, beginId); } catch (error) { FileUtils.handleFileException( this.logPrefix(), -- 2.34.1