fix: 支持通过 Video RAM 匹配定制显存大小#686
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds a configurable special VRAM parsing path that reads a new specialVRAMType config and, when enabled, extracts video memory size from dmesg lines containing "Video RAM" with more flexible formatting, wiring this through a new Common::SpecialVRAMType enum and static state. Sequence diagram for specialVRAMType configuration and Video RAM parsingsequenceDiagram
participant Main
participant DConfig
participant Common
participant CmdTool
Main->>DConfig: value(specialVRAMType)
DConfig-->>Main: int
Main->>Common: set curVRAMType
Main->>CmdTool: loadDmesgInfo(debugfile)
loop each dmesg line
CmdTool->>Common: read curVRAMType
alt [curVRAMType == kSpecialVRAMType1]
CmdTool->>CmdTool: regCustom.exactMatch(line)
alt [matched Video RAM]
CmdTool->>CmdTool: regCustom.cap(1).toDouble()
CmdTool->>CmdTool: mapInfo["Size"] = "null=" + sizeS
end
else [other VRAM types]
CmdTool->>CmdTool: existing VRAM regex handling
end
end
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 the
Video RAMparsing branch you hardcodemapInfo["Size"] = "null=" + sizeS;, which differs from the existing pattern (cap(1) + "=" + sizeS); consider aligning the key prefix logic or documenting why this one is intentionallynull=to avoid confusion for future changes. - The regex
".*Video RAM[^0-9]*([0-9]+)[\s]{0,1}M.*"could be made a bit more robust and readable by using\s*instead of{0,1}and optionally enabling case-insensitivity if dmesg output might vary in capitalization.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the `Video RAM` parsing branch you hardcode `mapInfo["Size"] = "null=" + sizeS;`, which differs from the existing pattern (`cap(1) + "=" + sizeS`); consider aligning the key prefix logic or documenting why this one is intentionally `null=` to avoid confusion for future changes.
- The regex `".*Video RAM[^0-9]*([0-9]+)[\s]{0,1}M.*"` could be made a bit more robust and readable by using `\s*` instead of `{0,1}` and optionally enabling case-insensitivity if dmesg output might vary in capitalization.
## Individual Comments
### Comment 1
<location path="deepin-devicemanager/src/commonfunction.h" line_range="37-38" />
<code_context>
kSpecialCpuType1
};
+ enum SpecialVRAMType {
+ kUnknowVRAMType = 0,
+ kSpecialVRAMType1
+ };
</code_context>
<issue_to_address>
**suggestion (typo):** Enum value name has a likely typo (`Unknow` vs `Unknown`).
If this isn’t yet used externally, consider renaming it to `kUnknownVRAMType` now to avoid spreading the typo. If you keep the current spelling for consistency with `kUnknowCpuType`, adding a brief code comment elsewhere could help prevent confusion later.
Suggested implementation:
```c
enum SpecialVRAMType {
kUnknownVRAMType = 0,
kSpecialVRAMType1
};
```
1. Search the codebase for all usages of `kUnknowVRAMType` and update them to `kUnknownVRAMType`.
2. If this enum is part of any public API (e.g., headers used by other modules or external consumers), consider adding a temporary compatibility alias (e.g., a constexpr or deprecated enum value) in a separate header or migration note to ease the transition.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| enum SpecialVRAMType { | ||
| kUnknowVRAMType = 0, |
There was a problem hiding this comment.
suggestion (typo): Enum value name has a likely typo (Unknow vs Unknown).
If this isn’t yet used externally, consider renaming it to kUnknownVRAMType now to avoid spreading the typo. If you keep the current spelling for consistency with kUnknowCpuType, adding a brief code comment elsewhere could help prevent confusion later.
Suggested implementation:
enum SpecialVRAMType {
kUnknownVRAMType = 0,
kSpecialVRAMType1
};- Search the codebase for all usages of
kUnknowVRAMTypeand update them tokUnknownVRAMType. - If this enum is part of any public API (e.g., headers used by other modules or external consumers), consider adding a temporary compatibility alias (e.g., a constexpr or deprecated enum value) in a separate header or migration note to ease the transition.
|
Note
详情{
"deepin-devicemanager/src/main.cpp": [
{
"line": " const QString acknowledgementLink = \"https://www.deepin.org/original/device-manager/\";",
"line_number": 89,
"rule": "S35",
"reason": "Url link | 9d824dc221"
}
]
} |
|
Note
详情{
"deepin-devicemanager/src/main.cpp": [
{
"line": " const QString acknowledgementLink = \"https://www.deepin.org/original/device-manager/\";",
"line_number": 89,
"rule": "S35",
"reason": "Url link | 9d824dc221"
}
]
} |
|
Note
详情{
"deepin-devicemanager/src/main.cpp": [
{
"line": " const QString acknowledgementLink = \"https://www.deepin.org/original/device-manager/\";",
"line_number": 89,
"rule": "S35",
"reason": "Url link | 9d824dc221"
}
]
} |
|
Note
详情{
"deepin-devicemanager/src/main.cpp": [
{
"line": " const QString acknowledgementLink = \"https://www.deepin.org/original/device-manager/\";",
"line_number": 89,
"rule": "S35",
"reason": "Url link | 9d824dc221"
}
]
} |
|
Note
详情{
"deepin-devicemanager/src/main.cpp": [
{
"line": " const QString acknowledgementLink = \"https://www.deepin.org/original/device-manager/\";",
"line_number": 89,
"rule": "S35",
"reason": "Url link | 9d824dc221"
}
]
} |
|
Note
详情{
"deepin-devicemanager/src/main.cpp": [
{
"line": " const QString acknowledgementLink = \"https://www.deepin.org/original/device-manager/\";",
"line_number": 89,
"rule": "S35",
"reason": "Url link | 9d824dc221"
}
]
} |
|
Note
详情{
"deepin-devicemanager/src/main.cpp": [
{
"line": " const QString acknowledgementLink = \"https://www.deepin.org/original/device-manager/\";",
"line_number": 89,
"rule": "S35",
"reason": "Url link | 9d824dc221"
}
]
} |
|
/merga |
Log: 通过 specialVRAMType 配置启用定制显存解析逻辑,匹配 dmesg 中的 Video RAM 字段并提取显存大小;Video RAM 与数值之间不再限制必须使用冒号分隔,兼容 Video RAM: 2048M、Video RAM 2048M 等格式。 Task: https://pms.uniontech.com/task-view-391143.html
|
Note
详情{
"deepin-devicemanager/src/main.cpp": [
{
"line": " const QString acknowledgementLink = \"https://www.deepin.org/original/device-manager/\";",
"line_number": 89,
"rule": "S35",
"reason": "Url link | 9d824dc221"
}
]
} |
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // CmdTool.cpp 中的改进建议:将已废弃的 QRegExp 替换为性能更优的 QRegularExpression
void CmdTool::loadDmesgInfo(const QString &debugfile)
{
// 获取显存大小信息
QMap<QString, QString> mapInfo;
QStringList lines = deviceInfo.split("\n");
const bool isSpecialVRAM = Common::curVRAMType == Common::kSpecialVRAMType1;
bool hasCustomVRAMSize = false;
// 使用 QRegularExpression 替代 QRegExp 以提升匹配性能及规范性
QRegularExpression regCustom(".*([0-9a-z]{4}:[0-9a-z]{2}:[0-9a-z]{2}\\.[0-9]{1}):.*Video RAM[^0-9]*([0-9]+)[\\s]{0,1}M.*");
foreach (const QString &line, lines) {
if (isSpecialVRAM) {
QRegularExpressionMatch match = regCustom.match(line);
if (match.hasMatch()) {
double size = match.captured(2).toDouble();
QString sizeS = QString("%1GB").arg(size / 1024);
mapInfo["Size"] = match.captured(1) + "=" + sizeS;
hasCustomVRAMSize = true;
continue;
}
}
if (hasCustomVRAMSize)
continue;
// 原有逻辑也可同步替换为 QRegularExpression
QRegularExpression reg(".*([0-9a-z]{4}:[0-9a-z]{2}:[0-9a-z]{2}\\.[0-9]{1}):.*VRAM([=:]{1}) ([0-9]*)[\\s]{0,1}M.*");
QRegularExpressionMatch regMatch = reg.match(line);
if (regMatch.hasMatch()) {
// 后续原有赋值逻辑
}
}
} |
|
/merge |
|
This pr cannot be merged! (status: unstable) |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: max-lvs, Resurgamz 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 |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
255bef2
into
linuxdeepin:develop/eagle
Log: 通过 specialVRAMType 配置启用定制显存解析逻辑,匹配 dmesg 中的 Video RAM
字段并提取显存大小;Video RAM 与数值之间不再限制必须使用冒号分隔,兼容 Video RAM: 2048M、Video RAM
2048M 等格式。
Task: https://pms.uniontech.com/task-view-391143.html
Summary by Sourcery
Add configurable handling for parsing custom Video RAM formats from dmesg and integrate a new VRAM type flag into the device manager configuration.
New Features:
Bug Fixes:
Enhancements: