smaller fixes

This commit is contained in:
Sebastian Hildebrandt 2019-02-01 18:31:43 +01:00
parent e0cf84836a
commit 877bd6b963
4 changed files with 39 additions and 43 deletions

View File

@ -14,7 +14,6 @@
const os = require('os'); const os = require('os');
const exec = require('child_process').exec; const exec = require('child_process').exec;
const execSync = require('child_process').execSync;
const fs = require('fs'); const fs = require('fs');
const util = require('./util'); const util = require('./util');
@ -320,42 +319,39 @@ function getCpu() {
result.cache.l3 = util.getValue(lines, 'l3 cache'); result.cache.l3 = util.getValue(lines, 'l3 cache');
if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3) * (result.cache.l3.indexOf('K') !== -1 ? 1024 : 1); } if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3) * (result.cache.l3.indexOf('K') !== -1 ? 1024 : 1); }
// # processurs & # threads/core - method 1
let threadsPerCoreInt = 0;
try {
lines = [];
lines = execSync('cat /proc/cpuinfo | grep -E "physical id|core id"').toString().split('\n');
if (lines && lines.length) {
result.processors = util.countUniqueLines(lines, 'physical id') || 1;
result.physicalCores = util.countUniqueLines(lines, 'core id') / result.processors;
if (result.physicalCores) {
threadsPerCoreInt = result.cores / result.physicalCores;
}
}
} catch (e) {
util.noop();
}
// # threads/core - method 2
if (threadsPerCoreInt === 0) {
const threadsPerCore = util.getValue(lines, 'thread(s) per core');
if (threadsPerCore) {
threadsPerCoreInt = parseInt(threadsPerCore, 10);
if (!isNaN(threadsPerCoreInt)) {
result.physicalCores = result.cores / threadsPerCoreInt;
}
}
}
// socket type // socket type
try { lines = [];
lines = []; exec('export LC_ALL=C; dmidecode t 4 2>/dev/null | grep "Upgrade: Socket"; unset LC_ALL', function (error2, stdout2) {
lines = execSync('dmidecode t 4 2>/dev/null | grep "Upgrade: Socket"').toString().split('\n'); lines = stdout2.toString().split('\n');
if (lines && lines.length) { if (lines && lines.length) {
result.socket = util.getValue(lines, 'Upgrade').replace('Socket', '').trim(); result.socket = util.getValue(lines, 'Upgrade').replace('Socket', '').trim();
} }
} catch (e) {
util.noop(); // # processurs & # threads/core - method 1
} let threadsPerCoreInt = 0;
resolve(result); lines = [];
exec('cat /proc/cpuinfo | grep -E "physical id|core id"', function (error2, stdout3) {
lines = stdout3.toString().split('\n');
if (lines && lines.length) {
result.processors = util.countUniqueLines(lines, 'physical id') || 1;
result.physicalCores = util.countUniqueLines(lines, 'core id') / result.processors;
if (result.physicalCores) {
threadsPerCoreInt = result.cores / result.physicalCores;
}
}
// # threads/core - method 2
if (threadsPerCoreInt === 0) {
const threadsPerCore = util.getValue(lines, 'thread(s) per core');
if (threadsPerCore) {
threadsPerCoreInt = parseInt(threadsPerCore, 10);
if (!isNaN(threadsPerCoreInt)) {
result.physicalCores = result.cores / threadsPerCoreInt;
}
}
}
resolve(result);
});
});
}); });
} }
if (_freebsd || _openbsd) { if (_freebsd || _openbsd) {

View File

@ -167,7 +167,7 @@ function graphics(callback) {
// PCI bus IDs // PCI bus IDs
let pciIDs = []; let pciIDs = [];
try { try {
pciIDs = execSync('dmidecode -t 9 2>/dev/null | grep "Bus Address: "').toString().split('\n'); pciIDs = execSync('export LC_ALL=C; dmidecode -t 9 2>/dev/null; unset LC_ALL | grep "Bus Address: "').toString().split('\n');
for (let i = 0; i < pciIDs.length; i++) { for (let i = 0; i < pciIDs.length; i++) {
pciIDs[i] = pciIDs[i].replace('Bus Address:', '').replace('0000:', '').trim(); pciIDs[i] = pciIDs[i].replace('Bus Address:', '').replace('0000:', '').trim();
} }
@ -414,7 +414,7 @@ function graphics(callback) {
pixeldepth: -1, pixeldepth: -1,
resolutionx: parseInt(parts[0], 10), resolutionx: parseInt(parts[0], 10),
resolutiony: parseInt(parts[1], 10) resolutiony: parseInt(parts[1], 10)
}) });
} }
} }
if (lines.length > 1 && lines[1].indexOf('gpu=') >= -1) { if (lines.length > 1 && lines[1].indexOf('gpu=') >= -1) {
@ -424,7 +424,7 @@ function graphics(callback) {
bus: '', bus: '',
vram: lines[1].replace('gpu=', ''), vram: lines[1].replace('gpu=', ''),
vramDynamic: true vramDynamic: true
}) });
} }
if (callback) { if (callback) {
callback(result); callback(result);

View File

@ -41,7 +41,7 @@ function system(callback) {
}; };
if (_linux || _freebsd || _openbsd) { if (_linux || _freebsd || _openbsd) {
exec('dmidecode -t system 2>/dev/null', function (error, stdout) { exec('export LC_ALL=C; dmidecode -t system 2>/dev/null; unset LC_ALL', function (error, stdout) {
// if (!error) { // if (!error) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
result.manufacturer = util.getValue(lines, 'manufacturer'); result.manufacturer = util.getValue(lines, 'manufacturer');
@ -255,7 +255,7 @@ function bios(callback) {
cmd = 'cat /proc/cpuinfo | grep Serial'; cmd = 'cat /proc/cpuinfo | grep Serial';
} else { } else {
cmd = 'dmidecode --type 0 2>/dev/null'; cmd = 'export LC_ALL=C; dmidecode --type 0 2>/dev/null; unset LC_ALL';
} }
exec(cmd, function (error, stdout) { exec(cmd, function (error, stdout) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
@ -349,7 +349,7 @@ function baseboard(callback) {
cmd = 'cat /proc/cpuinfo | grep Serial'; cmd = 'cat /proc/cpuinfo | grep Serial';
// 'BCM2709', 'BCM2835', 'BCM2708' --> // 'BCM2709', 'BCM2835', 'BCM2708' -->
} else { } else {
cmd = 'dmidecode -t 2 2>/dev/null'; cmd = 'export LC_ALL=C; dmidecode -t 2 2>/dev/null; unset LC_ALL';
} }
exec(cmd, function (error, stdout) { exec(cmd, function (error, stdout) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');

View File

@ -292,9 +292,9 @@ function isRaspberry() {
cpuinfo = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).split('\n'); cpuinfo = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).split('\n');
} catch (e) { } catch (e) {
return false; return false;
}; }
const hardware = getValue(cpuinfo, 'hardware'); const hardware = getValue(cpuinfo, 'hardware');
return (PI_MODEL_NO.indexOf(hardware) >= -1) return (hardware && PI_MODEL_NO.indexOf(hardware) > -1);
} }
function isRaspbian() { function isRaspbian() {
@ -303,9 +303,9 @@ function isRaspbian() {
osrelease = fs.readFileSync('/etc/os-release', { encoding: 'utf8' }).split('\n'); osrelease = fs.readFileSync('/etc/os-release', { encoding: 'utf8' }).split('\n');
} catch (e) { } catch (e) {
return false; return false;
}; }
const id = getValue(osrelease, 'id'); const id = getValue(osrelease, 'id');
return (id.indexOf('raspbian') >= -1) return (id && id.indexOf('raspbian') > -1);
} }
function execWin(cmd, opts, callback) { function execWin(cmd, opts, callback) {