Skip to content

Conversation

@add-uos
Copy link
Contributor

@add-uos add-uos commented Sep 15, 2025

Modified CPU frequency display for kSpecialType5 devices include current frequency and max frequency to correct hardware reporting inaccuracies.

Log: Fix CPU frequency display for special device type
Task: https://pms.uniontech.com/task-view-381921.html
Change-Id: Ia80c7e9edf7618188874e0648cb599920f49eada

Summary by Sourcery

Include support for kSpecialType5 devices in CPU frequency reporting and unify enum naming for better consistency.

Enhancements:

  • Extend CPU frequency correction to apply to kSpecialType5 as well as kSpecialType6 devices
  • Rename PGUX enum to kSpecialType5 in Common to standardize special device type identifiers

Modified CPU frequency display for kSpecialType5 devices
include current frequency and max frequency to correct hardware
reporting inaccuracies.

Log: Fix CPU frequency display for special device type
Task: https://pms.uniontech.com/task-view-381921.html
Change-Id: Ia80c7e9edf7618188874e0648cb599920f49eada
@deepin-ci-robot
Copy link

deepin pr auto review

根据提供的代码差异,我来进行分析和提出改进建议:

  1. 代码逻辑改进:
  • 在 DeviceCpu.cpp 中,将特殊类型判断从只判断 kSpecialType6 扩展到同时判断 kSpecialType5 和 kSpecialType6,这是一个合理的扩展,但建议添加注释说明为什么这两种类型需要特殊处理。
  • 在 commonfunction.cpp 和 commonfunction.h 中,将 PGUX 重命名为 kSpecialType5,这是一个好的改进,因为命名更加统一和规范,遵循了已有的命名模式。
  1. 代码质量改进:
  • 建议在 DeviceCpu.cpp 中的字符串替换操作添加错误处理,因为如果 m_Frequency 或 m_MaxFrequency 为空或未初始化,replace 操作可能会导致意外行为。
  • 对于硬编码的值如 "2.189" 和 "2188",建议定义为命名常量,以提高代码可维护性。
  1. 代码性能改进:
  • 频繁的字符串替换操作可能会影响性能,特别是如果这些操作在性能关键的代码路径中。可以考虑使用 QStringRef 或其他优化方法来减少字符串操作的开销。
  • 如果这些特殊处理是针对特定硬件型号的,可以考虑将这些信息存储在配置文件中,而不是硬编码在代码中。
  1. 代码安全改进:
  • 在进行字符串替换时,建议先检查字符串是否包含要替换的内容,避免不必要的操作。
  • 考虑添加输入验证,确保 m_Frequency 和 m_MaxFrequency 是有效的数值字符串,防止潜在的注入攻击或格式错误。

具体改进建议:

// 在 DeviceCpu.cpp 中
void DeviceCpu::setCpuInfo(const QMap<QString, QString> &mapLscpu, const QMap<QString, QString> &mapCpuinfo) {
    // ... 其他代码 ...

    // 特殊处理特定型号的CPU频率显示
    if (Common::specialComType == Common::kSpecialType5 ||
        Common::specialComType == Common::kSpecialType6) {
        // 定义常量
        static const QLatin1String oldFreq("2.189");
        static const QLatin1String newFreq("2.188");
        static const QLatin1String oldMaxFreq("2189");
        static const QLatin1String newMaxFreq("2188");
        
        // 安全地进行字符串替换
        if (m_Frequency.contains(oldFreq)) {
            m_Frequency.replace(oldFreq, newFreq);
        }
        if (m_MaxFrequency.contains(oldMaxFreq)) {
            m_MaxFrequency.replace(oldMaxFreq, newMaxFreq);
        }
    }
}

// 在 commonfunction.h 中
class Common {
    // ... 其他代码 ...
    enum SpecialType {
        // ... 其他枚举值 ...
        kSpecialType5,  // 之前是 PGUX
        kSpecialType6,
        kSpecialType7,
        kCustomType
    };
    // ... 其他代码 ...
};

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

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 15, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR adds kSpecialType5 support for CPU frequency correction alongside existing specialType6 logic and renames the PGUX enum to kSpecialType5 in common functions for consistent device categorization.

File-Level Changes

Change Details Files
Extend CPU frequency correction to kSpecialType5 devices
  • Include kSpecialType5 in the if condition within DeviceCpu::setCpuInfo
  • Adjust the multi-line conditional indentation
  • Apply frequency and max frequency replacements for kSpecialType5
deepin-devicemanager/src/DeviceManager/DeviceCpu.cpp
Rename PGUX enum to kSpecialType5 and update its mapping
  • Replace PGUX enum value with kSpecialType5 in commonfunction.h
  • Update switch case in commonfunction.cpp to map kSpecialType5 to the PGUX vendor key
deepin-devicemanager/src/commonfunction.cpp
deepin-devicemanager/src/commonfunction.h

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

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

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@add-uos
Copy link
Contributor Author

add-uos commented Sep 15, 2025

/merge

@deepin-bot deepin-bot bot merged commit fb6672b into linuxdeepin:develop/eagle Sep 15, 2025
18 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