feat: Intel核显回退数据源,支持温度和共享内存显示
Intel 核显无 hwmon/gpu_busy_percent/mem_info_vram 等 sysfs 接口, 增加回退逻辑: - 温度:扫描 thermal_zone 匹配 B0D4(Intel GPU ACPI 标识) - 显存:读取 /proc/meminfo 获取系统共享内存总量和已用量 - GPU 使用率:Skylake i915 不支持,仍显示占位符
This commit is contained in:
@@ -395,6 +395,52 @@ void GraphicsDriverApplet::readGpuStats()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- 以下为 Intel 核显等无 hwmon/vram sysfs 接口时的回退逻辑 ---
|
||||
|
||||
// 温度回退:扫描 thermal_zone,匹配 Intel GPU 的 ACPI 标识 (B0D4)
|
||||
// B0D4 是 Intel GPU 在 ACPI 规范中的标准热区标识
|
||||
if (gpu.temperature < 0) {
|
||||
QDir thermalDir("/sys/class/thermal");
|
||||
QStringList zones = thermalDir.entryList(QStringList() << "thermal_zone*", QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
for (const QString &zone : zones) {
|
||||
QFile typeFile(thermalDir.absoluteFilePath(zone + "/type"));
|
||||
if (typeFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QString type = QTextStream(&typeFile).readAll().trimmed();
|
||||
if (type == "B0D4") {
|
||||
QFile tempFile(thermalDir.absoluteFilePath(zone + "/temp"));
|
||||
if (tempFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
int tempMilli = QTextStream(&tempFile).readAll().trimmed().toInt();
|
||||
gpu.temperature = tempMilli / 1000;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 显存回退:Intel 核显使用共享系统内存,读取 /proc/meminfo 作为参考
|
||||
// 注意:这是系统内存使用量,非核显独占,仅作参考
|
||||
if (gpu.memTotal < 0) {
|
||||
QFile meminfo("/proc/meminfo");
|
||||
if (meminfo.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QString content = QTextStream(&meminfo).readAll();
|
||||
QRegularExpression totalRe("MemTotal:\\s*(\\d+)\\s*kB");
|
||||
QRegularExpression availRe("MemAvailable:\\s*(\\d+)\\s*kB");
|
||||
auto totalMatch = totalRe.match(content);
|
||||
auto availMatch = availRe.match(content);
|
||||
if (totalMatch.hasMatch()) {
|
||||
gpu.memTotal = totalMatch.captured(1).toLongLong() / 1024; // kB -> MB
|
||||
}
|
||||
if (availMatch.hasMatch() && gpu.memTotal > 0) {
|
||||
qint64 availMB = availMatch.captured(1).toLongLong() / 1024;
|
||||
gpu.memUsed = gpu.memTotal - availMB;
|
||||
if (gpu.memUsed >= 0) {
|
||||
gpu.memUsage = gpu.memUsed * 100 / gpu.memTotal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 生成统计数据 (格式: temp|gpuUsage|memUsage|memUsed|memTotal)
|
||||
|
||||
Reference in New Issue
Block a user