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 |
|
| 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.3 | 2017-04-29 | minor fix (blockDevices data array, Windows) |
|
||||||
| 3.17.2 | 2017-04-24 | minor fix (removed console.log) |
|
| 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) |
|
| 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
|
### 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.17.0: windows support for some very first functions (work in progress)
|
||||||
- Version 3.16.0: `blockDevices`: added removable attribute
|
- Version 3.16.0: `blockDevices`: added removable attribute
|
||||||
- Version 3.15.0: added `cpuTemperature` also for OSX
|
- 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.13.0: added `shell` (returns standard shell)
|
||||||
- Version 3.12.0: refactoring and extended `currentLoad` (better OSX coverage and added irq load).
|
- 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).
|
- 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)' |
|
| - manufacturer | X | X | X | e.g. 'Intel(R)' |
|
||||||
| - brand | X | X | X | e.g. 'Core(TM)2 Duo' |
|
| - brand | X | X | X | e.g. 'Core(TM)2 Duo' |
|
||||||
| - speed | X | X | X | in GHz e.g. '3.40' |
|
| - 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 |
|
| - 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.cpuFlags(cb) | X | X | | CPU flags|
|
||||||
| si.cpuCache(cb) | X | X | | CPU cache sizes |
|
| si.cpuCache(cb) | X | X | | CPU cache sizes |
|
||||||
| - l1d | X | X | | L1D size |
|
| - l1d | X | X | | L1D size |
|
||||||
|
|||||||
85
lib/cpu.js
85
lib/cpu.js
@ -56,6 +56,18 @@ function cpuBrandManufacturer(res) {
|
|||||||
return 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
|
// CPU - brand, speed
|
||||||
|
|
||||||
@ -63,39 +75,82 @@ function getCpu() {
|
|||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
|
const UNKNOWN = 'unknown'
|
||||||
let result = {
|
let result = {
|
||||||
manufacturer: 'unknown',
|
manufacturer: UNKNOWN,
|
||||||
brand: 'unknown',
|
brand: UNKNOWN,
|
||||||
|
vendor: '',
|
||||||
|
family: '',
|
||||||
|
model: '',
|
||||||
|
stepping: '',
|
||||||
|
revision: '',
|
||||||
speed: '0.00',
|
speed: '0.00',
|
||||||
cores: util.cores()
|
speedmin: '',
|
||||||
|
speedmax: '',
|
||||||
|
cores: util.cores(),
|
||||||
|
cache: {}
|
||||||
};
|
};
|
||||||
if (_darwin) {
|
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) {
|
if (!error) {
|
||||||
let lines = stdout.toString().split('\n');
|
let lines = stdout.toString().split('\n');
|
||||||
result.brand = lines[0].split('@')[0].trim();
|
const modelline = getValue(lines, 'machdep.cpu.brand_string');
|
||||||
result.speed = lines[0].split('@')[1].trim();
|
result.brand = modelline.split('@')[0].trim();
|
||||||
result.speed = parseFloat(result.speed.replace(/GHz+/g, ""));
|
result.speed = modelline.split('@')[1].trim();
|
||||||
|
result.speed = parseFloat(result.speed.replace(/GHz+/g, "")).toFixed(2);
|
||||||
_cpu_speed = result.speed;
|
_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);
|
cpuCache().then(res => {
|
||||||
resolve(result);
|
result.cache = res;
|
||||||
|
resolve(result);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (_linux) {
|
if (_linux) {
|
||||||
exec("cat /proc/cpuinfo | grep 'model name'", function (error, stdout) {
|
exec("lscpu", function (error, stdout) {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
let lines = stdout.toString().split('\n');
|
let lines = stdout.toString().split('\n');
|
||||||
let line = lines[0].split(':')[1];
|
const modelline = getValue(lines, 'model name');
|
||||||
result.brand = line.split('@')[0].trim();
|
result.brand = modelline.split('@')[0].trim();
|
||||||
result.speed = line.split('@')[1] ? parseFloat(line.split('@')[1].trim()).toFixed(2) : '0.00';
|
result.speed = modelline.split('@')[1] ? parseFloat(modelline.split('@')[1].trim()).toFixed(2) : '0.00';
|
||||||
if (result.speed === '0.00') {
|
if (result.speed === '0.00') {
|
||||||
let current = getCpuCurrentSpeedSync();
|
let current = getCpuCurrentSpeedSync();
|
||||||
if (current !== '0.00') result.speed = current;
|
if (current !== '0.00') result.speed = current;
|
||||||
}
|
}
|
||||||
_cpu_speed = result.speed;
|
_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);
|
resolve(result);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -108,8 +163,8 @@ function getCpu() {
|
|||||||
result.speed = line.split('@')[1].trim();
|
result.speed = line.split('@')[1].trim();
|
||||||
result.speed = parseFloat(result.speed.replace(/GHz+/g, ""));
|
result.speed = parseFloat(result.speed.replace(/GHz+/g, ""));
|
||||||
_cpu_speed = result.speed;
|
_cpu_speed = result.speed;
|
||||||
|
result = cpuBrandManufacturer(result);
|
||||||
}
|
}
|
||||||
result = cpuBrandManufacturer(result);
|
|
||||||
resolve(result);
|
resolve(result);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -82,6 +82,7 @@
|
|||||||
// --------------------------------
|
// --------------------------------
|
||||||
//
|
//
|
||||||
// version date comment
|
// 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.3 2017-04-29 minor fix (blockDevices data array, Windows)
|
||||||
// 3.17.2 2017-04-24 minor fix (removed console.log)
|
// 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)
|
// 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