Skip to content

Fix: [gpu-info] The gpu info not show in special platform.#540

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/eaglefrom
GongHeng2017:202510071026-eagle-fix
Oct 9, 2025
Merged

Fix: [gpu-info] The gpu info not show in special platform.#540
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/eaglefrom
GongHeng2017:202510071026-eagle-fix

Conversation

@GongHeng2017
Copy link
Contributor

@GongHeng2017 GongHeng2017 commented Oct 7, 2025

-- adjust the code logic to get gpu info.

Log: fix issue
Bug: https://pms.uniontech.com/bug-view-333969.html

Summary by Sourcery

Fix GPU info retrieval and display by centralizing fetching logic in CommonTools and updating usage across the application

New Features:

  • Add CommonTools::preGenerateGpuInfo to fetch and cache GPU information via D-Bus and environment variables
  • Introduce CommonTools::getGpuBaseInfo to parse GPU base details from glxinfo output
  • Define GPU info key constants for Name, Vendor, Model, Version, and Graphics Memory

Bug Fixes:

  • Ensure GPU information is displayed correctly on special platforms by adjusting the code logic

Enhancements:

  • Refactor DeviceInterface::getGpuInfoByCustom to remove static caching and standardize process invocation
  • Update CustomGenerator and application main to invoke CommonTools::preGenerateGpuInfo instead of custom DBus-based calls
  • Streamline customgpuinfo main to leverage the centralized GPU info retrieval

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 7, 2025

Reviewer's Guide

Centralize and refactor GPU information retrieval by introducing a cached utility in CommonTools that leverages D-Bus or glxinfo, simplifying existing interfaces and integrating the new flow in generator and startup logic.

Sequence diagram for the new GPU info retrieval flow

sequenceDiagram
    participant App
    participant CommonTools
    participant D-Bus
    participant DeviceInfoService
    participant glxinfo

    App->>CommonTools: getGpuInfoCommandFromDConfig()
    App->>CommonTools: preGenerateGpuInfo()
    alt D-Bus available
        CommonTools->>D-Bus: getGpuInfoByCustom(arguments, gpuInfo)
        D-Bus->>DeviceInfoService: getGpuInfoByCustom(cmd, arguments)
        DeviceInfoService->>glxinfo: execute GPU info command
        glxinfo-->>DeviceInfoService: GPU info output
        DeviceInfoService-->>D-Bus: GPU info
        D-Bus-->>CommonTools: GPU info
    else D-Bus not available
        CommonTools->>glxinfo: execute glxinfo -B
        glxinfo-->>CommonTools: GPU info output
    end
    CommonTools-->>App: GPU info
Loading

Class diagram for updated CommonTools GPU info methods

classDiagram
    class CommonTools {
        +static QString getGpuInfoCommandFromDConfig()
        +static QString preGenerateGpuInfo()
        -static bool getGpuBaseInfo(QMap<QString, QString> &mapInfo)
    }
Loading

Class diagram for updated DeviceInterface GPU info method

classDiagram
    class DeviceInterface {
        +QString getGpuInfoByCustom(const QString &cmd, const QStringList &arguments)
    }
Loading

File-Level Changes

Change Details Files
Introduce GPU info constants and a cached retrieval utility in CommonTools
  • Define kName, kVendor, kModel, kVersion, kGraphicsMemory constants
  • Implement preGenerateGpuInfo with D-Bus call and fallback to glxinfo
  • Add private getGpuBaseInfo helper to parse and map glxinfo output
deepin-devicemanager/src/Tool/commontools.cpp
deepin-devicemanager/src/Tool/commontools.h
Simplify DeviceInterface::getGpuInfoByCustom by removing static cache
  • Remove firstFlag and static gpuinfo variables
  • Use a local gpuinfo variable and always wait for process completion
  • Retain environment setup and command execution logic
deepin-devicemanager-server/deepin-deviceinfo/src/loadinfo/deviceinterface.cpp
Refactor generator and main to use the new CommonTools utility
  • Replace manual DISPLAY/XAUTHORITY setup and direct D-Bus calls in CustomGenerator
  • Invoke CommonTools::preGenerateGpuInfo in main if config command is present
  • Include commontools header in main
deepin-devicemanager/src/GenerateDevice/CustomGenerator.cpp
deepin-devicemanager/src/main.cpp
Fix customgpuinfo main to use correct predicate for GPU memory info
  • Change startup condition to check getGpuMemInfoForFTDTM return value instead of getGpuBaseInfo
deepin-devicemanager-server/customgpuinfo/main.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • In preGenerateGpuInfo(), return immediately after logging if DISPLAY or XAUTHORITY is missing to avoid making a DBus call with invalid arguments.
  • Move the QRegularExpression instance outside the loop (e.g. as a static) to avoid recompiling it for every line in getGpuBaseInfo.
  • The static gpuInfo cache in preGenerateGpuInfo isn’t thread-safe—consider protecting it with a mutex or refactoring to avoid data races in multi-threaded contexts.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In preGenerateGpuInfo(), return immediately after logging if DISPLAY or XAUTHORITY is missing to avoid making a DBus call with invalid arguments.
- Move the QRegularExpression instance outside the loop (e.g. as a static) to avoid recompiling it for every line in getGpuBaseInfo.
- The static gpuInfo cache in preGenerateGpuInfo isn’t thread-safe—consider protecting it with a mutex or refactoring to avoid data races in multi-threaded contexts.

## Individual Comments

### Comment 1
<location> `deepin-devicemanager/src/Tool/commontools.cpp:269` </location>
<code_context>
     return cmd;
 }
+
+QString CommonTools::preGenerateGpuInfo()
+{
+    static QString gpuInfo { "" };
</code_context>

<issue_to_address>
**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.
</issue_to_address>

### Comment 2
<location> `deepin-devicemanager/src/Tool/commontools.cpp:278-282` </location>
<code_context>
-    QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
-    QString display = env.value("DISPLAY");
-    QString xauthority = env.value("XAUTHORITY");
-    if (display.isEmpty() || xauthority.isEmpty()) {
-        qWarning() << "DISPLAY or XAUTHORITY is not set!";
-    } else {
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Function continues execution even if DISPLAY or XAUTHORITY is missing.

Recommend returning immediately after logging the error to prevent further execution when DISPLAY or XAUTHORITY is missing.

```suggestion
        if (display.isEmpty() || xauthority.isEmpty()) {
            qCritical() << "DISPLAY or XAUTHORITY is not set!";
            return gpuInfo;
        } else {
            arguments << display << xauthority;
        }
```
</issue_to_address>

### Comment 3
<location> `deepin-devicemanager/src/Tool/commontools.cpp:289` </location>
<code_context>
+                             "org.deepin.DeviceInfo",
+                             QDBusConnection::systemBus());
+        if (iface.isValid()) {
+            QDBusReply<QString> replyList = iface.call("getGpuInfoByCustom", arguments, gpuInfo);
+            if (replyList.isValid()) {
+                gpuInfo = replyList.value();
</code_context>

<issue_to_address>
**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.
</issue_to_address>

### Comment 4
<location> `deepin-devicemanager/src/Tool/commontools.cpp:328-329` </location>
<code_context>
+        if (match.hasMatch()) {
+            QString key = match.captured(1).trimmed();
+            QString value = match.captured(2).trimmed();
+            if (key == "OpenGL renderer string") {
+                mapInfo.insert(kName, value);
+                mapInfo.insert(kModel, value);
+            } else if (key == "OpenGL vendor string") {
</code_context>

<issue_to_address>
**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:

```cpp
            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 `kName`, you could use a default value or combine vendor and renderer strings after parsing both. For now, this change ensures that `kModel` is set to the renderer string, which is typically more appropriate.
</issue_to_address>

### Comment 5
<location> `deepin-devicemanager-server/customgpuinfo/main.cpp:101-102` </location>
<code_context>
 int main(int argc, char *argv[])
 {
     QMap<QString, QString> mapInfo;
-    if (getGpuBaseInfo(mapInfo)) {
-        getGpuMemInfoForFTDTM(mapInfo);
+    if (getGpuMemInfoForFTDTM(mapInfo)) {
         for (auto it = mapInfo.begin(); it != mapInfo.end(); ++it)
</code_context>

<issue_to_address>
**suggestion:** getGpuMemInfoForFTDTM return value is now used for conditional logic.

Please verify that error handling and fallback logic remain correct if getGpuMemInfoForFTDTM fails.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

return cmd;
}

QString CommonTools::preGenerateGpuInfo()
Copy link

Choose a reason for hiding this comment

The 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.

"org.deepin.DeviceInfo",
QDBusConnection::systemBus());
if (iface.isValid()) {
QDBusReply<QString> replyList = iface.call("getGpuInfoByCustom", arguments, gpuInfo);
Copy link

Choose a reason for hiding this comment

The 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.

Comment on lines +328 to +329
if (key == "OpenGL renderer string") {
mapInfo.insert(kName, value);
Copy link

Choose a reason for hiding this comment

The 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 kName, you could use a default value or combine vendor and renderer strings after parsing both. For now, this change ensures that kModel is set to the renderer string, which is typically more appropriate.

Comment on lines -101 to -102
if (getGpuBaseInfo(mapInfo)) {
getGpuMemInfoForFTDTM(mapInfo);
Copy link

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.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: GongHeng2017, max-lvs

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@GongHeng2017
Copy link
Contributor Author

/forcemege

@GongHeng2017
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Oct 9, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 85e94c5 into linuxdeepin:develop/eagle Oct 9, 2025
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants