Skip to content

fix(gpu): fix GPU VRAM size parsing failure on multi-line gpu-info - #719

Open
add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:fix-372403-fix-gpu-vram-parsing
Open

fix(gpu): fix GPU VRAM size parsing failure on multi-line gpu-info#719
add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:fix-372403-fix-gpu-vram-parsing

Conversation

@add-uos

@add-uos add-uos commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Split gpu-info by single "\n" and parse each line separately instead of splitting the whole content by "\n\n" and ":" on the entire string.

修复多行gpu-info文件显存大小解析失败的问题,改为逐行分割解析。

Log: 修复显存大小解析失败问题
PMS: BUG-372403
Influence: 修复后含多行的gpu-info文件能正确解析显存大小并显示。

Summary by Sourcery

Fix GPU VRAM size parsing from multi-line gpu-info files by parsing each line separately.

Bug Fixes:

  • Correct gpu-info parsing logic so VRAM size is properly extracted when the file contains multiple lines.

Enhancements:

  • Update SPDX copyright header years for DeviceGpu.cpp.

Split gpu-info by single "\n" and parse each line separately instead
of splitting the whole content by "\n\n" and ":" on the entire string.

修复多行gpu-info文件显存大小解析失败的问题,改为逐行分割解析。

Log: 修复显存大小解析失败问题
PMS: BUG-372403
Influence: 修复后含多行的gpu-info文件能正确解析显存大小并显示。

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @add-uos, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@sourcery-ai

sourcery-ai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts GPU VRAM size parsing logic to correctly handle multi-line gpu-info files and updates the SPDX copyright year range.

Flow diagram for updated gpu-info VRAM parsing logic

graph TD
    A[DeviceGpu::setHwinfoInfo] --> B[QFile::open QIODevice::ReadOnly]
    B --> C[QFile::readAll]
    C --> D[QString::split '\n']
    D --> E[iterate each item]
    E --> F{item.isEmpty}
    F -- yes --> E
    F -- no --> G[QString::split ':' QT_SKIP_EMPTY_PARTS]
    G --> H{tmpItems.size == 2}
    H -- no --> E
    H -- yes --> I[parse VRAM size from tmpItems]
Loading

File-Level Changes

Change Details Files
Fix GPU VRAM size parsing by switching from whole-file splitting to per-line parsing of gpu-info content.
  • Change gpu-info content splitting from double-newline ('\n\n') to single-newline ('\n') so each line is processed independently.
  • For each non-empty line, split that line on ':' with QT_SKIP_EMPTY_PARTS to extract key/value pairs, instead of splitting the entire file content.
  • Retain the skip logic for empty or incorrectly formatted lines to avoid invalid entries in the parsed result.
deepin-devicemanager/src/DeviceManager/DeviceGpu.cpp
Update SPDX copyright header year range.
  • Extend the SPDX-FileCopyrightText year range from '2022' to '2022 - 2026' in the DeviceGpu source file.
deepin-devicemanager/src/DeviceManager/DeviceGpu.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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码修复了GPU信息解析中变量误用导致的逻辑错误,提升了解析的准确性
逻辑修复完全正确且无安全漏洞,仅因修改范围较小未达满分

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

DeviceGpu::setHwinfoInfo 函数中,原代码在 foreach 循环内错误地对外层变量 allStr 进行 split 操作,导致无法正确解析单行键值对。修复后改为对当前遍历的 item 进行 split(":"),同时将行分隔符从 \n\n 调整为 \n,逻辑完全符合预期。
潜在问题:无
建议:无

  • 2.代码质量(良好)✓

修复了明显的变量引用错误,代码逻辑更加清晰。保留了原有的空行跳过和长度校验逻辑,符合编码规范。
潜在问题:无
建议:无

  • 3.代码性能(无性能问题)✓

修复前在循环内反复对整个文件内容字符串 allStr 进行切分,存在不必要的性能损耗。修复后仅对当前 item 进行切分,消除了冗余计算,性能表现良好。
潜在问题:无
建议:无

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次修改仅涉及字符串解析逻辑的修正,未引入任何外部输入处理、文件操作或网络通信的安全风险,不存在攻击面。

  • 建议:无

■ 【改进建议代码示例】

// 当前代码已修复核心问题,无需进一步修改。以下为完整上下文展示:
if (file.open(QIODevice::ReadOnly)) {
    qCDebug(appLog) << "gpu-info file opened successfully.";
    QString allStr(file.readAll());
    QStringList items = allStr.split("\n");
    file.close();
    foreach (const QString &item, items) {
        if (item.isEmpty()) {
            continue;
        }
        QStringList tmpItems = item.split(":", QT_SKIP_EMPTY_PARTS);
        if (tmpItems.size() != 2) {
            continue;
        }
        // 后续处理逻辑...
    }
}

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, lzwind

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

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