processes() optimized start time parsing

This commit is contained in:
Sebastian Hildebrandt 2018-08-25 10:14:32 +02:00
parent e8c72461ac
commit cedd67acee
4 changed files with 21 additions and 6 deletions

View File

@ -100,6 +100,7 @@ Other changes
| Version | Date | Comment | | 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.9 | 2018-08-08 | `cpuTemperature()` optimized parsing |
| 3.42.8 | 2018-08-03 | updated docs | | 3.42.8 | 2018-08-03 | updated docs |
| 3.42.7 | 2018-08-03 | `processes()` optimized parsing ps name | | 3.42.7 | 2018-08-03 | `processes()` optimized parsing ps name |

View File

@ -619,7 +619,7 @@ function cpuFlags(callback) {
} }
} }
if (_linux) { if (_linux) {
exec('lscpu', function (error, stdout) { exec('export LC_ALL=C; lscpu; unset LC_ALL', function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
lines.forEach(function (line) { lines.forEach(function (line) {
@ -698,7 +698,7 @@ function cpuCache(callback) {
l3: -1, l3: -1,
}; };
if (_linux) { if (_linux) {
exec('lscpu', function (error, stdout) { exec('export LC_ALL=C; lscpu; unset LC_ALL', function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
lines.forEach(function (line) { lines.forEach(function (line) {

View File

@ -148,6 +148,12 @@ function getLogoFile(distro) {
else if (distro.indexOf('solaris') !== -1) { else if (distro.indexOf('solaris') !== -1) {
result = 'solaris'; result = 'solaris';
} }
else if (distro.indexOf('tails') !== -1) {
result = 'tails';
}
else if (distro.indexOf('robolinux') !== -1) {
result = 'robolinux';
}
return result; return result;
} }

View File

@ -55,7 +55,15 @@ function parseTimeWin(time) {
} else { } else {
return ''; 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); checkColumn(7);
let nice = parseInt(line.substring(parsedhead[7].from + offset, parsedhead[7].to + offset2)) || 0; let nice = parseInt(line.substring(parsedhead[7].from + offset, parsedhead[7].to + offset2)) || 0;
checkColumn(8); 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); checkColumn(9);
let state = line.substring(parsedhead[9].from + offset, parsedhead[9].to + offset2).trim(); 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'))))))); 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 ((_process_cpu.ms && Date.now() - _process_cpu.ms >= 500) || _process_cpu.ms === 0) {
if (_linux || _freebsd || _openbsd || _darwin || _sunos) { 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 (_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 = 'ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,ni,start,state,tty,user,command'; 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 = 'ps -acxo pid,ppid,pcpu,pmem,pri,vsz,rss,nice,start,state,tty,user,command -r'; 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'; 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) { exec(cmd, { maxBuffer: 1024 * 2000 }, function (error, stdout) {
if (!error) { if (!error) {