cpu() Apple Silicon M1 frequency

This commit is contained in:
Sebastian Hildebrandt 2020-12-17 22:37:25 +01:00
parent a465449fa4
commit a23eeabc9c

View File

@ -418,13 +418,13 @@ function getCpu() {
result.speed = modellineParts[1] ? modellineParts[1].trim() : '0';
result.speed = parseFloat(result.speed.replace(/GHz+/g, '')).toFixed(2);
let tbFrequency = util.getValue(lines, 'hw.tbfrequency') / 1000000000.0;
tbFrequency = tbFrequency < 1 ? tbFrequency * 1000 : tbFrequency;
tbFrequency = tbFrequency < 0.1 ? tbFrequency * 100 : tbFrequency;
result.speed = result.speed === '0.00' ? tbFrequency.toFixed(2) : result.speed;
_cpu_speed = result.speed;
result = cpuBrandManufacturer(result);
result.speedmin = (util.getValue(lines, 'hw.cpufrequency_min') / 1000000000.0).toFixed(2);
result.speedmax = (util.getValue(lines, 'hw.cpufrequency_max') / 1000000000.0).toFixed(2);
result.speedmin = (util.getValue(lines, 'hw.cpufrequency_min') / 1000000000.0).toFixed(2) || result.speed;
result.speedmax = (util.getValue(lines, 'hw.cpufrequency_max') / 1000000000.0).toFixed(2) || result.speed;
result.vendor = util.getValue(lines, 'machdep.cpu.vendor');
result.family = util.getValue(lines, 'machdep.cpu.family');
result.model = util.getValue(lines, 'machdep.cpu.model');
@ -432,7 +432,7 @@ function getCpu() {
const countProcessors = util.getValue(lines, 'hw.packages');
const countCores = util.getValue(lines, 'hw.physicalcpu_max');
const countThreads = util.getValue(lines, 'hw.ncpu');
if (os.arch === 'arm64') {
if (os.arch() === 'arm64') {
const clusters = execSync('ioreg -c IOPlatformDevice -d 3 -r | grep cluster-type').toString().split('\n');
const efficiencyCores = clusters.filter(line => line.indexOf('"E"') >= 0).length;
const performanceCores = clusters.filter(line => line.indexOf('"P"') >= 0).length;
@ -726,18 +726,19 @@ function getCpuCurrentSpeedSync() {
if (cpus && cpus.length) {
for (let i in cpus) {
if ({}.hasOwnProperty.call(cpus, i)) {
avgFreq = avgFreq + cpus[i].speed;
if (cpus[i].speed > maxFreq) maxFreq = cpus[i].speed;
if (cpus[i].speed < minFreq) minFreq = cpus[i].speed;
let freq = (cpus[i].speed + 1) / 1000;
freq = freq < 0.1 ? freq * 100 : freq;
avgFreq = avgFreq + freq;
if (freq > maxFreq) maxFreq = freq;
if (freq < minFreq) minFreq = freq;
cores.push(parseFloat(freq.toFixed(2)));
}
const freq = (cpus[i].speed + 1) / 1000;
cores.push(parseFloat((freq < 0.1 ? freq * 1000 : freq).toFixed(2)));
}
avgFreq = avgFreq / cpus.length;
return {
min: parseFloat(((minFreq + 1) / 1000).toFixed(2)),
max: parseFloat(((maxFreq + 1) / 1000).toFixed(2)),
avg: parseFloat(((avgFreq + 1) / 1000).toFixed(2)),
min: parseFloat(minFreq.toFixed(2)),
max: parseFloat(maxFreq.toFixed(2)),
avg: parseFloat((avgFreq).toFixed(2)),
cores: cores
};
} else {