Skip to content

fix: [memory] Memory show error in special platform.#512

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
GongHeng2017:202508111630-eagle-fixMem
Aug 12, 2025
Merged

fix: [memory] Memory show error in special platform.#512
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
GongHeng2017:202508111630-eagle-fixMem

Conversation

@GongHeng2017
Copy link
Copy Markdown
Contributor

@GongHeng2017 GongHeng2017 commented Aug 12, 2025

-- Change the right way to get memory.

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

Summary by Sourcery

Fix GPU memory info retrieval by using the correct debug file path and simplifying the parsing logic

Bug Fixes:

  • Switch memory source file from "/sys/kernel/debug/gc/meminfo" to "/sys/kernel/debug/gc/total_mem"
  • Update error messages to reference the new file path

Enhancements:

  • Replace multi-step regex extraction with a single pattern to capture memory value and unit
  • Normalize all memory units to gigabytes with two-decimal formatting before inserting into map

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

关键摘要:

  • 文件路径已更改,需要确认新路径/sys/kernel/debug/gc/total_mem是否正确且文件存在。
  • 删除了不必要的变量和逻辑,简化了代码结构。
  • 正则表达式已更新,以匹配内存信息并提取数值和单位。
  • 代码中添加了对单位转换的逻辑,确保内存大小以GB为单位返回。

是否建议立即修改:

  • 是,需要验证新文件路径的正确性,并确保代码在所有可能的内存单位情况下都能正确工作。

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Aug 12, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates GPU memory retrieval to use the /sys/kernel/debug/gc/total_mem file, replaces the previous SYSTEM0-specific parsing with a single generic regex that captures the numeric value and unit, and refactors unit conversion logic to consistently output GB.

Class diagram for updated GPU memory retrieval logic

classDiagram
    class main {
    }
    class getGpuMemInfoForFTDTM {
        +bool getGpuMemInfoForFTDTM(QMap<QString, QString> &mapInfo)
    }
    main --> getGpuMemInfoForFTDTM
    getGpuMemInfoForFTDTM : -const QString filePath
    getGpuMemInfoForFTDTM : -QString totalValue
    getGpuMemInfoForFTDTM : +QFile file
    getGpuMemInfoForFTDTM : +QRegularExpression regex
    getGpuMemInfoForFTDTM : +QRegularExpressionMatch memInfoMatch
    getGpuMemInfoForFTDTM : +double value
    getGpuMemInfoForFTDTM : +QString unit
    getGpuMemInfoForFTDTM : +mapInfo.insert(kGraphicsMemory, totalValue)
Loading

Flow diagram for new GPU memory info extraction and conversion

flowchart TD
    A[Open /sys/kernel/debug/gc/total_mem] -->|Success| B[Read file content]
    B --> C[Apply regex to extract value and unit]
    C --> D{Unit type}
    D -->|MB| E[Convert value to GB]
    D -->|GB| F[Use value as GB]
    D -->|KB| G[Convert value to GB]
    D -->|B| H[Convert value to GB]
    E --> I[Insert into mapInfo]
    F --> I
    G --> I
    H --> I
    D -->|No match| J[Log error and return false]
Loading

File-Level Changes

Change Details Files
Switch memory info source to total_mem
  • Updated filePath constant from meminfo to total_mem
  • Adjusted error log messages to reference total_mem
deepin-devicemanager-server/customgpuinfo/main.cpp
Simplify memory info extraction with generic regex
  • Removed SYSTEM0/VIRTUAL section matching
  • Introduced a single regex to capture numeric value and unit
deepin-devicemanager-server/customgpuinfo/main.cpp
Refactor unit conversion logic
  • Parsed captured value and unit instead of manual scanning
  • Converted MB, GB, KB, B to GB with formatted string
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
Copy Markdown

@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 @GongHeng2017 - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `deepin-devicemanager-server/customgpuinfo/main.cpp:80` </location>
<code_context>
-        } else {
-            totalValue = QString::number(memSize) + "MB";
-        }
+    double value = memInfoMatch.captured(1).toDouble();
+    QString unit = memInfoMatch.captured(2).toUpper();
+
+    if (unit == "MB") {
</code_context>

<issue_to_address>
Consider validating the conversion result of toDouble for robustness.

Using the overload with a bool allows you to detect conversion failures and handle them appropriately, improving error handling.
</issue_to_address>

### Comment 2
<location> `deepin-devicemanager-server/customgpuinfo/main.cpp:93` </location>
<code_context>
+        totalValue = QString("%1GB").arg(value / (1024.0 * 1024.0 * 1024.0), 0, 'f', 2);
     }

     mapInfo.insert(kGraphicsMemory, totalValue);
</code_context>

<issue_to_address>
totalValue may be empty if the unit is not recognized.

If the unit is not MB, GB, KB, or B, totalValue will be empty and mapInfo will contain an empty string. Add an else branch to handle unknown units and log a warning.
</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.

Comment thread deepin-devicemanager-server/customgpuinfo/main.cpp
Comment thread deepin-devicemanager-server/customgpuinfo/main.cpp
Comment thread deepin-devicemanager-server/customgpuinfo/main.cpp
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, 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
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot
Copy link
Copy Markdown
Contributor

deepin-bot Bot commented Aug 12, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot Bot merged commit 41df0c9 into linuxdeepin:develop/eagle Aug 12, 2025
15 of 17 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.

4 participants