Skip to content

Conversation

@add-uos
Copy link
Contributor

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

Modified CPU frequency display for kSpecialType7 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-381765.html
Change-Id: Id37a4b03a83ccb6428a1bd3edf601d905edbd2c8

Summary by Sourcery

Include special device type7 in the CPU frequency correction logic to ensure accurate display of current and maximum frequencies.

Bug Fixes:

  • Add kSpecialType7 to the condition applying CPU frequency replacements
  • Apply the same frequency value fixes (2.189→2.188 GHz and 2189→2188 MHz) to kSpecialType7 devices

Modified CPU frequency display for kSpecialType7 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-381765.html
Change-Id: Id37a4b03a83ccb6428a1bd3edf601d905edbd2c8
@deepin-ci-robot
Copy link

deepin pr auto review

我对这段代码进行审查,发现以下几个需要改进的地方:

  1. 代码逻辑问题:
  • 代码中对特殊类型的处理使用了硬编码的数值(kSpecialType5、kSpecialType6、kSpecialType7),这种方式不利于维护和理解。建议使用枚举常量或命名常量来替代这些魔法数字。
  1. 代码质量问题:
  • 字符串替换操作(m_Frequency.replace和m_MaxFrequency.replace)使用了硬编码的值("2.189" -> "2.188"和"2189" -> "2188"),这些值没有明确的业务含义,应该提取为有意义的常量。
  • 整个特殊类型的处理逻辑应该封装到一个单独的函数中,以提高代码的可读性和可维护性。
  1. 代码性能问题:
  • 当前代码中的字符串替换操作可能会创建新的字符串对象,虽然对于小字符串来说影响不大,但在频繁调用的场景下可能会有性能影响。可以考虑使用QString::replace的in-place版本,或者使用QStringRef进行更高效的字符串操作。
  1. 代码安全问题:
  • 代码中没有对输入参数进行有效性检查,如果mapLscpu或mapCpuinfo为空或包含无效数据,可能会导致程序崩溃或产生不可预期的行为。
  • 字符串替换操作没有考虑替换值不存在的情况,这可能会导致替换操作没有效果但程序继续执行,产生潜在的问题。

改进建议:

// 在类定义中添加常量定义
static const QString CPU_FREQUENCY_CORRECTION_VALUE = "2.189";
static const QString CPU_MAX_FREQUENCY_CORRECTION_VALUE = "2189";
static const QString CPU_FREQUENCY_CORRECTED_VALUE = "2.188";
static const QString CPU_MAX_FREQUENCY_CORRECTED_VALUE = "2188";

// 添加输入验证函数
bool DeviceCpu::isValidInput(const QMap<QString, QString> &map) const {
    return !map.isEmpty();
}

// 封装特殊类型的处理逻辑
void DeviceCpu::handleSpecialTypeCorrection() {
    if (Common::specialComType == Common::kSpecialType5 ||
        Common::specialComType == Common::kSpecialType6 ||
        Common::specialComType == Common::kSpecialType7) {
        m_Frequency.replace(CPU_FREQUENCY_CORRECTION_VALUE, CPU_FREQUENCY_CORRECTED_VALUE);
        m_MaxFrequency.replace(CPU_MAX_FREQUENCY_CORRECTION_VALUE, CPU_MAX_FREQUENCY_CORRECTED_VALUE);
    }
}

// 改进后的setCpuInfo函数
void DeviceCpu::setCpuInfo(const QMap<QString, QString> &mapLscpu, const QMap<QString, QString> &mapCpuinfo) {
    // 输入验证
    if (!isValidInput(mapLscpu) || !isValidInput(mapCpuinfo)) {
        qWarning() << "Invalid input maps in DeviceCpu::setCpuInfo";
        return;
    }
    
    // 原有逻辑...
    
    // 使用封装的特殊类型处理函数
    handleSpecialTypeCorrection();
}

这些改进可以提高代码的可读性、可维护性,并减少潜在的错误。同时,通过添加输入验证和封装特殊逻辑,可以增强代码的健壮性和安全性。

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 15, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Extend the CPU frequency correction logic in DeviceCpu::setCpuInfo to include kSpecialType7 devices, ensuring the same frequency and max-frequency replacements apply to correct hardware reporting inaccuracies.

Class diagram for updated DeviceCpu frequency correction logic

classDiagram
    class DeviceCpu {
        - m_Name : QString
        - m_Frequency : QString
        - m_MaxFrequency : QString
        + setCpuInfo(mapLscpu: QMap<QString, QString>, mapCpuinfo: QMap<QString, QString>)
    }
    class Common {
        + specialComType : int
        + kSpecialType5 : int
        + kSpecialType6 : int
        + kSpecialType7 : int
    }
    DeviceCpu --> Common : uses
    DeviceCpu : setCpuInfo() now applies frequency correction for kSpecialType7
Loading

File-Level Changes

Change Details Files
Extend CPU frequency workaround to kSpecialType7
  • Add kSpecialType7 to the specialComType conditional
  • Apply existing m_Frequency and m_MaxFrequency replacements for type7
deepin-devicemanager/src/DeviceManager/DeviceCpu.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

[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 340f1a2 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