Skip to content

Feat: add CPU header info storage and cache size formatting#633

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/eagle-20260325from
GongHeng2017:202604011108-tmp-dev-feat
Apr 1, 2026
Merged

Feat: add CPU header info storage and cache size formatting#633
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/eagle-20260325from
GongHeng2017:202604011108-tmp-dev-feat

Conversation

@GongHeng2017
Copy link
Copy Markdown
Contributor

@GongHeng2017 GongHeng2017 commented Apr 1, 2026

  • Add DeviceManager CPU header info getters/setters and storage member
  • Adjust main window initial height to 802
  • Rename HeaderInfoTableWidget clear() to resetTableContents()
  • Add Common::formatTotalCache for converting per-thread cache to total cache and formatting with KiB/MiB/GiB units
  • Update SPDX year range in DeviceManager files

Log: add feature for cpu info show
Task: https://pms.uniontech.com/task-view-387697.html

Summary by Sourcery

Add CPU header information storage in DeviceManager and introduce a utility for formatting total CPU cache size, alongside minor UI and metadata adjustments.

New Features:

  • Store per-CPU header information in DeviceManager with public getter and setter APIs.
  • Provide a Common::formatTotalCache helper to convert per-thread CPU cache values to a formatted total size string in KiB/MiB/GiB units.

Enhancements:

  • Rename HeaderInfoTableWidget::clear to resetTableContents to better reflect its behavior and use it when updating table data.
  • Adjust the main window initial height to 802 for improved layout.
  • Update SPDX copyright year ranges in DeviceManager sources.

- Add DeviceManager CPU header info getters/setters and storage member
- Adjust main window initial height to 802
- Rename HeaderInfoTableWidget clear() to resetTableContents()
- Add Common::formatTotalCache for converting per-thread cache to total cache
  and formatting with KiB/MiB/GiB units
- Update SPDX year range in DeviceManager files

Log: add feature for cpu info show
Task: https://pms.uniontech.com/task-view-387697.html
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 1, 2026

Reviewer's Guide

Implements CPU header info storage on DeviceManager, introduces a reusable cache-size formatting helper, and performs a few small UI and metadata tweaks (window height, header table reset naming, SPDX year range).

Class diagram for updated DeviceManager, Common, and HeaderInfoTableWidget

classDiagram
    class Common {
        +SpecialCpuType curCpuType
        +QByteArray executeClientCmd(cmd, args, workPath, msecsWaiting)
        +QString formatTotalCache(perThreadCache, coreCount)
    }

    class DeviceManager {
        +setCpuFrequencyIsCur(flag)
        +setCpuHeaderInfo(info)
        +getCpuHeaderInfo(info) const
        -m_CurrentXlsRow : int
        -m_networkDriver : QStringList
        -m_ListCpuHeaderInfo : QList~QList~QPair~QString, QString~~~~
    }

    class HeaderInfoTableWidget {
        -HeaderInfoDelegate m_delegate
        +HeaderInfoTableWidget(parent)
        +updateData(data)
        -initUI()
        -resetTableContents()
    }

    DeviceManager ..> QList : uses
    DeviceManager ..> QPair : uses
    DeviceManager ..> QString : uses
    Common ..> QString : uses
    HeaderInfoTableWidget --|> DTableWidget
Loading

Flow diagram for Common::formatTotalCache cache size formatting

flowchart TD
    A_start[Start formatTotalCache] --> B_trim[Trim perThreadCache to s]
    B_trim --> C_empty{s is empty?}
    C_empty -- Yes --> Z_returnEmpty[Return empty QString]
    C_empty -- No --> D_scan[Scan from end to find last digit or '.' index i]
    D_scan --> E_numUnit["Split into numStr and unitStr (uppercased)"]
    E_numUnit --> F_parseNum[Parse numStr to double num]
    F_parseNum --> G_ok{Parse ok?}
    G_ok -- No --> Z_returnEmpty
    G_ok -- Yes --> H_unitToKiB[Convert per core cache to perCoreKiB]

    H_unitToKiB --> H1_unitCheck{unitStr type}
    H1_unitCheck -- K/KiB/KB --> H1_k[perCoreKiB = num]
    H1_unitCheck -- M/MiB/MB --> H1_m[perCoreKiB = num * 1024]
    H1_unitCheck -- G/GiB/GB --> H1_g[perCoreKiB = num * 1024 * 1024]
    H1_unitCheck -- T/TiB/TB --> H1_t[perCoreKiB = num * 1024 * 1024 * 1024]
    H1_unitCheck -- empty or B --> H1_b[perCoreKiB = num / 1024]
    H1_unitCheck -- other --> H1_other[perCoreKiB = num]

    H1_k --> I_total
    H1_m --> I_total
    H1_g --> I_total
    H1_t --> I_total
    H1_b --> I_total
    H1_other --> I_total

    I_total[Compute totalKiB = perCoreKiB * coreCount] --> J_pickUnit{totalKiB >= 1024^2?}
    J_pickUnit -- Yes --> J_gib[value = totalKiB / 1024^2; unit = GiB]
    J_pickUnit -- No --> K_pickMiB{totalKiB >= 1024?}
    K_pickMiB -- Yes --> K_mib[value = totalKiB / 1024; unit = MiB]
    K_pickMiB -- No --> K_kib[value = totalKiB; unit = KiB]

    J_gib --> L_intCheck
    K_mib --> L_intCheck
    K_kib --> L_intCheck

    L_intCheck[Check if value is integer using modf] --> M_isInt{Is integer?}
    M_isInt -- Yes --> N_int[Return integer string + space + unit]
    M_isInt -- No --> O_frac[Return value with 1 decimal + space + unit]

    N_int --> P_end[End]
    O_frac --> P_end
Loading

File-Level Changes

Change Details Files
Add reusable helper to compute and format total CPU cache size from per-thread values.
  • Introduce Common::formatTotalCache API in commonfunction.{h,cpp}.
  • Parse numeric and unit parts from a per-thread cache string, normalizing to KiB internally.
  • Support K/M/G/T and byte/no-unit inputs, then scale total to KiB/MiB/GiB based on magnitude.
  • Format output with integer precision when possible, otherwise one decimal place.
deepin-devicemanager/src/commonfunction.cpp
deepin-devicemanager/src/commonfunction.h
Store and expose CPU header info in DeviceManager.
  • Add QList<QList<QPair<QString, QString>>> m_ListCpuHeaderInfo member to DeviceManager for all physical CPU header info.
  • Provide setCpuHeaderInfo and getCpuHeaderInfo accessors to write/read cached header info.
  • Update DeviceManager header and implementation SPDX year range metadata.
deepin-devicemanager/src/DeviceManager/DeviceManager.h
deepin-devicemanager/src/DeviceManager/DeviceManager.cpp
Align header info table widget API naming and adjust main window layout.
  • Rename HeaderInfoTableWidget::clear() to resetTableContents() and use it from updateData().
  • Keep resetTableContents delegating to DTableWidget::clear() and resetting row count.
  • Increase main window initial height from 720 to 802 to better fit new content.
deepin-devicemanager/src/Widget/headerinfotablewidget.h
deepin-devicemanager/src/Widget/headerinfotablewidget.cpp
deepin-devicemanager/src/Page/MainWindow.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

Copy link
Copy Markdown

@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 - I've found 1 issue, and left some high level feedback:

  • In Common::formatTotalCache, consider validating/corectly guarding against non-positive coreCount values (e.g., <= 0) to avoid misleading results like negative or zero total cache.
  • The unit parsing in Common::formatTotalCache treats unknown units as KiB, which may hide input errors; consider either returning an empty string or logging/flagging unrecognized units instead of silently assuming KiB.
  • DeviceManager::getCpuHeaderInfo currently uses an out-parameter and copies the entire QList; consider returning a const reference or value directly to simplify the API and potentially reduce unnecessary copying.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In Common::formatTotalCache, consider validating/corectly guarding against non-positive coreCount values (e.g., <= 0) to avoid misleading results like negative or zero total cache.
- The unit parsing in Common::formatTotalCache treats unknown units as KiB, which may hide input errors; consider either returning an empty string or logging/flagging unrecognized units instead of silently assuming KiB.
- DeviceManager::getCpuHeaderInfo currently uses an out-parameter and copies the entire QList; consider returning a const reference or value directly to simplify the API and potentially reduce unnecessary copying.

## Individual Comments

### Comment 1
<location path="deepin-devicemanager/src/commonfunction.cpp" line_range="243-252" />
<code_context>
+QString Common::formatTotalCache(const QString &perThreadCache, int coreCount)
</code_context>
<issue_to_address>
**issue:** Guard against non-positive coreCount to avoid misleading results.

For `coreCount <= 0`, `totalKiB` becomes 0 or negative and still formats as a valid cache size. Please either early-return a sentinel (e.g., empty string) or clamp `coreCount` to at least 1 so that invalid inputs are handled explicitly and easier to detect.
</issue_to_address>

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
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
Copy link
Copy Markdown
Contributor

deepin-bot bot commented Apr 1, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 8f355a2 into linuxdeepin:develop/eagle-20260325 Apr 1, 2026
19 of 22 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