How to use pidusage - 10 common examples

To help you get started, we’ve selected a few pidusage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lgapontes / hey-joe / infrastructure / memory.js View on Github external
this.getStatus = function(request,callback) {
        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]
                    ]);
github Tjatse / pm2-gui / lib / monitor.js View on Github external
function runTimer () {
      pidusage.stat(pid, function (err, stat) {
        if (err) {
          clearInterval(self._usages[pidStr])
          delete self._usages[pidStr]
          return emitError.call(self, err, pid)
        }
        stat.memory = stat.memory * 100 / totalmem

        var data = {
          pid: pid,
          time: Date.now(),
          usage: stat
        }
        self._broadcast.call(self, 'proc', data, conf.NSP.PROC) // eslint-disable-line no-useless-call
      })
    }
github lgapontes / hey-joe / infrastructure / cpu.js View on Github external
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
                    ]);
                }
            }
        });
    };
github lgapontes / hey-joe / infrastructure / memory.js View on Github external
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]
                    ]);
                }
            }
        });
    };
github polygonplanet / chillout / test / benchmark.js View on Github external
return new Promise(function(resolve, reject) {
    pusage.stat(process.pid, function(err, stat) {
      if (err) {
        console.log('[Error]');
        console.log(err);
        console.log('*** If you got an error on Windows, you may try succeed if you execute this benchmark several times.');
        process.exit(0);
      }

      cpuLoads[type].push(stat.cpu);
      resolve();
    });
  });
}
github tangmi / node-gameloop / test / simple.js View on Github external
const interval = setInterval(function() {
	testCount += 1;

	pidusage.stat(process.pid, function(err, result) {
		totalCpu += result.cpu;

		if (testCount == 10) {
			let avgDelta = totalDelta / testRuns;
			let targetDelta =
			console.log(`Test runs: ${testRuns}`);
			console.log(`target delta : ${intervalMs/1000}s`);
			console.log(`average delta: ${avgDelta}s`);
			console.log(`average cpu over ${testCount} seconds: ${totalCpu / testCount}%`);

			gameloop.clearGameLoop(loop);
			clearInterval(interval);
		}
	});
}, 1000);
github artilleryio / artillery / lib / runner-sp.js View on Github external
function checkCPU() {
        pidusage.stat(process.pid, function(err, pidStats) {
          if (err) {
            debug(err);
            return;
          }

          if (pidStats && pidStats.cpu && pidStats.cpu >= MELTING_POINT) {
            mpe++;
          }

          if (mpe * CPU_CHECK_INTERVAL_MS >= CPU_HOT_BEFORE_WARN) {
            self.events.emit('highcpu', [process.pid]);
            mpe = 0;
          }
        });
      },
      CPU_CHECK_INTERVAL_MS).unref();
github facebookarchive / atom-ide-ui / modules / atom-ide-debugger-python / VendorLib / vs-py-debugger / out / client / providers / jediProxy.js View on Github external
checkJediMemoryFootprint() {
        if (!this.proc || this.proc.killed) {
            return;
        }
        pidusage.stat(this.proc.pid, (err, result) => __awaiter(this, void 0, void 0, function* () {
            if (err) {
                return console.error('Python Extension: (pidusage)', err);
            }
            const limit = Math.min(Math.max(this.pythonSettings.jediMemoryLimit, 1024), 8192);
            if (result && result.memory > limit * 1024 * 1024) {
                this.logger.logWarning(`IntelliSense process memory consumption exceeded limit of ${limit} MB and process will be restarted.\nThe limit is controlled by the 'python.jediMemoryLimit' setting.`);
                yield this.restartLanguageServer();
            }
        }));
    }
    pythonSettingsChangeHandler() {
github AidosKuneen / aidos-wallet / app / js / main.js View on Github external
App.trackCPU = function () {
    var pid;

    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);
      }
    }
  }
github AidosKuneen / aidos-wallet / app / js / main.js View on Github external
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);
      }
    }
  }

pidusage

Cross-platform process cpu % and memory usage of a PID

MIT
Latest version published 1 year ago

Package Health Score

74 / 100
Full package analysis