diff --git a/CHANGELOG.md b/CHANGELOG.md index 0075feb..30dac75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.42.10 | 2018-08-25 | `processes()` optimized start time parsing | | 3.42.9 | 2018-08-08 | `cpuTemperature()` optimized parsing | | 3.42.8 | 2018-08-03 | updated docs | | 3.42.7 | 2018-08-03 | `processes()` optimized parsing ps name | diff --git a/lib/cpu.js b/lib/cpu.js index 5167312..7a4b20d 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -619,7 +619,7 @@ function cpuFlags(callback) { } } if (_linux) { - exec('lscpu', function (error, stdout) { + exec('export LC_ALL=C; lscpu; unset LC_ALL', function (error, stdout) { if (!error) { let lines = stdout.toString().split('\n'); lines.forEach(function (line) { @@ -698,7 +698,7 @@ function cpuCache(callback) { l3: -1, }; if (_linux) { - exec('lscpu', function (error, stdout) { + exec('export LC_ALL=C; lscpu; unset LC_ALL', function (error, stdout) { if (!error) { let lines = stdout.toString().split('\n'); lines.forEach(function (line) { diff --git a/lib/osinfo.js b/lib/osinfo.js index b6072a4..822efe5 100644 --- a/lib/osinfo.js +++ b/lib/osinfo.js @@ -148,6 +148,12 @@ function getLogoFile(distro) { else if (distro.indexOf('solaris') !== -1) { result = 'solaris'; } + else if (distro.indexOf('tails') !== -1) { + result = 'tails'; + } + else if (distro.indexOf('robolinux') !== -1) { + result = 'robolinux'; + } return result; } diff --git a/lib/processes.js b/lib/processes.js index 7a8b9e5..ed7df78 100644 --- a/lib/processes.js +++ b/lib/processes.js @@ -55,7 +55,15 @@ function parseTimeWin(time) { } else { return ''; } +} +function parseTimeUnix(time) { + let result = time; + let parts = time.replace(/ +/g, ' ').split(' '); + if (parts.length === 5) { + result = parts[4] + '-' + ('0' + ('JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'.indexOf(parts[1].toUpperCase()) / 3 + 1)).slice(-2) + '-' + ('0' + parts[2]).slice(-2) + ' ' + parts[3]; + } + return result; } // -------------------------- @@ -308,7 +316,7 @@ function processes(callback) { checkColumn(7); let nice = parseInt(line.substring(parsedhead[7].from + offset, parsedhead[7].to + offset2)) || 0; checkColumn(8); - let started = line.substring(parsedhead[8].from + offset, parsedhead[8].to + offset2).trim(); + let started = parseTimeUnix(line.substring(parsedhead[8].from + offset, parsedhead[8].to + offset2).trim()); checkColumn(9); let state = line.substring(parsedhead[9].from + offset, parsedhead[9].to + offset2).trim(); state = (state[0] === 'R' ? 'running' : (state[0] === 'S' ? 'sleeping' : (state[0] === 'T' ? 'stopped' : (state[0] === 'W' ? 'paging' : (state[0] === 'X' ? 'dead' : (state[0] === 'Z' ? 'zombie' : ((state[0] === 'D' || state[0] === 'U') ? 'blocked' : 'unknown'))))))); @@ -504,9 +512,9 @@ function processes(callback) { if ((_process_cpu.ms && Date.now() - _process_cpu.ms >= 500) || _process_cpu.ms === 0) { if (_linux || _freebsd || _openbsd || _darwin || _sunos) { - if (_linux) cmd = 'ps -axo pid:10,ppid:10,pcpu:6,pmem:6,pri:5,vsz:10,rss:10,ni:5,start:20,state:20,tty:20,user:20,command'; - if (_freebsd || _openbsd) cmd = 'ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,ni,start,state,tty,user,command'; - if (_darwin) cmd = 'ps -acxo pid,ppid,pcpu,pmem,pri,vsz,rss,nice,start,state,tty,user,command -r'; + if (_linux) cmd = 'export LC_ALL=C; ps -axo pid:11,ppid:11,pcpu:6,pmem:6,pri:5,vsz:11,rss:11,ni:5,lstart:30,state:5,tty:15,user:20,command; unset LC_ALL'; + if (_freebsd || _openbsd) cmd = 'export LC_ALL=C; ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,ni,lstart,state,tty,user,command; unset LC_ALL'; + if (_darwin) cmd = 'export LC_ALL=C; ps -acxo pid,ppid,pcpu,pmem,pri,vsz,rss,nice,lstart,state,tty,user,command -r; unset LC_ALL'; if (_sunos) cmd = 'ps -Ao pid,ppid,pcpu,pmem,pri,vsz,rss,nice,stime,s,tty,user,comm'; exec(cmd, { maxBuffer: 1024 * 2000 }, function (error, stdout) { if (!error) {