extended cpu info (vendor, family, model, stepping, revision, cache, speedmin/max)

This commit is contained in:
Sebastian Hildebrandt
2017-05-27 18:01:01 +02:00
parent df5bba8dc3
commit 052ecdb7ec
4 changed files with 86 additions and 16 deletions
+70 -15
View File
@@ -56,6 +56,18 @@ function cpuBrandManufacturer(res) {
return res;
}
function getValue(lines, property) {
for (let i = 0; i < lines.length; i++) {
if (lines[i].toLowerCase().startsWith(property)) {
const parts = lines[i].split(':');
if (parts.length > 1) {
return parts[1].trim();
}
}
}
return '';
}
// --------------------------
// CPU - brand, speed
@@ -63,39 +75,82 @@ function getCpu() {
return new Promise((resolve) => {
process.nextTick(() => {
const UNKNOWN = 'unknown'
let result = {
manufacturer: 'unknown',
brand: 'unknown',
manufacturer: UNKNOWN,
brand: UNKNOWN,
vendor: '',
family: '',
model: '',
stepping: '',
revision: '',
speed: '0.00',
cores: util.cores()
speedmin: '',
speedmax: '',
cores: util.cores(),
cache: {}
};
if (_darwin) {
exec("sysctl -n machdep.cpu.brand_string", function (error, stdout) {
exec("sysctl machdep.cpu hw.cpufrequency_max hw.cpufrequency_min", function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
result.brand = lines[0].split('@')[0].trim();
result.speed = lines[0].split('@')[1].trim();
result.speed = parseFloat(result.speed.replace(/GHz+/g, ""));
const modelline = getValue(lines, 'machdep.cpu.brand_string');
result.brand = modelline.split('@')[0].trim();
result.speed = modelline.split('@')[1].trim();
result.speed = parseFloat(result.speed.replace(/GHz+/g, "")).toFixed(2);
_cpu_speed = result.speed;
result = cpuBrandManufacturer(result);
result.speedmin = (getValue(lines, 'hw.cpufrequency_min') / 1000000000.0 ).toFixed(2);
result.speedmax = (getValue(lines, 'hw.cpufrequency_max') / 1000000000.0 ).toFixed(2);
result.vendor = getValue(lines, 'machdep.cpu.vendor');
result.family = getValue(lines, 'machdep.cpu.family');
result.model = getValue(lines, 'machdep.cpu.model');
result.stepping = getValue(lines, 'machdep.cpu.stepping');
}
result = cpuBrandManufacturer(result);
resolve(result);
cpuCache().then(res => {
result.cache = res;
resolve(result);
})
});
}
if (_linux) {
exec("cat /proc/cpuinfo | grep 'model name'", function (error, stdout) {
exec("lscpu", function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
let line = lines[0].split(':')[1];
result.brand = line.split('@')[0].trim();
result.speed = line.split('@')[1] ? parseFloat(line.split('@')[1].trim()).toFixed(2) : '0.00';
const modelline = getValue(lines, 'model name');
result.brand = modelline.split('@')[0].trim();
result.speed = modelline.split('@')[1] ? parseFloat(modelline.split('@')[1].trim()).toFixed(2) : '0.00';
if (result.speed === '0.00') {
let current = getCpuCurrentSpeedSync();
if (current !== '0.00') result.speed = current;
}
_cpu_speed = result.speed;
result.speedmin = Math.round(parseFloat(getValue(lines, 'cpu min mhz').replace(/,/g, '.')) / 10.0) / 100;
result.speedmin = result.speedmin ? parseFloat(result.speedmin).toFixed(2) : ''
result.speedmax = Math.round(parseFloat(getValue(lines, 'cpu max mhz').replace(/,/g, '.')) / 10.0) / 100;
result.speedmax = result.speedmax ? parseFloat(result.speedmax).toFixed(2) : ''
result = cpuBrandManufacturer(result);
result.vendor = getValue(lines, 'vendor id');
if (!result.vendor) { result.vendor = getValue(lines, 'anbieterkennung'); }
result.family = getValue(lines, 'cpu family');
if (!result.family) { result.family = getValue(lines, 'prozessorfamilie'); }
result.model = getValue(lines, 'model:');
if (!result.model) { result.model = getValue(lines, 'modell:'); }
result.stepping = getValue(lines, 'stepping');
result.revision = getValue(lines, 'cpu revision');
result.cache.l1d = getValue(lines, 'l1d cache');
if (result.cache.l1d) { result.cache.l1d = parseInt(result.cache.l1d) * (result.cache.l1d.indexOf('K') !== -1 ? 1024 : 1)}
result.cache.l1i = getValue(lines, 'l1i cache');
if (result.cache.l1i) { result.cache.l1i = parseInt(result.cache.l1i) * (result.cache.l1i.indexOf('K') !== -1 ? 1024 : 1)}
result.cache.l2 = getValue(lines, 'l2 cache');
if (result.cache.l2) { result.cache.l2 = parseInt(result.cache.l2) * (result.cache.l2.indexOf('K') !== -1 ? 1024 : 1)}
result.cache.l3 = getValue(lines, 'l3 cache');
if (result.cache.l3) { result.cache.l3 = parseInt(result.cache.l3) * (result.cache.l3.indexOf('K') !== -1 ? 1024 : 1)}
} else {
}
result = cpuBrandManufacturer(result);
resolve(result);
})
}
@@ -108,8 +163,8 @@ function getCpu() {
result.speed = line.split('@')[1].trim();
result.speed = parseFloat(result.speed.replace(/GHz+/g, ""));
_cpu_speed = result.speed;
result = cpuBrandManufacturer(result);
}
result = cpuBrandManufacturer(result);
resolve(result);
})
}
+1
View File
@@ -82,6 +82,7 @@
// --------------------------------
//
// version date comment
// 3.18.0 2017-05-23 extended `cpu` info (vendor, family, model, stepping, revision, cache, speedmin/max)
// 3.17.3 2017-04-29 minor fix (blockDevices data array, Windows)
// 3.17.2 2017-04-24 minor fix (removed console.log)
// 3.17.1 2017-04-23 fixed bugs fsSize(win), si.processes (command), si.osinfo(win)