Skip to content

Conversation

@add-uos
Copy link
Contributor

@add-uos add-uos commented Dec 1, 2025

-- In some special computer, the GPU info not show. -- Add logic to show GPU info.

pick from: 350c0a6

Log: add feature for GPU.
Task: https://pms.uniontech.com/task-view-378987.html

-- In some special computer, the GPU info not show.
-- Add logic to show GPU info.

pick from: linuxdeepin@350c0a6

Log: add feature for GPU.
Task: https://pms.uniontech.com/task-view-378987.html
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.

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

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码进行审查:

  1. 代码结构和逻辑:
  • 新增了一个customgpuinfo子模块用于获取GPU信息,结构清晰
  • 通过DConfig配置来控制是否使用自定义GPU信息获取方式,设计合理
  • 实现了完整的GPU信息获取流程,包括基本信息和显存信息
  1. 代码质量:
  • 代码注释充分,使用SPDX许可证头
  • 变量命名规范,使用驼峰命名法
  • 函数职责单一,符合单一职责原则
  1. 存在的问题和改进建议:

a) 错误处理:

// 在getGpuMemInfoForFTDTM函数中
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
    qCritical() << "Error opening /sys/kernel/debug/gc/meminfo:" << file.errorString();
    return false;
}

建议添加文件权限检查,因为访问/sys/kernel/debug/需要root权限。

b) 内存管理:

// 在CustomGenerator::generatorGpuDevice中
DeviceGpu *device = new DeviceGpu();

建议使用智能指针(QSharedPointer)管理内存,避免内存泄漏。

c) 安全性:

// 在getGpuInfoByCustom函数中
process.start(cmd, arguments);

建议对cmd参数进行验证,防止命令注入攻击。

d) 性能优化:

// 在getGpuMemInfoForFTDTM中
QRegularExpression system0Regex(R"(POOL SYSTEM0:*(.*?)POOL VIRTUAL:)",
                                QRegularExpression::DotMatchesEverythingOption);

建议将正则表达式编译为静态常量,避免重复编译。

e) 代码健壮性:

// 在getGpuMemInfoForFTDTM中
if (ok && memSize >= 1048576) {
    memSize /= 1048576;
    auto curSize = memSize / 1024.0;
    if (curSize >= 1) {
        totalValue = QString::number(curSize) + "GB";
    } else {
        totalValue = QString::number(memSize) + "MB";
    }
}

建议添加边界检查,防止数值溢出。

  1. 其他建议:
  • 建议为GPU信息获取添加超时机制,避免长时间阻塞
  • 可以考虑添加GPU信息的缓存机制,减少重复获取
  • 建议添加更详细的日志记录,便于问题排查
  1. 安全建议:
  • 对/sys/kernel/debug/gc/meminfo的访问需要添加权限检查
  • 对外部命令执行需要添加参数验证
  • 建议添加对GPU信息获取失败的重试机制

总体来说,代码结构清晰,功能完整,但在错误处理、内存管理和安全性方面还有改进空间。建议按照上述建议进行优化,以提高代码的健壮性和安全性。

@deepin-ci-robot
Copy link

[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

@add-uos
Copy link
Contributor Author

add-uos commented Dec 1, 2025

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 1, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 78a3b31 into linuxdeepin:master Dec 1, 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