extended cpu info (vendor, family, model, stepping, revision, cache, speedmin/max)
This commit is contained in:
parent
df5bba8dc3
commit
052ecdb7ec
@ -94,6 +94,7 @@ Other changes
|
||||
|
||||
| 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) |
|
||||
|
||||
15
README.md
15
README.md
@ -42,10 +42,11 @@ si.cpu()
|
||||
|
||||
### Latest Activity
|
||||
|
||||
- Version 3.18.0: extended `cpu` info (vendor, family, model, stepping, revision, cache, speedmin, speedmax)
|
||||
- Version 3.17.0: windows support for some very first functions (work in progress)
|
||||
- Version 3.16.0: `blockDevices`: added removable attribute
|
||||
- Version 3.15.0: added `cpuTemperature` also for OSX
|
||||
- Version 3.14.0: added `currentLoad` per cpu/core, cpu cache (L1, L2, L3) and cpu flags
|
||||
- Version 3.14.0: added `currentLoad` per cpu/core, `cpuCache` (L1, L2, L3) and cpu flags
|
||||
- Version 3.13.0: added `shell` (returns standard shell)
|
||||
- Version 3.12.0: refactoring and extended `currentLoad` (better OSX coverage and added irq load).
|
||||
- Version 3.11.0: `blockDevices` now also for OSX and also extended (+ label, model, serial, protocol).
|
||||
@ -128,7 +129,19 @@ This library is splitted in several sections:
|
||||
| - manufacturer | X | X | X | e.g. 'Intel(R)' |
|
||||
| - brand | X | X | X | e.g. 'Core(TM)2 Duo' |
|
||||
| - speed | X | X | X | in GHz e.g. '3.40' |
|
||||
| - speedmin | X | X | X | in GHz e.g. '0.80' |
|
||||
| - speedmax | X | X | X | in GHz e.g. '3.90' |
|
||||
| - cores | X | X | X | # cores |
|
||||
| - vendor | X | X | | Vendow ID |
|
||||
| - family | X | X | | Processor Family |
|
||||
| - Model | X | X | | Processor Model |
|
||||
| - stepping | X | X | | Processor Stepping |
|
||||
| - revision | X | X | | Revision |
|
||||
| - cache | X | X | | cache in bytes (object) |
|
||||
| - cache.l1d | X | X | | L1D size |
|
||||
| - cache.l1i | X | X | | L1I size |
|
||||
| - cache.l2 | X | X | | L2 size |
|
||||
| - cache.l3 | X | X | | L3 size |
|
||||
| si.cpuFlags(cb) | X | X | | CPU flags|
|
||||
| si.cpuCache(cb) | X | X | | CPU cache sizes |
|
||||
| - l1d | X | X | | L1D size |
|
||||
|
||||
85
lib/cpu.js
85
lib/cpu.js
@ -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);
|
||||
})
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user