Socket
Socket
Sign inDemoInstall

usage

Package Overview
Dependencies
1
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.6 to 0.3.7

34

lib/providers/mac.js

@@ -0,1 +1,3 @@

var exec = require('child_process').exec;
module.exports = function(sysinfo) {

@@ -16,4 +18,34 @@

sysinfo.getUsage(pid, callback);
exec('ps -vp ' + pid, function(err, stdout, stderr) {
if (err || stderr) return callback(err || stderr);
var usage = parsePS(pid, stdout);
if (!usage)
return callback('INVALID_PID');
callback(null, usage);
});
};
}
function parsePS(pid, output) {
var lines = output.trim().split('\n');
if (lines.length !== 2)
return null;
var labelsMap = {};
var labels = lines[0].trim().split(/[ \t]+/g);
for (var i = 0; i < labels.length; i++)
labelsMap[labels[i]] = i;
var values = lines[1].trim().split(/[ \t]+/g);
var foundPID = parseInt(values[labelsMap['PID']], 10);
var rss = parseInt(values[labelsMap['RSS']], 10);
var cpu = parseFloat(values[labelsMap['%CPU']]);
if (pid != foundPID || isNaN(rss) || isNaN(cpu))
return null;
return { memory: rss, cpu: cpu };
}

2

package.json
{
"name": "usage",
"version": "0.3.6",
"version": "0.3.7",
"description": "simple way to lookup linux process usage",

@@ -5,0 +5,0 @@ "keywords": [

@@ -52,5 +52,2 @@ # node-usage [![Build Status](https://travis-ci.org/arunoda/node-usage.png?branch=master)](https://travis-ci.org/arunoda/node-usage)

## Notes on OSX
if you are going to monitor usage of a foriegn pid, please do it as `sudo`. See [here](https://github.com/arunoda/node-usage/pull/5) for more details.
## Motivation

@@ -57,0 +54,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc