Comparing version 2.0.5 to 2.0.6
@@ -20,2 +20,6 @@ 'use strict' | ||
if (options === undefined) { | ||
options = {} | ||
} | ||
if (typeof callback === 'function') { | ||
@@ -22,0 +26,0 @@ stats(pids, options, callback) |
'use strict' | ||
var DEFAULT_MAXAGE = 60000 | ||
@@ -7,19 +8,23 @@ var expiration = {} | ||
var size = 0 | ||
var maxage = 60000 | ||
var interval = null | ||
function get (pid) { | ||
function get (pid, maxage) { | ||
if (maxage <= 0) { | ||
return | ||
} | ||
if (history[pid] !== undefined) { | ||
expiration[pid] = Date.now() + maxage | ||
expiration[pid] = Date.now() + (maxage || DEFAULT_MAXAGE) | ||
} | ||
return history[pid] | ||
} | ||
function set (pid, object) { | ||
if (object === undefined) return | ||
function set (pid, object, maxage) { | ||
if (object === undefined || maxage <= 0) return | ||
expiration[pid] = Date.now() + maxage | ||
expiration[pid] = Date.now() + (maxage || DEFAULT_MAXAGE) | ||
if (history[pid] === undefined) { | ||
size++ | ||
sheduleInvalidator() | ||
sheduleInvalidator(maxage) | ||
} | ||
@@ -29,15 +34,6 @@ history[pid] = object | ||
function remove (pid) { | ||
if (history[pid] !== undefined) { | ||
size-- | ||
delete history[pid] | ||
delete expiration[pid] | ||
sheduleInvalidator() | ||
} | ||
} | ||
function sheduleInvalidator () { | ||
function sheduleInvalidator (maxage) { | ||
if (size > 0) { | ||
if (interval === null) { | ||
interval = setInterval(runInvalidator, maxage / 2) | ||
interval = setInterval(runInvalidator, (maxage || DEFAULT_MAXAGE) / 2) | ||
} | ||
@@ -69,4 +65,3 @@ | ||
get: get, | ||
set: set, | ||
remove: remove | ||
set: set | ||
} |
'use strict' | ||
var fs = require('fs') | ||
var os = require('os') | ||
@@ -15,2 +16,3 @@ | ||
var useProcfile = fs.existsSync('/etc/alpine-release') | ||
var platform = os.platform() | ||
@@ -23,3 +25,3 @@ if (platform.match(/^win/)) { | ||
try { | ||
stat = require('./' + platformToMethod[platform]) | ||
stat = useProcfile ? require('./procfile') : require('./' + platformToMethod[platform]) | ||
} catch (err) {} | ||
@@ -37,2 +39,3 @@ | ||
* @param {Number|Number[]|String|String[]} pids A pid or a list of pids. | ||
* @param {Object} [options={}] Options object | ||
* @param {pidCallback} callback Called when the statistics are ready. | ||
@@ -62,3 +65,3 @@ */ | ||
stat(pids, {}, function (err, stats) { | ||
stat(pids, options, function (err, stats) { | ||
if (err) { | ||
@@ -65,0 +68,0 @@ return callback(err) |
@@ -95,3 +95,3 @@ 'use strict' | ||
var hst = history.get(pid) | ||
var hst = history.get(pid, options.maxage) | ||
if (hst === undefined) { | ||
@@ -108,3 +108,3 @@ again = true | ||
history.set(pid, {ctime: usertime + kerneltime, uptime: uptime}) | ||
history.set(pid, {ctime: usertime + kerneltime, uptime: uptime}, options.maxage) | ||
@@ -111,0 +111,0 @@ statistics[pid] = { |
{ | ||
"name": "pidusage", | ||
"version": "2.0.5", | ||
"version": "2.0.6", | ||
"description": "Cross-platform process cpu % and memory usage of a PID", | ||
@@ -26,2 +26,3 @@ "license": "MIT", | ||
"test": "npm run lint && nyc ava -m \"!*benchmark*\"", | ||
"alpine": "docker run -v $(pwd):/var/pidusage pidusage:latest npm test", | ||
"coverage": "codecov", | ||
@@ -28,0 +29,0 @@ "bench": "ava -m \"*benchmark*\"" |
@@ -80,10 +80,10 @@ # pidusage | ||
| Property | Linux | FreeBSD | NetBSD | SunOS | macOS | Win | AIX | | ||
| --- | --- | --- | --- | --- | --- | --- | --- | | ||
| `cpu` | ✅ | ❓ | ❓ | ❓ | ✅ | ℹ️ | ❓ | | ||
| `memory` | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | | ||
| `pid` | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | | ||
| `ctime` | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | | ||
| `elapsed` | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | | ||
| `timestamp` | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | | ||
| Property | Linux | FreeBSD | NetBSD | SunOS | macOS | Win | AIX | Alpine | ||
| --- | --- | --- | --- | --- | --- | --- | --- | --- | | ||
| `cpu` | ✅ | ❓ | ❓ | ❓ | ✅ | ℹ️ | ❓ | ✅ | | ||
| `memory` | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ | | ||
| `pid` | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ | | ||
| `ctime` | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ | | ||
| `elapsed` | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ | | ||
| `timestamp` | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ | | ||
@@ -102,3 +102,3 @@ ✅ = Working | ||
### pidusage(pids, [callback]) ⇒ <code>[Promise.<Object>]</code> | ||
### pidusage(pids, [options = {}], [callback]) ⇒ <code>[Promise.<Object>]</code> | ||
Get pid informations. | ||
@@ -105,0 +105,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26297
13
570
5
2