fix: [memory] Memory show error in special platform.#512
Conversation
-- Change the right way to get memory. Log: fix issue Bug: https://pms.uniontech.com/bug-view-328705.html
deepin pr auto review关键摘要:
是否建议立即修改:
|
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates GPU memory retrieval to use the /sys/kernel/debug/gc/total_mem file, replaces the previous SYSTEM0-specific parsing with a single generic regex that captures the numeric value and unit, and refactors unit conversion logic to consistently output GB. Class diagram for updated GPU memory retrieval logicclassDiagram
class main {
}
class getGpuMemInfoForFTDTM {
+bool getGpuMemInfoForFTDTM(QMap<QString, QString> &mapInfo)
}
main --> getGpuMemInfoForFTDTM
getGpuMemInfoForFTDTM : -const QString filePath
getGpuMemInfoForFTDTM : -QString totalValue
getGpuMemInfoForFTDTM : +QFile file
getGpuMemInfoForFTDTM : +QRegularExpression regex
getGpuMemInfoForFTDTM : +QRegularExpressionMatch memInfoMatch
getGpuMemInfoForFTDTM : +double value
getGpuMemInfoForFTDTM : +QString unit
getGpuMemInfoForFTDTM : +mapInfo.insert(kGraphicsMemory, totalValue)
Flow diagram for new GPU memory info extraction and conversionflowchart TD
A[Open /sys/kernel/debug/gc/total_mem] -->|Success| B[Read file content]
B --> C[Apply regex to extract value and unit]
C --> D{Unit type}
D -->|MB| E[Convert value to GB]
D -->|GB| F[Use value as GB]
D -->|KB| G[Convert value to GB]
D -->|B| H[Convert value to GB]
E --> I[Insert into mapInfo]
F --> I
G --> I
H --> I
D -->|No match| J[Log error and return false]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @GongHeng2017 - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `deepin-devicemanager-server/customgpuinfo/main.cpp:80` </location>
<code_context>
- } else {
- totalValue = QString::number(memSize) + "MB";
- }
+ double value = memInfoMatch.captured(1).toDouble();
+ QString unit = memInfoMatch.captured(2).toUpper();
+
+ if (unit == "MB") {
</code_context>
<issue_to_address>
Consider validating the conversion result of toDouble for robustness.
Using the overload with a bool allows you to detect conversion failures and handle them appropriately, improving error handling.
</issue_to_address>
### Comment 2
<location> `deepin-devicemanager-server/customgpuinfo/main.cpp:93` </location>
<code_context>
+ totalValue = QString("%1GB").arg(value / (1024.0 * 1024.0 * 1024.0), 0, 'f', 2);
}
mapInfo.insert(kGraphicsMemory, totalValue);
</code_context>
<issue_to_address>
totalValue may be empty if the unit is not recognized.
If the unit is not MB, GB, KB, or B, totalValue will be empty and mapInfo will contain an empty string. Add an else branch to handle unknown units and log a warning.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, 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 |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
41df0c9
into
linuxdeepin:develop/eagle
-- Change the right way to get memory.
Log: fix issue
Bug: https://pms.uniontech.com/bug-view-328705.html
Summary by Sourcery
Fix GPU memory info retrieval by using the correct debug file path and simplifying the parsing logic
Bug Fixes:
Enhancements: