Skip to content

Commit

Permalink
Merge pull request #61 from soyuka/cpu-fix
Browse files Browse the repository at this point in the history
[WIP] Fix cpu percentage on multi threaded processes
  • Loading branch information
soyuka authored Jun 11, 2018
2 parents e3f0c05 + eb478da commit f990f72
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ setInterval(function () {
pidusage(process.pid, function (err, stats) {
console.log(stats)
// => {
// cpu: 10.0, // percentage (0-100%)
// cpu: 10.0, // percentage (from 0 to 100*vcore)
// memory: 357306368, // bytes
// ppid: 312, // PPID
// pid: 727, // PID
Expand All @@ -41,7 +41,7 @@ pidusage([727, 1234], function (err, stats) {
console.log(stats)
// => {
// 727: {
// cpu: 10.0, // percentage (0-100%)
// cpu: 10.0, // percentage (from 0 to 100*vcore)
// memory: 357306368, // bytes
// ppid: 312, // PPID
// pid: 727, // PID
Expand All @@ -50,7 +50,7 @@ pidusage([727, 1234], function (err, stats) {
// timestamp: 864000000 // ms since epoch
// },
// 1234: {
// cpu: 0.1, // percentage (0-100%)
// cpu: 0.1, // percentage (from 0 to 100*vcore)
// memory: 3846144, // bytes
// ppid: 727, // PPID
// pid: 1234, // PID
Expand All @@ -65,7 +65,7 @@ pidusage([727, 1234], function (err, stats) {
const stats = await pidusage(process.pid)
console.log(stats)
// => {
// cpu: 10.0, // percentage (0-100%)
// cpu: 10.0, // percentage (from 0 to 100*vcore)
// memory: 357306368, // bytes
// ppid: 312, // PPID
// pid: 727, // PID
Expand Down
2 changes: 1 addition & 1 deletion lib/procfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function readProcFile (pid, options, done) {
history.set(stat, options.maxage)

return done(null, {
cpu: Math.min(cpu, 100.0),
cpu: cpu,
memory: memory,
ctime: (stat.utime + stat.stime) / cpuInfo.clockTick,
elapsed: date - (stat.start * 1000),
Expand Down
2 changes: 1 addition & 1 deletion lib/ps.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function ps (pids, options, done) {
var ctime = parseTime(line[5], true)

statistics[pid] = {
cpu: Math.min(cpu, 100.0),
cpu: cpu,
memory: memory,
ppid: ppid,
pid: pid,
Expand Down
2 changes: 1 addition & 1 deletion lib/wmic.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function wmic (pids, options, done) {
history.set(pid, {ctime: usertime + kerneltime, uptime: uptime}, options.maxage)

statistics[pid] = {
cpu: Math.min(cpu, 100.0),
cpu: cpu,
memory: memory,
ppid: ppid,
pid: pid,
Expand Down
6 changes: 2 additions & 4 deletions test/ps.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ test('should parse ps output on Darwin', async t => {
EOL: os.EOL,
platform: () => 'darwin',
type: () => 'type',
release: () => 'release',
cpus: () => [os.cpus()[0]]
release: () => 'release'
})

const ps = require('../lib/ps')
Expand Down Expand Up @@ -106,8 +105,7 @@ test('should parse ps output on *nix', async t => {
EOL: os.EOL,
platform: () => 'linux',
type: () => 'type',
release: () => 'release',
cpus: () => [os.cpus()[0]]
release: () => 'release'
})

const ps = require('../lib/ps')
Expand Down

0 comments on commit f990f72

Please sign in to comment.