Repository navigation
perf: cache redundant command outputs in disk health check - #229
tianming-1996 wants to merge 1 commit into
Conversation
1. Root cause: getDeviceHardInfo called smartctl --all, hwinfo, and lshw multiple times via separate child functions, each spawning external processes redundantly and causing 40s+ response time 2. Fix: pre-execute smartctl --all, hwinfo --disk --only, and lshw -C disk once in getDeviceHardInfo, pass cached outputs to child functions via optional parameters with default values 3. Impact: reduces disk health check from 40s+ to 15-20s, existing callers using default params are unaffected Influence: 1. Test disk health check response time on SSD and HDD devices 2. Verify SMART info, model, and interface display correctly 3. Test with devices requiring -d sat fallback for smartctl 4. Verify no regression when functions called without cached params perf: 缓存磁盘健康检测中的冗余命令输出 1. 根因:getDeviceHardInfo 通过多个子函数分别调用 smartctl --all、 hwinfo 和 lshw,每个子函数独立执行外部命令导致 40s+ 响应时间 2. 方案:在 getDeviceHardInfo 中预执行 smartctl --all、 hwinfo --disk --only、lshw -C disk 各一次,通过带默认值的可选 参数将缓存结果传递给子函数复用 3. 影响:磁盘健康检测从 40s+ 降至 15-20s,使用默认参数的现有 调用方不受影响 Influence: 1. 测试 SSD 和 HDD 设备的磁盘健康检测响应时间 2. 验证 SMART 信息、型号和接口显示正确 3. 测试需要 -d sat 回退的 smartctl 设备 4. 验证不传缓存参数调用时无回归 PMS: BUG-275165
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: tianming-1996 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 (Utils::executCmd(\"lshw -C disk\", outPut, error) != 0) {",
" qDebug() << \"Failed to execute lshw command, error:\" << error;",
" exitcode = Utils::executCmd(\"lshw -C disk\", outPut, error);",
" qDebug() << \"Failed to execute lshw command, error:\" << error;"
],
"service/diskoperation/partedcore.cpp": [
" QString lshwOutput;",
" Utils::executCmd(\"lshw -C disk\", lshwOutput, error);",
" device.getDiskInfoFromLshw(devicepath, lshwOutput);",
" device.getDiskInfoModel(devicepath, device.m_model, smartctlOutput, lshwOutput);"
]
}
} |
Reviewer's GuideThe disk health-check aggregation path now executes smartctl, hwinfo, and lshw once and shares their outputs with the relevant parsers, reducing redundant process launches while keeping existing direct callers compatible through default parameters and preserving smartctl -d sat fallback behavior. Sequence diagram for cached disk health-check command outputssequenceDiagram
participant PartedCore
participant DeviceStorage
participant smartctl
participant hwinfo
participant lshw
PartedCore->>DeviceStorage: runSmartctlAll(devicepath, smartctlOutput)
DeviceStorage->>smartctl: smartctl --all devicepath
alt device type required
DeviceStorage->>smartctl: smartctl --all -d sat devicepath
end
PartedCore->>hwinfo: hwinfo --disk --only devicepath
PartedCore->>lshw: lshw -C disk
PartedCore->>DeviceStorage: getDiskInfoFromHwinfo(devicepath, hwinfoOutput)
PartedCore->>DeviceStorage: getDiskInfoFromLshw(devicepath, lshwOutput)
PartedCore->>DeviceStorage: getDiskInfoFromSmartCtl(devicepath, smartctlOutput, smartctlExitCode)
PartedCore->>DeviceStorage: getDiskInfoModel(devicepath, model, smartctlOutput, lshwOutput)
PartedCore->>DeviceStorage: getDiskInfoInterface(devicepath, interface, model, hwinfoOutput)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ❌评价: 存在逻辑缺陷 ❌ 不通过 潜在问题: 建议: ['1. 将 DeviceStorage.h 中 runSmartctlAll 的声明从 private: 移至 public: 区域,或为 PartedCore 添加 friend 声明,使其可被外部类调用。', '2. 为 getDiskInfoModel 增加 cachedExitCode 参数(与 getDiskInfoFromSmartCtl 保持一致),在缓存路径校验退出码,失败时提前返回。', '3. 在 partedcore.cpp 预执行 hwinfo/lshw 处检查 Utils::executCmd 返回值,失败时记录日志,避免空输出误导下游缓存判断。'] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['1. 删除 getDiskInfoModel 中未使用的 QString cmd; 声明。', '2. 让 runSmartctlAll 增加输出参数 QString &error,或将 qDebug 中的 << error 移除,避免打印空字符串。', '3. 将 cachedExitCode 默认值改为 -1,调用方未传时可在缓存路径识别并处理。'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: ['1. 预执行处检查 Utils::executCmd 返回值,失败时记录日志并保持缓存输出为空但明确不重试,或调整下游函数在缓存模式下不因空输出而重执行。'] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: ['无安全相关建议。'] 💡 改进建议代码示例// === DeviceStorage.h:将 runSmartctlAll 移至 public 区域 ===
class DeviceStorage
{
public:
DeviceStorage();
bool getDiskInfoFromHwinfo(const QString &devicePath, const QString &cachedOutput = QString());
bool getDiskInfoFromLshw(const QString &devicePath, const QString &cachedOutput = QString());
bool getDiskInfoFromLsblk(const QString &devicePath);
bool getDiskInfoFromSmartCtl(const QString &devicePath, const QString &cachedOutput = QString(), int cachedExitCode = -1);
void getDiskInfoModel(const QString &devicePath, QString &model,
const QString &cachedSmartctlOutput = QString(),
const QString &cachedLshwOutput = QString(),
int cachedSmartctlExitCode = -1);
QString getDiskInfoMediaType(const QString &devicePath);
void getDiskInfoInterface(const QString &devicePath, QString &interface, QString &model,
const QString &cachedHwinfoOutput = QString());
void updateForHWDevice(const QString &devicePath);
/**@brief:运行 smartctl --all 并处理 -d sat 重试,返回退出码*/
static int runSmartctlAll(const QString &devicePath, QString &outPut, QString &error = QString());
// ...
// === DeviceStorage.cpp:getDiskInfoModel 缓存路径校验退出码,移除未使用变量 ===
void DeviceStorage::getDiskInfoModel(const QString &devicePath, QString &model,
const QString &cachedSmartctlOutput,
const QString &cachedLshwOutput,
int cachedSmartctlExitCode)
{
qDebug() << "DeviceStorage::getDiskInfoModel BEGIN";
QString outPut, error;
int exitcode = 0;
if (cachedSmartctlOutput.isEmpty()) {
exitcode = runSmartctlAll(devicePath, outPut, error);
if (exitcode != 0) {
qDebug() << "Failed to execute smartctl command, error:" << error;
return;
}
} else {
outPut = cachedSmartctlOutput;
exitcode = cachedSmartctlExitCode;
if (exitcode != 0) {
qDebug() << "Cached smartctl command failed (exit code" << exitcode << "), skip parsing";
return;
}
}
// ... 解析逻辑保持不变 ...
}
// === partedcore.cpp:预执行检查退出码 ===
QString hwinfoOutput;
{
QString cmd = QString("hwinfo --disk --only %1").arg(devicepath);
QString error;
if (Utils::executCmd(cmd, hwinfoOutput, error) != 0) {
qDebug() << "Failed to pre-execute hwinfo command, error:" << error;
}
}
QString lshwOutput;
{
QString error;
if (Utils::executCmd("lshw -C disk", lshwOutput, error) != 0) {
qDebug() << "Failed to pre-execute lshw command, error:" << error;
}
}本报告由 AI 代码审查工具自动生成 |
|
TAG Bot New tag: 6.0.28 |
|
TAG Bot New tag: 6.0.29 |
|
TAG Bot New tag: 6.0.30 |
perf: cache redundant command outputs in disk health check
lshw multiple times via separate child functions, each spawning
external processes redundantly and causing 40s+ response time
lshw -C disk once in getDeviceHardInfo, pass cached outputs to
child functions via optional parameters with default values
callers using default params are unaffected
Influence:
perf: 缓存磁盘健康检测中的冗余命令输出
hwinfo 和 lshw,每个子函数独立执行外部命令导致 40s+ 响应时间
hwinfo --disk --only、lshw -C disk 各一次,通过带默认值的可选
参数将缓存结果传递给子函数复用
调用方不受影响
Influence:
PMS: BUG-275165
Summary by Sourcery
Enhancements: