forked from Steve-Mcl/node-red-contrib-image-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperformanceLogger.js
33 lines (32 loc) · 925 Bytes
/
performanceLogger.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class performanceLogger {
constructor(nodeid) {
this.nodeid = nodeid;
this.startTime = new Date();
this.timers = {};
this.performance = { nodeid: nodeid, startTime: new Date() };
}
start(name) {
this.timers[name] = { hrtime: process.hrtime(), startTime: new Date() };
return this;//for chaining
}
end(name) {
try {
var endTime = process.hrtime(this.timers[name].hrtime);
this.performance[name] = {
startTime: this.timers[name].startTime,
seconds: endTime[0],
milliseconds: endTime[1] / 1000000.0
};
return this;//for chaining
}
catch (error) {
}
}
getPerformance(name) {
if (name) {
return this.performance[name];
}
return this.performance;
}
}
module.exports = performanceLogger;