Feat: add CPU header info storage and cache size formatting#651
Conversation
Reviewer's GuideImplements CPU header info storage in DeviceManager, introduces a common helper for aggregating and formatting total CPU cache from per-thread values, adjusts main window default height, and updates SPDX headers. Class diagram for updated Common and DeviceManager CPU cache and header infoclassDiagram
class Common {
+static bool isShowScreenSize()
+static QString formatTotalCache(QString perThreadCache, int coreCount)
}
class DeviceManager {
+void setCpuFrequencyIsCur(const bool & flag)
+void setCpuHeaderInfo(const QList~QList~QPair~QString, QString~~~~ & info)
+void getCpuHeaderInfo(QList~QList~QPair~QString, QString~~~~ & info) const
-QList~QList~QPair~QString, QString~~~~ m_ListCpuHeaderInfo
}
DeviceManager ..> Common : uses formatTotalCache
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In Common::formatTotalCache, consider validating coreCount (e.g., treating non-positive values as 0 or 1) and early-returning to avoid misleading results when the multiplier is unexpectedly zero or negative.
- The unit parsing logic in Common::formatTotalCache mixes startsWith checks with specific equality checks (e.g., startsWith("K") or unitStr == "KB"), which is redundant; simplifying this to a consistent normalization and lookup (e.g., mapping normalized units to multipliers) would make the code clearer and less error-prone.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In Common::formatTotalCache, consider validating coreCount (e.g., treating non-positive values as 0 or 1) and early-returning to avoid misleading results when the multiplier is unexpectedly zero or negative.
- The unit parsing logic in Common::formatTotalCache mixes startsWith checks with specific equality checks (e.g., startsWith("K") or unitStr == "KB"), which is redundant; simplifying this to a consistent normalization and lookup (e.g., mapping normalized units to multipliers) would make the code clearer and less error-prone.
## Individual Comments
### Comment 1
<location path="deepin-devicemanager/src/commonfunction.cpp" line_range="266-270" />
<code_context>
+ while (i >= 0 && !s[i].isDigit() && s[i] != '.')
+ --i;
+
+ QString numStr = s.left(i + 1);
+ QString unitStr = s.mid(i + 1).toUpper();
+
+ bool ok;
+ double num = numStr.toDouble(&ok);
+ if (!ok)
+ return QString();
</code_context>
<issue_to_address>
**issue (bug_risk):** Input formats with prefixes (e.g. "L3 256 KiB") will fail to parse.
Because the backward scan only skips trailing non-digits, `s.left(i + 1)` still includes any leading label (e.g. "L3 256 "), so `toDouble` fails and the function returns empty. If inputs can include such prefixes, you’ll need to strip non-numeric content before the numeric part (e.g. scan forward for the first digit or use a regex to extract the number and unit).
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
2d33350 to
67f9625
Compare
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
- 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
67f9625 to
8a54efe
Compare
deepin pr auto review这段代码主要是对设备管理器(DeviceManager)进行了一些更新,包括版权年份更新、新增CPU头部信息的存取接口、调整窗口初始高度,以及新增一个用于格式化总缓存大小的工具函数。以下是对这段diff的详细审查和改进建议: 1. 版权与许可证更新-// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
+// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.意见:这是一个常规的版权年份更新,将有效期延长至2026年。这是合理的,但建议在代码库中统一更新所有相关文件的版权年份,避免不同文件年份不一致。 2. 新增CPU头部信息接口void DeviceManager::setCpuHeaderInfo(const QList<QList<QPair<QString, QString>>> &info)
{
m_ListCpuHeaderInfo = info;
}
void DeviceManager::getCpuHeaderInfo(QList<QList<QPair<QString, QString>>> &info) const
{
info = m_ListCpuHeaderInfo;
}意见:
3. 窗口初始高度调整-#define INIT_HEIGHT 720 // 窗口的初始化高度
+#define INIT_HEIGHT 802 // 窗口的初始化高度意见:
4. 新增
|
|
/merge |
|
This pr cannot be merged! (status: unstable) |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
27cd21b
into
linuxdeepin:develop/eagle
Log: add feature for cpu info show
Task: https://pms.uniontech.com/task-view-387697.html
Summary by Sourcery
Add storage and accessors for CPU header information and introduce formatted total CPU cache size display, alongside minor UI and metadata tweaks.
New Features:
Enhancements: