cpuCurrentSpeed() deno compatibility
This commit is contained in:
parent
34dd408e54
commit
eb57e2fae4
25
lib/cpu.js
25
lib/cpu.js
@ -995,16 +995,25 @@ function getCpuCurrentSpeedSync() {
|
||||
let maxFreq = 0;
|
||||
let avgFreq = 0;
|
||||
let cores = [];
|
||||
let speeds = [];
|
||||
|
||||
if (cpus && cpus.length) {
|
||||
if (cpus && cpus.length && cpus[0].speed) {
|
||||
for (let i in cpus) {
|
||||
if ({}.hasOwnProperty.call(cpus, i)) {
|
||||
let freq = cpus[i].speed > 100 ? (cpus[i].speed + 1) / 1000 : cpus[i].speed / 10;
|
||||
avgFreq = avgFreq + freq;
|
||||
if (freq > maxFreq) { maxFreq = freq; }
|
||||
if (freq < minFreq) { minFreq = freq; }
|
||||
cores.push(parseFloat(freq.toFixed(2)));
|
||||
}
|
||||
speeds.push(cpus[i].speed > 100 ? (cpus[i].speed + 1) / 1000 : cpus[i].speed / 10);
|
||||
}
|
||||
} else {
|
||||
speedStrings = execSync('cat /proc/cpuinfo | grep "cpu MHz" | cut -d " " -f 3', util.execOptsLinux).toString().split('\n');
|
||||
for (let i in speedStrings) {
|
||||
speeds.push(parseInt(speedStrings, 10));
|
||||
}
|
||||
}
|
||||
|
||||
if (speeds && speeds.length) {
|
||||
for (let i in speeds) {
|
||||
avgFreq = avgFreq + speeds[i];
|
||||
if (speeds[i] > maxFreq) { maxFreq = speeds[i]; }
|
||||
if (speeds[i] < minFreq) { minFreq = speeds[i]; }
|
||||
cores.push(parseFloat(speeds[i].toFixed(2)));
|
||||
}
|
||||
avgFreq = avgFreq / cpus.length;
|
||||
return {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user