Skip to content

fix(cpu): format CPU frequency range with two decimals - #723

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
GongHeng2017:agent/pms-bug-bot/bf407351
Aug 6, 2026
Merged

fix(cpu): format CPU frequency range with two decimals#723
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
GongHeng2017:agent/pms-bug-bot/bf407351

Conversation

@GongHeng2017

@GongHeng2017 GongHeng2017 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

根因分析

DeviceCpu::setInfoFromLscpudeepin-devicemanager/src/DeviceManager/DeviceCpu.cpp:306/308)用 QString::arg(double) 的默认 'g'(6 位有效数字)格式显示由 MHz 换算得到的 GHz 值。兆芯 7000 等机型 lscpu 的 CPU min/max MHz 为非整数值,换算后两端按"有效数字"输出,小数位数不一致(如 1.59997-2.8 GHz),即 bug 所述"频率信息显示不统一"。m_Frequency 经概览表"频率"列(:453)与详情"Max Speed"(:406)两处展示,故界面可见。

关键证据:

  1. DeviceCpu.cpp:308 QString("%1-%2 GHz").arg(minHz).arg(maxHz) —— 默认 'g' 按有效数字输出,非整数 MHz 时两端小数位数不同。
  2. :453 / :406 —— m_Frequency 写入概览表"频率"列与详情"Max Speed",即用户所见。
  3. 演算验证:1.599975 → 'g'6="1.59997" vs 'f'2="1.60";2.8 → "2.8" vs "2.80"。

修复方案

将三处 arg(double) 改为 arg(double, 0, 'f', 2)(定点两位小数),频率范围统一为 1.60-2.80 GHz,直接消除小数位数不一致的根因。覆盖单值 GHz / 单值 MHz / 范围三种取值,不改变分支逻辑与阈值,改动最小。同步更新既有单测 UT_DeviceCpu_setInfoFromLscpu_002/_003 两条 m_Frequency 断言为新格式(0.80-4.20 GHz / 800.00 MHz)。

改动安全评估

中风险:仅改输出格式与对应单测断言,函数签名不变,无生产调用方回归;历史提交 fe4b2f678a(修复"最大频率不显示单位")的单位后缀被完整保留,不回滚。UT_DeviceCpu_setInfoFromLscpu_002/_003tests/src/DeviceManager/ut_devicecpu.cpp:266/296)的两条断言已同步更新为新格式,与修复后的生产行为一致;其余单测断言(4085.639 MHz8300 MHz)走未被改动的分支,无需调整。

@sourcery-ai

sourcery-ai Bot commented Aug 6, 2026

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

Reviewer's Guide

Standardize CPU frequency display formatting by switching QString::arg(double) calls to fixed two-decimal formatting for GHz and MHz, ensuring consistent frequency ranges in the UI without altering logic or thresholds.

File-Level Changes

Change Details Files
Standardize CPU frequency string formatting for single-value and range displays from lscpu data.
  • Change GHz single-value formatting to use fixed-point with two decimal places when min and max frequencies are equal.
  • Change MHz single-value formatting (when frequency < 1 GHz) to use fixed-point with two decimal places.
  • Change GHz range formatting (min-max) to use fixed-point with two decimal places for both endpoints, eliminating inconsistent decimal lengths.
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

@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 left some high level feedback:

  • Since the GHz and MHz formatting logic is now duplicated in multiple branches, consider extracting a small helper (e.g. formatFrequencyGHz(double) / formatFrequencyMHz(double)) to keep the formatting rules centralized and easier to adjust later.
  • Using two decimal places for MHz values (e.g. 800.00 MHz) may be unnecessarily verbose compared to the original output; consider using a different precision for MHz (or trimming trailing zeros) while still keeping GHz at two decimals for consistency within ranges.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since the GHz and MHz formatting logic is now duplicated in multiple branches, consider extracting a small helper (e.g. `formatFrequencyGHz(double)` / `formatFrequencyMHz(double)`) to keep the formatting rules centralized and easier to adjust later.
- Using two decimal places for MHz values (e.g. `800.00 MHz`) may be unnecessarily verbose compared to the original output; consider using a different precision for MHz (or trimming trailing zeros) while still keeping GHz at two decimals for consistency within ranges.

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.

@GongHeng2017
GongHeng2017 force-pushed the agent/pms-bug-bot/bf407351 branch 4 times, most recently from a8a8c9a to af278e2 Compare August 6, 2026 12:13
Use fixed 2-decimal format for CPU GHz/MHz frequency display strings;
sync related unit-test assertions to the new format.

将CPU频率(GHz/MHz)显示统一格式化为定点保留两位小数;同步更新相关单测断言。

Log: 统一CPU频率显示为保留两位小数,避免频率范围两端小数位数不一致
PMS: BUG-372847
Influence: 修复兆芯等机型上设备管理器CPU频率范围两端小数位数显示不一致的问题。
@GongHeng2017
GongHeng2017 force-pushed the agent/pms-bug-bot/bf407351 branch from af278e2 to 109cf2d Compare August 6, 2026 12:21
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码精准修复了CPU频率显示格式不统一的问题,逻辑清晰且测试同步更新
逻辑正确、质量良好且无任何安全风险,不扣分

■ 【详细分析】

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

修改位于 DeviceCpu.cpp 第 306-308 行的 setInfoFromLscpu 函数中,通过在 QString::arg() 中增加 0, 'f', 2 参数,准确实现了浮点数强制保留两位小数的需求,完美解决了 0.8-4.2 GHz 显示为 0.80-4.20 GHz 的格式问题

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

代码修改范围克制,仅针对格式化逻辑进行精准修改,并在 ut_devicecpu.cpp 中同步更新了对应的单元测试期望值,确保了代码与测试的一致性,同时规范了版权声明格式

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

仅涉及基础的浮点数字符串格式化操作,QString::arg 的额外参数不会引入任何可感知的性能开销

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
该修改纯粹涉及局部变量的字符串格式化展示,不涉及任何外部输入解析、内存分配、系统调用或权限操作,无安全攻击面

  • 建议:无需额外安全修复措施

■ 【改进建议代码示例】

// 当前代码已为最佳实践,无需额外改进,以下为确认其正确性的上下文参考
void DeviceCpu::setInfoFromLscpu(const QMap<QString, QString> &mapInfo)
{
    // ...
    if (fabs(minHz - maxHz) < 0.001) {
        m_FrequencyIsRange = false;
        m_Frequency = maxHz > 1 ? QString("%1 GHz").arg(maxHz, 0, 'f', 2) : QString("%1 MHz").arg(maxHz * 1000, 0, 'f', 2);
    } else {
        m_Frequency = QString("%1-%2 GHz").arg(minHz, 0, 'f', 2).arg(maxHz, 0, 'f', 2);
    }
    // ...
}

@deepin-ci-robot

Copy link
Copy Markdown

[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
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot
deepin-bot Bot merged commit af0f4ea into linuxdeepin:develop/eagle Aug 6, 2026
20 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