Skip to content

fix: 支持通过 Video RAM 匹配定制显存大小#686

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
Resurgamz:develop/eagle
Jun 16, 2026
Merged

fix: 支持通过 Video RAM 匹配定制显存大小#686
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
Resurgamz:develop/eagle

Conversation

@Resurgamz

@Resurgamz Resurgamz commented Jun 16, 2026

Copy link
Copy Markdown

Log: 通过 specialVRAMType 配置启用定制显存解析逻辑,匹配 dmesg 中的 Video RAM
字段并提取显存大小;Video RAM 与数值之间不再限制必须使用冒号分隔,兼容 Video RAM: 2048M、Video RAM
2048M 等格式。
Task: https://pms.uniontech.com/task-view-391143.html

Summary by Sourcery

Add configurable handling for parsing custom Video RAM formats from dmesg and integrate a new VRAM type flag into the device manager configuration.

New Features:

  • Introduce a configurable special VRAM type to enable custom Video RAM parsing logic based on dmesg output.

Bug Fixes:

  • Correct Video RAM size detection by supporting dmesg lines where the value is not strictly separated by a colon, e.g. 'Video RAM 2048M'.

Enhancements:

  • Update device manager startup to load the special VRAM type from configuration and use it when computing GPU memory size.

@sourcery-ai

sourcery-ai Bot commented Jun 16, 2026

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

Reviewer's Guide

Adds a configurable special VRAM parsing path that reads a new specialVRAMType config and, when enabled, extracts video memory size from dmesg lines containing "Video RAM" with more flexible formatting, wiring this through a new Common::SpecialVRAMType enum and static state.

Sequence diagram for specialVRAMType configuration and Video RAM parsing

sequenceDiagram
    participant Main
    participant DConfig
    participant Common
    participant CmdTool

    Main->>DConfig: value(specialVRAMType)
    DConfig-->>Main: int
    Main->>Common: set curVRAMType

    Main->>CmdTool: loadDmesgInfo(debugfile)
    loop each dmesg line
        CmdTool->>Common: read curVRAMType
        alt [curVRAMType == kSpecialVRAMType1]
            CmdTool->>CmdTool: regCustom.exactMatch(line)
            alt [matched Video RAM]
                CmdTool->>CmdTool: regCustom.cap(1).toDouble()
                CmdTool->>CmdTool: mapInfo["Size"] = "null=" + sizeS
            end
        else [other VRAM types]
            CmdTool->>CmdTool: existing VRAM regex handling
        end
    end
Loading

File-Level Changes

Change Details Files
Introduce configurable special VRAM type and store current value in Common
  • Add SpecialVRAMType enum with unknown and special type values
  • Declare static curVRAMType in Common alongside existing specialComType and curCpuType
  • Define and initialize curVRAMType to the unknown VRAM type in commonfunction.cpp
deepin-devicemanager/src/commonfunction.h
deepin-devicemanager/src/commonfunction.cpp
Read specialVRAMType from configuration at startup
  • On application startup, check dconfig for specialVRAMType key
  • Cast the configured integer to Common::SpecialVRAMType and assign to Common::curVRAMType
deepin-devicemanager/src/main.cpp
Add special VRAM parsing logic for dmesg Video RAM lines
  • When curVRAMType is the special type, apply a regex to match lines containing "Video RAM" followed by a non-strict separator and a numeric value ending with M
  • Convert the captured megabyte value to gigabytes and format it as a Size entry with key "null" in mapInfo, overriding previous size parsing if matched
deepin-devicemanager/src/GenerateDevice/CmdTool.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

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

Hey - I've found 1 issue, and left some high level feedback:

  • In the Video RAM parsing branch you hardcode mapInfo["Size"] = "null=" + sizeS;, which differs from the existing pattern (cap(1) + "=" + sizeS); consider aligning the key prefix logic or documenting why this one is intentionally null= to avoid confusion for future changes.
  • The regex ".*Video RAM[^0-9]*([0-9]+)[\s]{0,1}M.*" could be made a bit more robust and readable by using \s* instead of {0,1} and optionally enabling case-insensitivity if dmesg output might vary in capitalization.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the `Video RAM` parsing branch you hardcode `mapInfo["Size"] = "null=" + sizeS;`, which differs from the existing pattern (`cap(1) + "=" + sizeS`); consider aligning the key prefix logic or documenting why this one is intentionally `null=` to avoid confusion for future changes.
- The regex `".*Video RAM[^0-9]*([0-9]+)[\s]{0,1}M.*"` could be made a bit more robust and readable by using `\s*` instead of `{0,1}` and optionally enabling case-insensitivity if dmesg output might vary in capitalization.

## Individual Comments

### Comment 1
<location path="deepin-devicemanager/src/commonfunction.h" line_range="37-38" />
<code_context>
         kSpecialCpuType1
     };

+    enum SpecialVRAMType {
+        kUnknowVRAMType = 0,
+        kSpecialVRAMType1
+    };
</code_context>
<issue_to_address>
**suggestion (typo):** Enum value name has a likely typo (`Unknow` vs `Unknown`).

If this isn’t yet used externally, consider renaming it to `kUnknownVRAMType` now to avoid spreading the typo. If you keep the current spelling for consistency with `kUnknowCpuType`, adding a brief code comment elsewhere could help prevent confusion later.

Suggested implementation:

```c
    enum SpecialVRAMType {
        kUnknownVRAMType = 0,
        kSpecialVRAMType1
    };

```

1. Search the codebase for all usages of `kUnknowVRAMType` and update them to `kUnknownVRAMType`.
2. If this enum is part of any public API (e.g., headers used by other modules or external consumers), consider adding a temporary compatibility alias (e.g., a constexpr or deprecated enum value) in a separate header or migration note to ease the transition.
</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 on lines +37 to +38
enum SpecialVRAMType {
kUnknowVRAMType = 0,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (typo): Enum value name has a likely typo (Unknow vs Unknown).

If this isn’t yet used externally, consider renaming it to kUnknownVRAMType now to avoid spreading the typo. If you keep the current spelling for consistency with kUnknowCpuType, adding a brief code comment elsewhere could help prevent confusion later.

Suggested implementation:

    enum SpecialVRAMType {
        kUnknownVRAMType = 0,
        kSpecialVRAMType1
    };
  1. Search the codebase for all usages of kUnknowVRAMType and update them to kUnknownVRAMType.
  2. If this enum is part of any public API (e.g., headers used by other modules or external consumers), consider adding a temporary compatibility alias (e.g., a constexpr or deprecated enum value) in a separate header or migration note to ease the transition.

@github-actions

Copy link
Copy Markdown
  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "deepin-devicemanager/src/main.cpp": [
        {
            "line": "        const QString acknowledgementLink = \"https://www.deepin.org/original/device-manager/\";",
            "line_number": 89,
            "rule": "S35",
            "reason": "Url link | 9d824dc221"
        }
    ]
}

@github-actions

Copy link
Copy Markdown
  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "deepin-devicemanager/src/main.cpp": [
        {
            "line": "        const QString acknowledgementLink = \"https://www.deepin.org/original/device-manager/\";",
            "line_number": 89,
            "rule": "S35",
            "reason": "Url link | 9d824dc221"
        }
    ]
}

@github-actions

Copy link
Copy Markdown
  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "deepin-devicemanager/src/main.cpp": [
        {
            "line": "        const QString acknowledgementLink = \"https://www.deepin.org/original/device-manager/\";",
            "line_number": 89,
            "rule": "S35",
            "reason": "Url link | 9d824dc221"
        }
    ]
}

@github-actions

Copy link
Copy Markdown
  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "deepin-devicemanager/src/main.cpp": [
        {
            "line": "        const QString acknowledgementLink = \"https://www.deepin.org/original/device-manager/\";",
            "line_number": 89,
            "rule": "S35",
            "reason": "Url link | 9d824dc221"
        }
    ]
}

@github-actions

Copy link
Copy Markdown
  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "deepin-devicemanager/src/main.cpp": [
        {
            "line": "        const QString acknowledgementLink = \"https://www.deepin.org/original/device-manager/\";",
            "line_number": 89,
            "rule": "S35",
            "reason": "Url link | 9d824dc221"
        }
    ]
}

@github-actions

Copy link
Copy Markdown
  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "deepin-devicemanager/src/main.cpp": [
        {
            "line": "        const QString acknowledgementLink = \"https://www.deepin.org/original/device-manager/\";",
            "line_number": 89,
            "rule": "S35",
            "reason": "Url link | 9d824dc221"
        }
    ]
}

@github-actions

Copy link
Copy Markdown
  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "deepin-devicemanager/src/main.cpp": [
        {
            "line": "        const QString acknowledgementLink = \"https://www.deepin.org/original/device-manager/\";",
            "line_number": 89,
            "rule": "S35",
            "reason": "Url link | 9d824dc221"
        }
    ]
}

@Resurgamz

Copy link
Copy Markdown
Author

/merga

  Log: 通过 specialVRAMType 配置启用定制显存解析逻辑,匹配 dmesg 中的 Video RAM
  字段并提取显存大小;Video RAM 与数值之间不再限制必须使用冒号分隔,兼容 Video RAM: 2048M、Video RAM
  2048M 等格式。
  Task: https://pms.uniontech.com/task-view-391143.html
@github-actions

Copy link
Copy Markdown
  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "deepin-devicemanager/src/main.cpp": [
        {
            "line": "        const QString acknowledgementLink = \"https://www.deepin.org/original/device-manager/\";",
            "line_number": 89,
            "rule": "S35",
            "reason": "Url link | 9d824dc221"
        }
    ]
}

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码实现了定制机型显存大小的正确解析,逻辑严密且无安全风险
逻辑正确、质量良好、性能无问题且无安全漏洞,因沿用已废弃的QRegExp及版权年份笔误扣5分

■ 【详细分析】

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

在CmdTool::loadDmesgInfo函数中,增加了isSpecialVRAM标志位判断,针对定制机型输出为Video RAM的情况新增正则匹配分支,并使用hasCustomVRAMSize标志位避免后续无效匹配。在main.cpp中对DConfig读取的值进行了严格的枚举边界检查,防止越界赋值,整体逻辑严密无误。
建议:无

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

新增的SpecialVRAMType枚举及全局变量定义与现有的SpecialCpuType保持高度一致,DConfig配置项定义规范完整。使用标志位控制流程走向清晰。
潜在问题:SPDX版权年份被错误地从2022修改为2026
建议:将版权年份修正为当前实际年份或保持原年份不变;可为新增的正则表达式匹配逻辑补充简要注释说明定制机型日志格式差异

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

通过hasCustomVRAMSize标志位在匹配到首个定制显存信息后直接跳过后续行的正则匹配,相比原代码无脑遍历所有行执行正则,实际上优化了定制机型下的解析性能。dmesg日志数据量有限,整体无性能瓶颈。
建议:无

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码对外部配置读取进行了严格的整数边界校验,正则匹配使用exactMatch且数据源为内部系统日志,不存在注入或越界风险,整体安全。

  • 建议:保持现有的边界检查习惯

■ 【改进建议代码示例】

// CmdTool.cpp 中的改进建议:将已废弃的 QRegExp 替换为性能更优的 QRegularExpression
void CmdTool::loadDmesgInfo(const QString &debugfile)
{
    // 获取显存大小信息
    QMap<QString, QString> mapInfo;
    QStringList lines = deviceInfo.split("\n");
    const bool isSpecialVRAM = Common::curVRAMType == Common::kSpecialVRAMType1;
    bool hasCustomVRAMSize = false;
    
    // 使用 QRegularExpression 替代 QRegExp 以提升匹配性能及规范性
    QRegularExpression regCustom(".*([0-9a-z]{4}:[0-9a-z]{2}:[0-9a-z]{2}\\.[0-9]{1}):.*Video RAM[^0-9]*([0-9]+)[\\s]{0,1}M.*");
    
    foreach (const QString &line, lines) {
        if (isSpecialVRAM) {
            QRegularExpressionMatch match = regCustom.match(line);
            if (match.hasMatch()) {
                double size = match.captured(2).toDouble();
                QString sizeS = QString("%1GB").arg(size / 1024);
                mapInfo["Size"] = match.captured(1) + "=" + sizeS;
                hasCustomVRAMSize = true;
                continue;
            }
        }

        if (hasCustomVRAMSize)
            continue;

        // 原有逻辑也可同步替换为 QRegularExpression
        QRegularExpression reg(".*([0-9a-z]{4}:[0-9a-z]{2}:[0-9a-z]{2}\\.[0-9]{1}):.*VRAM([=:]{1}) ([0-9]*)[\\s]{0,1}M.*");
        QRegularExpressionMatch regMatch = reg.match(line);
        if (regMatch.hasMatch()) {
            // 后续原有赋值逻辑
        }
    }
}

@Resurgamz

Copy link
Copy Markdown
Author

/merge

@deepin-bot

deepin-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

This pr cannot be merged! (status: unstable)

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@Resurgamz

Copy link
Copy Markdown
Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot deepin-bot Bot merged commit 255bef2 into linuxdeepin:develop/eagle Jun 16, 2026
21 of 22 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