Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pusage.stat(process.pid, function(err, stat) {
if (err) {
callback(err);
} else {
if (stat.cpu === undefined) {
callback('CPU status not found!');
} else {
let cpuUsage = parseInt(stat.cpu)
let cpuFree = 100 - cpuUsage;
/* Unmonitor process */
pusage.unmonitor(process.pid);
callback(undefined,[
cpuUsage,
cpuFree
]);
}
}
});
};
pusage.stat(process.pid, function(err, stat) {
if (err) {
callback(err);
} else {
if (stat.memory === undefined) {
callback('Memory status not found!');
} else {
let memoryUsed = round( (stat.memory / 1024) / 1024 );
let memoryTotal = round( (os.totalmem() / 1024) / 1024 );
/* Unmonitor process */
pusage.unmonitor(process.pid);
callback(undefined,[
[memoryUsed],
[memoryTotal]
]);
}
}
});
};
if (settings.lightWallet == 1) {
pid = rendererPid;
} else if (server && server.pid) {
pid = server.pid;
}
if (pid) {
pusage.stat(pid, function (err, stat) {
if (err) {
App.updateStatusBar({ "cpu": "" });
} else {
App.updateStatusBar({ "cpu": Math.round(stat.cpu).toFixed(2) });
}
});
pusage.unmonitor(pid);
} else {
console.log("Track CPU: No server PID");
if (cpuTrackInterval) {
console.log("Clear the interval");
clearInterval(cpuTrackInterval);
}
}
}
async stop() {
clearInterval(this.intervalObj);
this.containers = [];
this.stats = {'time': []};
for(let key in this.pids) {
usage.unmonitor(key);
}
this.pids = [];
await Util.sleep(100);
}
restart() {
clearInterval(this.intervalObj);
for(let key in this.stats) {
if(key === 'time') {
this.stats[key] = [];
}
else {
for(let v in this.stats[key]) {
this.stats[key][v] = [];
}
}
}
for(let key in this.pids) {
usage.unmonitor(key);
}
this.pids = [];
return this.start();
}
stop() {
clearInterval(this.intervalObj);
this.containers = [];
this.stats = {'time': []};
for(let key in this.pids) {
usage.unmonitor(key);
}
this.pids = [];
return Util.sleep(100);
}
async restart() {
clearInterval(this.intervalObj);
for (let key in this.stats) {
if (key === 'time') {
this.stats[key] = [];
} else {
for (let v in this.stats[key]) {
this.stats[key][v] = [];
}
}
}
for (let key in this.pids) {
usage.unmonitor(key);
}
this.pids = [];
await this.start();
}
exports.clear = function(pids){
pids = Array.prototype.slice.call(pids);
let len = pids.length;
for(let i = 0; i < len; i++){
pusage.unmonitor(pids[i]);
}
};