Comparing version 1.0.2 to 1.0.3
@@ -18,5 +18,5 @@ var os = require('os') | ||
return done(err, null) | ||
if(uptime === undefined) { | ||
console.error("We couldn't find uptime from /proc/uptime") | ||
console.error("[pidusage] We couldn't find uptime from /proc/uptime") | ||
self.cpu.uptime = os.uptime() | ||
@@ -69,3 +69,3 @@ } else { | ||
var childrens = options.childrens ? stat.cutime + stat.cstime : 0 | ||
var total = stat.stime - (history.stime || 0) + stat.utime - (history.utime || 0) + childrens | ||
@@ -131,25 +131,32 @@ | ||
// https://msdn.microsoft.com/en-us/library/aa394277(v=vs.85).aspx | ||
var args = 'path Win32_PerfFormattedData_PerfProc_Process WHERE IDProcess=' + pid + ' get PercentProcessorTime, WorkingSet' | ||
var wmic = spawn('wmic', args.split(' '), {detached: true}) | ||
var stdout = '' | ||
var stderr = '' | ||
wmic.stdout.on('data', function(d) { | ||
stdout += d.toString() | ||
stdout += d.toString() | ||
}) | ||
wmic.stderr.on('data', function(d) { | ||
console.error(d.toString()) | ||
stderr += d.toString() | ||
}) | ||
wmic.on('close', function() { | ||
wmic.on('close', function(code) { | ||
stdout = stdout.trim() | ||
if(!stdout) | ||
return done(new Error(pid + ' does not exist', null)) | ||
return done(new Error(pid + ' does not exist'), null) | ||
stderr = stderr.trim() | ||
if (!!code && stderr) { | ||
return done(new Error(stderr), null) | ||
} | ||
// The new line in Windows is '\r\r\n' | ||
var lines = stdout.split(/\r?\r\n/) | ||
// We might need the titles someday. | ||
//var titles = lines[0].trim().split( / +/ ) | ||
//var titles = lines[0].trim().split( / +/ ) | ||
var values = lines[1].trim().split(/ +/) | ||
@@ -165,6 +172,2 @@ var cpuPercent = parseFloat(values[0]) | ||
}) | ||
wmic.on('error', function(err) { | ||
done(err, null) | ||
}) | ||
} | ||
@@ -171,0 +174,0 @@ } |
{ | ||
"name": "pidusage", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Process cpu % and memory use of a PID", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
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
20444
405