fix: cpu temperature AMD
This commit is contained in:
parent
61608655a7
commit
8bcc01bc51
35
lib/cpu.js
35
lib/cpu.js
@ -1181,13 +1181,13 @@ function cpuTemperature(callback) {
|
|||||||
const cmd =
|
const cmd =
|
||||||
'for mon in /sys/class/hwmon/hwmon*; do for label in "$mon"/temp*_label; do if [ -f $label ]; then value=${label%_*}_input; echo $(cat "$label")___$(cat "$value"); fi; done; done;';
|
'for mon in /sys/class/hwmon/hwmon*; do for label in "$mon"/temp*_label; do if [ -f $label ]; then value=${label%_*}_input; echo $(cat "$label")___$(cat "$value"); fi; done; done;';
|
||||||
try {
|
try {
|
||||||
exec(cmd, function (error, stdout) {
|
exec(cmd, (error, stdout) => {
|
||||||
stdout = stdout.toString();
|
stdout = stdout.toString();
|
||||||
const tdiePos = stdout.toLowerCase().indexOf('tdie');
|
const tdiePos = stdout.toLowerCase().indexOf('tdie');
|
||||||
if (tdiePos !== -1) {
|
if (tdiePos !== -1) {
|
||||||
stdout = stdout.substring(tdiePos);
|
stdout = stdout.substring(tdiePos);
|
||||||
}
|
}
|
||||||
let lines = stdout.split('\n');
|
const lines = stdout.split('\n');
|
||||||
let tctl = 0;
|
let tctl = 0;
|
||||||
lines.forEach((line) => {
|
lines.forEach((line) => {
|
||||||
const parts = line.split('___');
|
const parts = line.split('___');
|
||||||
@ -1223,13 +1223,13 @@ function cpuTemperature(callback) {
|
|||||||
resolve(result);
|
resolve(result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
exec('sensors', function (error, stdout) {
|
exec('sensors', (error, stdout) => {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
let lines = stdout.toString().split('\n');
|
const lines = stdout.toString().split('\n');
|
||||||
let tdieTemp = null;
|
let tdieTemp = null;
|
||||||
let newSectionStarts = true;
|
let newSectionStarts = true;
|
||||||
let section = '';
|
let section = '';
|
||||||
lines.forEach(function (line) {
|
lines.forEach((line) => {
|
||||||
// determine section
|
// determine section
|
||||||
if (line.trim() === '') {
|
if (line.trim() === '') {
|
||||||
newSectionStarts = true;
|
newSectionStarts = true;
|
||||||
@ -1243,11 +1243,14 @@ function cpuTemperature(callback) {
|
|||||||
if (line.trim().toLowerCase().startsWith('core')) {
|
if (line.trim().toLowerCase().startsWith('core')) {
|
||||||
section = 'core';
|
section = 'core';
|
||||||
}
|
}
|
||||||
|
if (line.trim().toLowerCase().startsWith('k10temp')) {
|
||||||
|
section = 'coreAMD';
|
||||||
|
}
|
||||||
newSectionStarts = false;
|
newSectionStarts = false;
|
||||||
}
|
}
|
||||||
let regex = /[+-]([^°]*)/g;
|
const regex = /[+-]([^°]*)/g;
|
||||||
let temps = line.match(regex);
|
const temps = line.match(regex);
|
||||||
let firstPart = line.split(':')[0].toUpperCase();
|
const firstPart = line.split(':')[0].toUpperCase();
|
||||||
if (section === 'acpi') {
|
if (section === 'acpi') {
|
||||||
// socket temp
|
// socket temp
|
||||||
if (firstPart.indexOf('TEMP') !== -1) {
|
if (firstPart.indexOf('TEMP') !== -1) {
|
||||||
@ -1260,7 +1263,7 @@ function cpuTemperature(callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// cpu temp
|
// cpu temp
|
||||||
if (firstPart.indexOf('PHYSICAL') !== -1 || firstPart.indexOf('PACKAGE') !== -1) {
|
if (firstPart.indexOf('PHYSICAL') !== -1 || firstPart.indexOf('PACKAGE') !== -1 || (section === 'coreAMD' && firstPart.indexOf('TDIE') !== -1) || firstPart.indexOf('TEMP') !== -1) {
|
||||||
result.main = parseFloat(temps);
|
result.main = parseFloat(temps);
|
||||||
}
|
}
|
||||||
if (firstPart.indexOf('CORE ') !== -1) {
|
if (firstPart.indexOf('CORE ') !== -1) {
|
||||||
@ -1288,11 +1291,11 @@ function cpuTemperature(callback) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fs.stat('/sys/class/thermal/thermal_zone0/temp', function (err) {
|
fs.stat('/sys/class/thermal/thermal_zone0/temp', (err) => {
|
||||||
if (err === null) {
|
if (err === null) {
|
||||||
fs.readFile('/sys/class/thermal/thermal_zone0/temp', function (error, stdout) {
|
fs.readFile('/sys/class/thermal/thermal_zone0/temp', (error, stdout) => {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
let lines = stdout.toString().split('\n');
|
const lines = stdout.toString().split('\n');
|
||||||
if (lines.length > 0) {
|
if (lines.length > 0) {
|
||||||
result.main = parseFloat(lines[0]) / 1000.0;
|
result.main = parseFloat(lines[0]) / 1000.0;
|
||||||
result.max = result.main;
|
result.max = result.main;
|
||||||
@ -1304,9 +1307,9 @@ function cpuTemperature(callback) {
|
|||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
exec('/opt/vc/bin/vcgencmd measure_temp', function (error, stdout) {
|
exec('/opt/vc/bin/vcgencmd measure_temp', (error, stdout) => {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
let lines = stdout.toString().split('\n');
|
const lines = stdout.toString().split('\n');
|
||||||
if (lines.length > 0 && lines[0].indexOf('=')) {
|
if (lines.length > 0 && lines[0].indexOf('=')) {
|
||||||
result.main = parseFloat(lines[0].split('=')[1]);
|
result.main = parseFloat(lines[0].split('=')[1]);
|
||||||
result.max = result.main;
|
result.max = result.main;
|
||||||
@ -1329,11 +1332,11 @@ function cpuTemperature(callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_freebsd || _openbsd || _netbsd) {
|
if (_freebsd || _openbsd || _netbsd) {
|
||||||
exec('sysctl dev.cpu | grep temp', function (error, stdout) {
|
exec('sysctl dev.cpu | grep temp', (error, stdout) => {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
let lines = stdout.toString().split('\n');
|
let lines = stdout.toString().split('\n');
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
lines.forEach(function (line) {
|
lines.forEach((line) => {
|
||||||
const parts = line.split(':');
|
const parts = line.split(':');
|
||||||
if (parts.length > 1) {
|
if (parts.length > 1) {
|
||||||
const temp = parseFloat(parts[1].replace(',', '.'));
|
const temp = parseFloat(parts[1].replace(',', '.'));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user