getCpu() fix physicalCores
This commit is contained in:
parent
e9fedd4d5b
commit
6821fc4374
56
lib/cpu.js
56
lib/cpu.js
@ -321,6 +321,13 @@ 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); }
|
||||
|
||||
const threadsPerCore = util.getValue(lines, 'thread(s) per core') || '1';
|
||||
const processors = util.getValue(lines, 'socket(s)') || '1';
|
||||
let threadsPerCoreInt = parseInt(threadsPerCore, 10);
|
||||
let processorsInt = parseInt(processors, 10);
|
||||
result.physicalCores = result.cores / threadsPerCoreInt;
|
||||
result.processors = processorsInt;
|
||||
|
||||
// socket type
|
||||
let lines2 = [];
|
||||
exec('export LC_ALL=C; dmidecode –t 4 2>/dev/null | grep "Upgrade: Socket"; unset LC_ALL', function (error2, stdout2) {
|
||||
@ -328,31 +335,32 @@ function getCpu() {
|
||||
if (lines2 && lines2.length) {
|
||||
result.socket = util.getValue(lines2, 'Upgrade').replace('Socket', '').trim();
|
||||
}
|
||||
resolve(result);
|
||||
|
||||
// # processurs & # threads/core - method 1
|
||||
let threadsPerCoreInt = 0;
|
||||
let lines3 = [];
|
||||
exec('cat /proc/cpuinfo | grep -E "physical id|core id"', function (error2, stdout3) {
|
||||
lines3 = stdout3.toString().split('\n');
|
||||
if (lines3 && lines3.length) {
|
||||
result.processors = util.countUniqueLines(lines3, 'physical id') || 1;
|
||||
result.physicalCores = util.countUniqueLines(lines3, '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);
|
||||
});
|
||||
// // # processurs & # threads/core - method 1
|
||||
// let threadsPerCoreInt = 0;
|
||||
// let lines3 = [];
|
||||
// exec('cat /proc/cpuinfo | grep -E "physical id|core id"', function (error2, stdout3) {
|
||||
// lines3 = stdout3.toString().split('\n');
|
||||
// if (lines3 && lines3.length) {
|
||||
// result.processors = util.countUniqueLines(lines3, 'physical id') || 1;
|
||||
// result.physicalCores = util.countLinesStartingWith(lines3, '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);
|
||||
// });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ function parseDateTime(dt) {
|
||||
// Dateformat: mm/dd/yyyy
|
||||
result.date = dtparts[2] + '-' + ('0' + dtparts[0]).substr(-2) + '-' + ('0' + dtparts[1]).substr(-2);
|
||||
} else {
|
||||
// Dateformat: dd/mm/yyyy
|
||||
// Dateformat: dd/mm/yyyy
|
||||
result.date = dtparts[2] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[0]).substr(-2);
|
||||
}
|
||||
}
|
||||
@ -454,6 +454,12 @@ function countUniqueLines(lines, startingWith) {
|
||||
});
|
||||
return uniqueLines.length;
|
||||
}
|
||||
|
||||
// function countLinesStartingWith(lines, startingWith) {
|
||||
// startingWith = startingWith || '';
|
||||
// return lines.filter(el => el.startsWith(startingWith)).length;
|
||||
// }
|
||||
|
||||
function noop() { }
|
||||
|
||||
exports.toInt = toInt;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user