Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Measure performance of template or configuration file operations
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
  • Loading branch information
Jérôme Benoit committed Mar 15, 2022
1 parent 2c3872a commit 42a3eee
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/charging-station/ChargingStation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 42a3eee

Please sign in to comment.