Skip to content

perf: cache external command outputs in disk info gathering - #225

Open
wangrong1069 wants to merge 1 commit into
linuxdeepin:masterfrom
wangrong1069:agent/pms-bug-bot/6a75dbcd652a
Open

wangrong1069 wants to merge 1 commit into
linuxdeepin:masterfrom
wangrong1069:agent/pms-bug-bot/6a75dbcd652a

Conversation

@wangrong1069

@wangrong1069 wangrong1069 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

perf: cache external command outputs in disk info gathering

  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

Summary by Sourcery

Enhancements:

  • Cache smartctl, hwinfo, and lshw command output within each DeviceStorage instance to avoid repeated disk information queries and reduce dialog load time while preserving smartctl fallback handling.

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
@deepin-ci-robot

Copy link
Copy Markdown

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@github-actions

Copy link
Copy Markdown
  • 检测到敏感词lshw变动
详情
    {
    "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;"
        ]
    }
}

@sourcery-ai

sourcery-ai Bot commented Sep 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

Reduces 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 gathering

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Cache external command output per DeviceStorage instance and reuse it across disk-information helpers.
  • Added cached output strings and validity flags for smartctl, hwinfo, and lshw.
  • Updated command-consuming methods to execute only on cache misses and parse cached output otherwise.
  • Preserved smartctl SATA-device retry behavior and existing command failure handling.
service/diskoperation/DeviceStorage.cpp
service/diskoperation/DeviceStorage.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants