Skip to content

Conversation

@GongHeng2017
Copy link
Contributor

@GongHeng2017 GongHeng2017 commented Sep 3, 2025

-- Not show gpu on some platform.

Log: fix issue
Bug: https://pms.uniontech.com/task-view-378987.html

Summary by Sourcery

Bug Fixes:

  • Always fetch and display GPU memory info after base info succeeds to prevent GPU from being hidden when memory retrieval fails

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 and they look great!


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.

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 3, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR refactors the main function’s GPU info retrieval logic by separating the base and memory info calls so that GPU details are displayed even when memory info detection fails on some platforms.

File-Level Changes

Change Details Files
Ensure GPU info is always printed by decoupling base and memory info checks
  • Removed combined condition requiring both getGpuBaseInfo and getGpuMemInfoForFTDTM to succeed
  • Replaced if (base && mem) with if (base)
  • Moved getGpuMemInfoForFTDTM call inside the base-info check block
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

@GongHeng2017 GongHeng2017 force-pushed the 202509031341-eagle-fixGpu branch from fa702c1 to e96c146 Compare September 3, 2025 07:42
@deepin-ci-robot
Copy link

deepin pr auto review

我对这段代码进行审查,发现了一些需要改进的地方:

  1. 逻辑问题:

    • 原代码中getGpuMemInfoForFTDTM的返回值被忽略,这可能导致错误处理不当。即使获取GPU内存信息失败,程序仍会继续执行并输出可能不完整的信息。
  2. 代码质量:

    • 缺少错误处理机制,当getGpuMemInfoForFTDTM失败时没有适当的反馈。
    • 没有对命令行参数进行处理,程序灵活性不足。
    • 输出直接使用std::cout,可以考虑使用更统一的日志系统。
  3. 代码性能:

    • 当前实现没有明显的性能问题,但对于生产环境,可以考虑添加缓存机制,避免频繁获取相同信息。
  4. 代码安全:

    • 没有对输入参数进行验证。
    • 直接输出到标准输出,可能存在信息泄露风险,特别是当处理敏感信息时。

改进建议:

#include <iostream>
#include <QMap>
#include <QString>

// 添加日志函数
void logInfo(const QString& message) {
    std::cout << "[INFO] " << message.toStdString() << std::endl;
}

void logError(const QString& message) {
    std::cerr << "[ERROR] " << message.toStdString() << std::endl;
}

bool getGpuBaseInfo(QMap<QString, QString> &mapInfo) {
    // 原有实现
}

bool getGpuMemInfoForFTDTM(QMap<QString, QString> &mapInfo) {
    // 原有实现
}

int main(int argc, char *argv[]) {
    // 处理命令行参数
    if (argc > 1) {
        logError("Usage: " + QString(argv[0]) + " [no arguments]");
        return 1;
    }

    QMap<QString, QString> mapInfo;
    
    // 获取基础信息
    if (!getGpuBaseInfo(mapInfo)) {
        logError("Failed to get GPU base information");
        return 1;
    }
    
    // 获取内存信息
    if (!getGpuMemInfoForFTDTM(mapInfo)) {
        logError("Failed to get GPU memory information");
        return 1;
    }
    
    // 输出信息
    for (auto it = mapInfo.begin(); it != mapInfo.end(); ++it) {
        logInfo(it.key() + ": " + it.value());
    }
    
    return 0;
}
  1. 其他建议:
    • 考虑添加配置文件支持,允许用户自定义输出格式或过滤特定信息。
    • 可以添加单元测试,确保代码的正确性和稳定性。
    • 考虑将代码模块化,提高可维护性和可扩展性。
    • 添加适当的注释,说明函数的功能和参数含义。

这些改进将使代码更加健壮、可维护,并提高其安全性。

@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

/merge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Sep 3, 2025

This pr cannot be merged! (status: unstable)

@GongHeng2017
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Sep 3, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 7e87464 into linuxdeepin:develop/eagle Sep 3, 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.

3 participants