perf: cache external command outputs in disk info gathering - #225
Open
wangrong1069 wants to merge 1 commit into
Open
wangrong1069 wants to merge 1 commit into
wangrong1069 wants to merge 1 commit into
Conversation
1. getDeviceHardInfo() calls smartctl --all, hwinfo --disk, lshw -C disk each twice via different methods, all serial, causing 5-6s delay 2. Add cache members to DeviceStorage so the first method to run a command stores its output; later methods reuse the cached result 3. Cache is per-object (DeviceStorage is created fresh per call), so no stale data risk; smartctl retry logic (-d sat) is preserved Influence: 1. Open disk info dialog and verify all fields display correctly 2. Verify dialog opens significantly faster (target under 3s) 3. Test with SATA, NVMe, and USB disks for field accuracy perf: 缓存外部命令输出以优化磁盘信息获取 1. getDeviceHardInfo() 中 smartctl --all、hwinfo --disk、lshw -C disk 各被重复调用1次且全部串行执行,导致磁盘信息对话框5-6秒延迟 2. 在 DeviceStorage 中增加缓存成员变量,首个执行命令的方法缓存 其输出,后续方法直接复用缓存结果,消除3次重复调用 3. 缓存为对象级(DeviceStorage 每次调用新建),无脏数据风险; smartctl 重试逻辑(-d sat)保持不变 Influence: 1. 打开磁盘信息对话框,验证各字段(型号、接口、转速等)显示正确 2. 验证对话框打开速度明显提升(目标3秒以内) 3. 对 SATA、NVMe、USB 不同类型磁盘测试信息获取准确性 PMS: BUG-327615
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: wangrong1069 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 |
|
Warning
详情 {
"lshw": {
"service/diskoperation/DeviceStorage.cpp": [
" if (!m_lshwOutputCached) {",
" if (Utils::executCmd(\"lshw -C disk\", m_cachedLshwOutput, error) != 0) {",
" qDebug() << \"Failed to execute lshw command, error:\" << error;",
" m_lshwOutputCached = true;",
" if (!m_lshwOutputCached) {",
" if (Utils::executCmd(\"lshw -C disk\", m_cachedLshwOutput, error) != 0) {",
" qDebug() << \"Failed to execute lshw command, error:\" << error;",
" m_lshwOutputCached = true;"
],
"service/diskoperation/DeviceStorage.h": [
" bool m_lshwOutputCached = false;"
]
}
} |
Reviewer's GuideReduces disk information dialog latency by avoiding repeated serial smartctl, hwinfo, and lshw executions within a DeviceStorage instance, while retaining existing parsing, retry, and error-handling behavior. Sequence diagram for cached disk information gatheringsequenceDiagram
participant DeviceStorage
participant Utils
participant smartctl
participant hwinfo
participant lshw
DeviceStorage->>Utils: executCmd(smartctl --all)
Utils->>smartctl: run command
smartctl-->>Utils: output
alt device type required
DeviceStorage->>Utils: executCmd(smartctl --all -d sat)
Utils->>smartctl: retry command
smartctl-->>Utils: output
end
Utils-->>DeviceStorage: cache m_cachedSmartctlOutput
DeviceStorage->>DeviceStorage: getDiskInfoFromSmartCtl()
DeviceStorage->>DeviceStorage: getDiskInfoModel()
Note over DeviceStorage: Reuse cached smartctl output
DeviceStorage->>Utils: executCmd(hwinfo --disk --only devicePath)
Utils->>hwinfo: run command
hwinfo-->>Utils: output
Utils-->>DeviceStorage: cache m_cachedHwinfoOutput
DeviceStorage->>DeviceStorage: getDiskInfoFromHwinfo()
DeviceStorage->>DeviceStorage: getDiskInfoInterface()
Note over DeviceStorage: Reuse cached hwinfo output
DeviceStorage->>Utils: executCmd(lshw -C disk)
Utils->>lshw: run command
lshw-->>Utils: output
Utils-->>DeviceStorage: cache m_cachedLshwOutput
DeviceStorage->>DeviceStorage: parse disk information
Note over DeviceStorage: Reuse cached lshw output
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
perf: cache external command outputs in disk info gathering
each twice via different methods, all serial, causing 5-6s delay
command stores its output; later methods reuse the cached result
stale data risk; smartctl retry logic (-d sat) is preserved
Influence:
perf: 缓存外部命令输出以优化磁盘信息获取
各被重复调用1次且全部串行执行,导致磁盘信息对话框5-6秒延迟
其输出,后续方法直接复用缓存结果,消除3次重复调用
smartctl 重试逻辑(-d sat)保持不变
Influence:
PMS: BUG-327615
Summary by Sourcery
Enhancements: