-
Notifications
You must be signed in to change notification settings - Fork 40
Fix: [gpu-info] The gpu info not show in special platform. #540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,14 @@ using namespace DDLog; | |
| #define ICON_SIZE_WIDTH 36 | ||
| #define ICON_SIZE_HEIGHT 36 | ||
|
|
||
| // 名称("Name") 厂商("Vendor") 型号("Model") 版本(Version) 显存("Graphics Memory") | ||
|
|
||
| constexpr char kName[] { "Name" }; | ||
| constexpr char kVendor[] { "Vendor" }; | ||
| constexpr char kModel[] { "Model" }; | ||
| constexpr char kVersion[] { "Version" }; | ||
| constexpr char kGraphicsMemory[] { "Graphics Memory" }; | ||
|
|
||
| QMap<DriverType, QString> CommonTools::m_MapDriverIcon = { | ||
| {DR_Bluetooth, QString(":/icons/deepin/builtin/icons/bluetooth.svg")} | ||
| , {DR_Camera, QString(":/icons/deepin/builtin/icons/image.svg")} | ||
|
|
@@ -257,3 +265,74 @@ QString CommonTools::getGpuInfoCommandFromDConfig() | |
| cmd = dconfig->value("CommandToGetGPUInfo").toString(); | ||
| return cmd; | ||
| } | ||
|
|
||
| QString CommonTools::preGenerateGpuInfo() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Static caching of GPU info may cause stale data if environment changes. Caching with a static QString prevents updates if DISPLAY or XAUTHORITY change. Please review if caching is required, or implement invalidation when these environment variables are modified. |
||
| { | ||
| static QString gpuInfo { "" }; | ||
|
|
||
| if (gpuInfo.isEmpty()) { | ||
| QStringList arguments; | ||
| QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); | ||
| QString display = env.value("DISPLAY"); | ||
| QString xauthority = env.value("XAUTHORITY"); | ||
| if (display.isEmpty() || xauthority.isEmpty()) { | ||
| qCritical() << "DISPLAY or XAUTHORITY is not set!"; | ||
| } else { | ||
| arguments << display << xauthority; | ||
| } | ||
|
|
||
| QDBusInterface iface("org.deepin.DeviceInfo", | ||
| "/org/deepin/DeviceInfo", | ||
| "org.deepin.DeviceInfo", | ||
| QDBusConnection::systemBus()); | ||
| if (iface.isValid()) { | ||
| QDBusReply<QString> replyList = iface.call("getGpuInfoByCustom", arguments, gpuInfo); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Passing gpuInfo as an argument to DBus call may be unnecessary. Please verify whether gpuInfo should be passed as an input to the DBus method, as it seems to be intended as an output parameter. |
||
| if (replyList.isValid()) { | ||
| gpuInfo = replyList.value(); | ||
| } else { | ||
| qCritical() << "Error: failed to call dbus to get gpu memery info! "; | ||
| } | ||
| } | ||
|
|
||
| QMap<QString, QString> mapInfo; | ||
| if (getGpuBaseInfo(mapInfo)) { | ||
| for (auto it = mapInfo.begin(); it != mapInfo.end(); ++it) { | ||
| QString tmpInfo = it.key() + ": " + it.value() + "\n"; | ||
| gpuInfo.append(tmpInfo); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return gpuInfo; | ||
| } | ||
|
|
||
| bool CommonTools::getGpuBaseInfo(QMap<QString, QString> &mapInfo) | ||
| { | ||
| QProcess process; | ||
| QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); | ||
| process.setProcessEnvironment(env); | ||
| process.start("/usr/bin/glxinfo", QStringList() << "-B"); | ||
| if (!process.waitForFinished()) { | ||
| qCritical() << "Error executing glxinfo:" << process.errorString(); | ||
| return false; | ||
| } | ||
|
|
||
| QString output = QString::fromLocal8Bit(process.readAllStandardOutput()); | ||
| QStringList lines = output.split('\n'); | ||
| QRegularExpression regex("^([^:]+):\\s*(.+)$"); | ||
| for (const QString &line : lines) { | ||
| QRegularExpressionMatch match = regex.match(line); | ||
| if (match.hasMatch()) { | ||
| QString key = match.captured(1).trimmed(); | ||
| QString value = match.captured(2).trimmed(); | ||
| if (key == "OpenGL renderer string") { | ||
| mapInfo.insert(kName, value); | ||
|
Comment on lines
+328
to
+329
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Assigning both kName and kModel to the same value may reduce clarity. Verify that assigning the same value to both fields matches their intended use and does not cause confusion for downstream consumers. Suggested implementation: if (key == "OpenGL renderer string") {
// Assign renderer string to kModel, not kName, for clarity
mapInfo.insert(kModel, value);
} else if (key == "OpenGL vendor string") {
If you want to provide a more descriptive name for |
||
| mapInfo.insert(kModel, value); | ||
| } else if (key == "OpenGL vendor string") { | ||
| mapInfo.insert(kVendor, value); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: getGpuMemInfoForFTDTM return value is now used for conditional logic.
Please verify that error handling and fallback logic remain correct if getGpuMemInfoForFTDTM fails.