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 exec = require('child_process').exec;
const execSync = require('child_process').execSync;
const fs = require('fs');
const util = require('./util');
@ -320,42 +319,39 @@ function getCpu() {
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); }
// # 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
try {
lines = [];
lines = execSync('dmidecode t 4 2>/dev/null | grep "Upgrade: Socket"').toString().split('\n');
lines = [];
exec('export LC_ALL=C; dmidecode t 4 2>/dev/null | grep "Upgrade: Socket"; unset LC_ALL', function (error2, stdout2) {
lines = stdout2.toString().split('\n');
if (lines && lines.length) {
result.socket = util.getValue(lines, 'Upgrade').replace('Socket', '').trim();
}
} catch (e) {
util.noop();
}
resolve(result);
// # processurs & # threads/core - method 1
let threadsPerCoreInt = 0;
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) {

View File

@ -167,7 +167,7 @@ function graphics(callback) {
// PCI bus IDs
let pciIDs = [];
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++) {
pciIDs[i] = pciIDs[i].replace('Bus Address:', '').replace('0000:', '').trim();
}
@ -414,7 +414,7 @@ function graphics(callback) {
pixeldepth: -1,
resolutionx: parseInt(parts[0], 10),
resolutiony: parseInt(parts[1], 10)
})
});
}
}
if (lines.length > 1 && lines[1].indexOf('gpu=') >= -1) {
@ -424,7 +424,7 @@ function graphics(callback) {
bus: '',
vram: lines[1].replace('gpu=', ''),
vramDynamic: true
})
});
}
if (callback) {
callback(result);

View File

@ -41,7 +41,7 @@ function system(callback) {
};
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) {
let lines = stdout.toString().split('\n');
result.manufacturer = util.getValue(lines, 'manufacturer');
@ -255,7 +255,7 @@ function bios(callback) {
cmd = 'cat /proc/cpuinfo | grep Serial';
} 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) {
let lines = stdout.toString().split('\n');
@ -349,7 +349,7 @@ function baseboard(callback) {
cmd = 'cat /proc/cpuinfo | grep Serial';
// 'BCM2709', 'BCM2835', 'BCM2708' -->
} 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) {
let lines = stdout.toString().split('\n');

View File

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