Skip to content

Commit

Permalink
fix(ps): parseTime centiseconds multiplier is 10
Browse files Browse the repository at this point in the history
Update documentation

fix tests
  • Loading branch information
abluchet committed Aug 21, 2018
1 parent 4adaa1a commit bcda538
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions lib/ps.js
Expand Up @@ -6,12 +6,12 @@ var history = require('./history')

var PLATFORM = os.platform()

function parseTime (timestr, fraction) {
function parseTime (timestr, centisec) {
var time = 0
var tpart = timestr.split(/-|:|\./)
var i = tpart.length - 1
if (i >= 0 && fraction && PLATFORM === 'darwin') { // Fractions of second
time += parseInt(tpart[i--], 10) * 600
if (i >= 0 && centisec && PLATFORM === 'darwin') {
time += parseInt(tpart[i--], 10) * 10
}
if (i >= 0) { // Seconds
time += parseInt(tpart[i--], 10) * 1000
Expand Down Expand Up @@ -70,7 +70,7 @@ function ps (pids, options, done) {
// Example of stdout on Darwin
// ELAPSED: format is [[dd-]hh:]mm:ss
// RSS: is counted as blocks of 1024 bytes
// TIME: format is [[dd-]hh:]ss:mm.pp (pp is the percentage of a minute)
// TIME: format is [[dd-]hh:]mm:ss.cc (cc are centiseconds)
// %CPU: goes from 0 to vcore * 100
//
// Refs: https://ss64.com/osx/ps.html
Expand Down
16 changes: 8 additions & 8 deletions test/ps.js
Expand Up @@ -50,38 +50,38 @@ test('should parse ps output on Darwin', async t => {
const result = await pify(ps)([348932], {})
t.deepEqual(result, {
430: {
cpu: (93788200 / 319853000) * 100,
cpu: (93784070 / 319853000) * 100,
memory: 5145 * 1024,
ppid: 1,
pid: 430,
ctime: (1 * 86400 + 2 * 3600 + 3 * 60 + 4 * 1) * 1000 + (600 * 7),
ctime: (1 * 86400 + 2 * 3600 + 3 * 60 + 4 * 1) * 1000 + (10 * 7),
elapsed: (2 * 86400 + 40 * 3600 + 50 * 60 + 53 * 1) * 1000,
timestamp: 864000000
},
432: {
cpu: (90129000 / 147053000) * 100,
cpu: (90123100 / 147053000) * 100,
memory: 2364 * 1024,
ppid: 430,
pid: 432,
ctime: (1 * 86400 + 1 * 3600 + 2 * 60 + 3 * 1) * 1000 + (600 * 10),
ctime: (1 * 86400 + 1 * 3600 + 2 * 60 + 3 * 1) * 1000 + (10 * 10),
elapsed: (40 * 3600 + 50 * 60 + 53 * 1) * 1000,
timestamp: 864000000
},
727: {
cpu: (882600 / 6650000) * 100,
cpu: (867260 / 6650000) * 100,
memory: 348932 * 1024,
ppid: 1,
pid: 727,
ctime: (14 * 60 + 27 * 1) * 1000 + (600 * 26),
ctime: (14 * 60 + 27 * 1) * 1000 + (10 * 26),
elapsed: (1 * 3600 + 50 * 60 + 50 * 1) * 1000,
timestamp: 864000000
},
7166: {
cpu: (1200 / 20000) * 100,
cpu: (20 / 20000) * 100,
memory: 3756 * 1024,
ppid: 1,
pid: 7166,
ctime: (600 * 2),
ctime: (10 * 2),
elapsed: (20 * 1) * 1000,
timestamp: 864000000
}
Expand Down

0 comments on commit bcda538

Please sign in to comment.