Skip to content

chore: clean up verbose debug logs in device detection#103

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
itsXuSt:v25
Jan 13, 2026
Merged

chore: clean up verbose debug logs in device detection#103
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
itsXuSt:v25

Conversation

@itsXuSt
Copy link
Contributor

@itsXuSt itsXuSt commented Jan 13, 2026

  • Remove step-by-step debug logs in ListUsbDrives()
  • Consolidate device detection output to single summary line
  • Clean up debug logs for Windows, Linux and Mac platforms

Log: Remove redundant debug logs during USB device enumeration

Summary by Sourcery

Clean up USB device detection logging to reduce verbosity while preserving a concise summary of detected devices.

Enhancements:

  • Remove verbose, step-by-step debug logging from USB drive enumeration across Windows, Linux, and macOS.
  • Log a single summarized line of detected USB devices in the device monitor instead of per-device debug entries.

- Remove step-by-step debug logs in ListUsbDrives()
- Consolidate device detection output to single summary line
- Clean up debug logs for Windows, Linux and Mac platforms

Log: Remove redundant debug logs during USB device enumeration
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 13, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Cleans up verbose USB device detection logging across platforms by removing step-by-step debug output in the low-level enumeration function and consolidating reporting into a single summary log line in the device monitor.

Sequence diagram for consolidated USB device detection logging

sequenceDiagram
    participant QTimer
    participant DeviceMonitor
    participant Utils
    participant OS
    participant Logger

    QTimer->>DeviceMonitor: timeout()
    DeviceMonitor->>Utils: ListUsbDrives()
    Utils->>OS: enumerate_usb_devices()
    OS-->>Utils: deviceList_raw
    Utils-->>DeviceMonitor: deviceList
    DeviceMonitor->>DeviceMonitor: collect device paths into devices
    DeviceMonitor->>Logger: qDebug Detected deviceList.size() USB devices: devices
Loading

File-Level Changes

Change Details Files
Reduce verbose logging in low-level USB enumeration logic while preserving functional behavior.
  • Remove initial ListUsbDrives() entry debug statements.
  • Delete per-drive/per-partition debug prints during Linux device filtering and partition handling.
  • Remove per-device discovery logs on Windows and macOS, including final detailed device list dumps.
src/libdbm/util/utils.cpp
Consolidate device detection output into a single summary log in the monitoring code.
  • Replace per-device debug logging in the timer callback with collection of device paths.
  • Log a single summary line showing count of detected USB devices plus their paths.
src/libdbm/util/devicemonitor.cpp

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

@deepin-ci-robot
Copy link

deepin pr auto review

Git Diff 代码审查报告

整体评价

本次代码修改的主要目的是清理 ListUsbDrives() 函数中的调试日志输出,并简化 DeviceMonitor 中的设备信息打印。修改后的代码更加简洁,减少了不必要的日志输出,这对于生产环境是有益的。

详细审查

1. devicemonitor.cpp 修改

修改内容:

  • 将详细的设备信息打印改为只打印设备路径列表
  • 简化了日志输出格式

优点:

  • 减少了日志输出量,避免日志过多影响性能
  • 保留了基本的设备检测信息,便于问题排查

建议:

  • 考虑使用更高效的容器操作,如基于范围的for循环或Qt的foreach
  • 可以考虑使用 join() 方法来构建设备路径字符串

2. utils.cpp 修改

修改内容:

  • 移除了 ListUsbDrives() 函数中大量的调试日志输出
  • 保留了核心功能逻辑不变

优点:

  • 大幅减少了日志输出,提高了函数执行效率
  • 代码更简洁,可读性更好
  • 减少了不必要的字符串操作,提升了性能

建议:

  • 考虑使用条件编译或日志级别控制,以便在需要时可以开启详细日志
  • 对于关键操作(如设备发现)可以保留少量日志,便于问题诊断

具体改进建议

1. 语法和逻辑

代码语法正确,逻辑清晰,没有明显问题。

2. 代码质量

devicemonitor.cpp:

// 原代码
for (int i = 0; i < list.size(); i++)
{
    devices << list.at(i).path;
}
qDebug() << "Detected" << list.length() << "USB devices: " << devices;

// 建议改进
for (const auto &device : list) {
    devices << device.path;
}
qDebug() << "Detected" << list.size() << "USB devices:" << devices.join(", ");

3. 性能优化

  1. 使用基于范围的for循环:

    • 使用 for (const auto &device : list) 替代索引循环
    • 避免不必要的 at() 调用
  2. 字符串操作优化:

    • 使用 join() 方法构建设备路径字符串,比多次输出更高效
  3. 日志输出优化:

    • 考虑使用日志级别控制,如 qDebug()qInfo()qWarning()
    • 可以添加条件编译,在调试模式下输出详细日志

4. 安全性

  1. 输入验证:

    • 确保从系统获取的设备路径经过适当验证
    • 检查设备路径是否存在和可访问
  2. 错误处理:

    • 添加对关键操作的错误处理
    • 考虑添加异常处理机制
  3. 日志敏感信息:

    • 确保日志中不包含敏感信息
    • 虽然本次修改减少了日志输出,但未来添加日志时需注意

总结

本次修改主要是清理调试日志,提高了代码简洁性和执行效率。建议考虑以下几点进一步改进:

  1. 使用更现代的C++/Qt语法,如基于范围的for循环
  2. 实现日志级别控制,便于不同环境下的日志管理
  3. 添加适当的错误处理和输入验证
  4. 考虑使用 join() 方法优化字符串操作

总体而言,修改方向正确,代码质量良好,没有明显的安全问题。

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/libdbm/util/utils.cpp:519` </location>
<code_context>

     QMap<QString, DeviceInfo> dfDeviceInfos = CommandDfParse();
     QMap<QString, DeviceInfo> lsblkDeviceInfos = CommandLsblkParse();
@@ -518,13 +514,7 @@ QList<DeviceInfo> ListUsbDrives()
             removeDevice.insert(filePath, fileName);
         }
     }
-    qDebug() << "Step 4: Filter devices - Found" << removeDevice.size() << "USB/MMC devices from" << usbfileinfoL.size() << "total devices";

-    for (auto it = removeDevice.begin(); it != removeDevice.end(); ++it) {
-        qDebug() << "  Device path:" << it.key() << "Device name:" << it.value();
-    }
-
-    qDebug() << "Step 5: Traverse device partitions and filter eligible devices";
     int processedCount = 0;
     int validCount = 0;

</code_context>

<issue_to_address>
**suggestion:** Consider removing or repurposing processedCount/validCount now that they’re only used for logging.

Now that the related logging is gone, `processedCount` and `validCount` are maintained only for unused debug output, which adds noise and potential confusion. If they’re not used elsewhere, consider removing them or giving them a clear functional role (for example, asserting that `deviceList.size()` equals `validCount`).

Suggested implementation:

```cpp

```

```cpp

```

```cpp

```

1. If there are any remaining references to `processedCount` or `validCount` (e.g., in `qDebug()` or assertions) later in `ListUsbDrives()`, those should be removed or refactored as well.
2. If you do want a functional role for such counters, reintroduce them with a clear purpose (for instance, `int validDevices = deviceList.size(); Q_ASSERT(validDevices == deviceList.size());`) instead of maintaining separate counters throughout the loop.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.


qDebug() << "Step 5: Traverse device partitions and filter eligible devices";
int processedCount = 0;
int validCount = 0;
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider removing or repurposing processedCount/validCount now that they’re only used for logging.

Now that the related logging is gone, processedCount and validCount are maintained only for unused debug output, which adds noise and potential confusion. If they’re not used elsewhere, consider removing them or giving them a clear functional role (for example, asserting that deviceList.size() equals validCount).

Suggested implementation:

  1. If there are any remaining references to processedCount or validCount (e.g., in qDebug() or assertions) later in ListUsbDrives(), those should be removed or refactored as well.
  2. If you do want a functional role for such counters, reintroduce them with a clear purpose (for instance, int validDevices = deviceList.size(); Q_ASSERT(validDevices == deviceList.size());) instead of maintaining separate counters throughout the loop.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: itsXuSt, lzwind

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

@itsXuSt
Copy link
Contributor Author

itsXuSt commented Jan 13, 2026

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Jan 13, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 5b703d0 into linuxdeepin:master Jan 13, 2026
16 of 18 checks passed
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.

3 participants