Skip to content

chore: More logs for application#154

Merged
re2zero merged 1 commit into
linuxdeepin:masterfrom
re2zero:bugfix
Jul 7, 2025
Merged

chore: More logs for application#154
re2zero merged 1 commit into
linuxdeepin:masterfrom
re2zero:bugfix

Conversation

@re2zero
Copy link
Copy Markdown
Contributor

@re2zero re2zero commented Jul 3, 2025

Add more logs for application. 86.21%

Log: More logs for application.

Summary by Sourcery

Add extensive qDebug logging throughout the application to record method entry points, key variable values, branching decisions and D-Bus interactions for better traceability.

Enhancements:

  • Instrument CreateVGWidget methods with debug logs for UI initialization, connection setup, data operations and LVM actions
  • Add qDebug statements to PartitionWidget, CreateLVWidget, ResizeDialog and DiskBadSectorsDialog to log user interactions and state changes
  • Enhance DMDbusHandler with logs for instance creation, meta-type registration, D-Bus calls and signal handlers
  • Log selection changes, menu actions and theme updates in TitleWidget, DeviceListWidget, InfoShowWidget, VGSizeInfoWidget, CylinderInfoWidget and DmTreeview
  • Introduce logging in dialogs and utilities (DecryptDialog, FormateDialog, CreatePartitionTableDialog, AccessibleWidget and Common::getIcon) to capture flow and parameters

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jul 3, 2025

Reviewer's Guide

This PR instruments the application with comprehensive qDebug() logging, adding entry/exit traces, parameter dumps, and decision-point logs across UI widgets, dialogs, D-Bus handler, and tree view components to improve runtime diagnostics.

Class diagram for logging instrumentation in UI widgets and dialogs

classDiagram
    class CreateVGWidget {
        +initUi()
        +initConnection()
        +setScrollAreaAttribute()
        +judgeDataEquality()
        +showLoadingWidget()
        +getVGName()
        +getCurSelectPVData()
        +onDoneButtonClicked()
        +onCancelButtonClicked()
        +updateData()
        +createAvailableDiskData()
        +resizeAvailableDiskData()
        +onDiskItemClicked()
        +updatePartitionData()
        +onDiskCheckBoxStateChange()
        +onPartitionCheckBoxStateChange()
        +getCurSizeUnit()
        +updateSelectedData()
        +onDeleteItemClicked()
        +onCurrentIndexChanged()
        +onTextChanged()
        +onVGCreateMessage()
        +onUpdateUsb()
        +getPVSize()
        +getDevSize()
        +getMaxSize()
        +getMinSize()
        +adjudicationPVMove()
        <<Instrumented with qDebug logs>>
    }
    class PartitionWidget {
        +initUi()
        +topFrameSetting()
        +midFrameSetting()
        +botFrameSetting()
        +partInfoShowing()
        +recPartitionInfo()
        +initConnection()
        +sumValue()
        +setSelectUnallocatesSpace()
        +setAddOrRemResult()
        +setRegValidator()
        +maxAmountPrimReached()
        +onShowSelectPathInfo()
        +onShowTip()
        +setEnable()
        +setControlEnable()
        +setLabelColor()
        +onComboxCurTextChange()
        +onComboxFormatTextChange()
        +onJudgeLastPartition()
        +onSliderValueChanged()
        +onSetSliderValue()
        +onTextChanged()
        +onSetPartName()
        +onAddPartition()
        +onRemovePartition()
        +onApplyButton()
        +onRevertButton()
        +onCancelButton()
        +event()
        +keyPressEvent()
        <<Instrumented with qDebug logs>>
    }
    class DecryptDialog {
        +initUi()
        +initConnection()
        +initData()
        +setPasswordEditStatus()
        +updateData()
        +onPasswordEditTextChanged()
        +onPasswordHintButtonClicked()
        +onCancelButtonClicked()
        +onButtonClicked()
        +onDecryptMessage()
        +onTimeOut()
        +keyPressEvent()
        <<Instrumented with qDebug logs>>
    }
    class VGInfoShowWidget {
        +initUi()
        +initConnection()
        +setData()
        <<Instrumented with qDebug logs>>
    }
Loading

File-Level Changes

Change Details Files
Insert debug logging at key points in CreateVGWidget to trace UI initialization, connections, data operations, and control flows
  • Added qDebug() at the start and end of initUi/initConnection
  • Logged parameters and branch decisions in setScrollAreaAttribute, judgeDataEquality, showLoadingWidget
  • Traced operations in onNext/Done/Cancel button handlers and selection change callbacks
application/widgets/createvgwidget.cpp
Expand DMDbusHandler with qDebug traces for D-Bus setup and calls
  • Logged instance creation and destructor events
  • Added logs around meta-type registration and D-Bus signal connections
  • Traced every D-Bus method call and event handler with parameters and results
application/partedproxy/dmdbushandler.cpp
Add detailed logging to major dialogs and widgets (PartitionWidget, CreateLVWidget, ResizeDialog, DiskBadSectorsDialog, DecryptDialog, FormateDialog, DeviceListWidget, DmTreeview)
  • Logged UI setup and connection initialization
  • Inserted qDebug in user actions and validation branches
  • Traced data updates, error conditions, and completion states
application/widgets/customcontrol/partitionwidget.cpp
application/widgets/createlvwidget.cpp
application/widgets/resizedialog.cpp
application/widgets/diskbadsectorsdialog.cpp
application/widgets/decryptdialog.cpp
application/widgets/formatedialog.cpp
application/widgets/devicelistwidget.cpp
application/widgets/customcontrol/dmtreeview.cpp
Instrument InfoShowWidget and VGSizeInfoWidget with theme and data rendering logs
  • Logged theme changes and data distribution in paintEvent
  • Traced enter/leave events for tooltips
application/widgets/infoshowwidget.cpp
application/widgets/customcontrol/vgsizeinfowidget.cpp
Enhance accessibility and keyboard event debugging
  • Added qDebug in AccessibleWidget interface casts and text methods
  • Traced keyPressEvent logic in dialogs and widgets
application/widgets/accessible/accessiblewidget.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

Copy link
Copy Markdown

@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 @re2zero - I've reviewed your changes - here's some feedback:

  • The PR adds a qDebug call in nearly every method and branch, which will flood the logs and hurt performance—please trim down to only key entry/exit or error events and consider using function-entry/exit macros instead of manual statements everywhere.
  • Introduce QLoggingCategory (and qCDebug/qCWarning) so you can selectively enable or disable logs by module, rather than sprinkling qDebug unconditionally.
  • Guard verbose debug logging behind a DEBUG or DEVELOPMENT build flag (or use Qt’s logging rules) to avoid shipping performance-heavy debug output in production.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The PR adds a qDebug call in nearly every method and branch, which will flood the logs and hurt performance—please trim down to only key entry/exit or error events and consider using function-entry/exit macros instead of manual statements everywhere.
- Introduce QLoggingCategory (and qCDebug/qCWarning) so you can selectively enable or disable logs by module, rather than sprinkling qDebug unconditionally.
- Guard verbose debug logging behind a DEBUG or DEVELOPMENT build flag (or use Qt’s logging rules) to avoid shipping performance-heavy debug output in production.

## Individual Comments

### Comment 1
<location> `application/widgets/infoshowwidget.cpp:661` </location>
<code_context>
         QVector<double> size {usedSize, unusedSize};
         m_infoWidget->setData(lvInfo, color, size, 1);
     }
+    qDebug() << "InfoShowWidget::onHandleChangeTheme() called.";
 }

</code_context>

<issue_to_address>
Debug output in theme change handlers may be unnecessary in production.

Frequent theme changes could lead to excessive logging. Please remove or conditionally compile this debug statement for production builds.
</issue_to_address>

### Comment 2
<location> `application/partedproxy/dmdbushandler.cpp:972` </location>
<code_context>
+            qDebug() << "CRYPT_ERR_CLOSE_FAILED for" << devPath;
             break;
         }
+        default:
+            qDebug() << "Unknown CRYPTError value:" << value;
+            break;
         }
</code_context>

<issue_to_address>
Logging unknown enum values is useful, but consider error handling.

Consider handling unknown enum values explicitly, such as by notifying the user or implementing a fallback, in addition to logging.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
        case CRYPTError::CRYPT_ERR_CLOSE_FAILED: {
            failedMessage = tr("%1 failed to close the crypto map").arg(devPath);
            qDebug() << "CRYPT_ERR_CLOSE_FAILED for" << devPath;
            break;
        }
=======
        case CRYPTError::CRYPT_ERR_CLOSE_FAILED: {
            failedMessage = tr("%1 failed to close the crypto map").arg(devPath);
            qDebug() << "CRYPT_ERR_CLOSE_FAILED for" << devPath;
            break;
        }
        default: {
            qDebug() << "Unknown CRYPTError value:" << value;
            failedMessage = tr("An unknown cryptographic error occurred for %1. Please contact support.").arg(devPath);
            // Optionally, you could trigger a user notification here if your UI supports it.
            break;
        }
>>>>>>> REPLACE

</suggested_fix>

### Comment 3
<location> `application/widgets/cylinderinfowidget.cpp:158` </location>
<code_context>

 void CylinderInfoWidget::againVerify(int cylNumber)
 {
+    qDebug() << "[CylinderInfoWidget] againVerify called with cylinder number:" << cylNumber;
     m_curCheckCount = 0;
     m_badSectorsCount = 0;
</code_context>

<issue_to_address>
Debug logging in UI update and loop-heavy code may cause performance issues.

Consider wrapping qDebug() statements in a debug flag or using a logging mechanism that can be toggled to avoid excessive output during widget iteration.

Suggested implementation:

```cpp
    setLayout(mainLayout);

    m_settings = new QSettings("/tmp/CheckData.conf", QSettings::IniFormat, this);
    m_debugLoggingEnabled = false; // Default: debug logging off
    if (m_debugLoggingEnabled) {
        qDebug() << "[CylinderInfoWidget] CylinderInfoWidget initialized.";
    }
}

```

```cpp
void CylinderInfoWidget::againVerify(int cylNumber)
{
    if (m_debugLoggingEnabled) {
        qDebug() << "[CylinderInfoWidget] againVerify called with cylinder number:" << cylNumber;
    }
    m_curCheckCount = 0;
    m_badSectorsCount = 0;
    m_scrollBar->hide();
    m_isChanged = false;
    m_startCylinder = m_settings->value("SettingData/BlockStart").toInt();
    m_endCylinder = m_settings->value("SettingData/BlockEnd").toInt();
    if (m_debugLoggingEnabled) {
        qDebug() << "[CylinderInfoWidget] Initialized for re-verification, start cylinder:" << m_startCylinder << ", end cylinder:" << m_endCylinder;
    }

    QList<QObject *> lstCylinderWidget = m_widget->children();
    if (m_debugLoggingEnabled) {
        qDebug() << "[CylinderInfoWidget] Current cylinder widget count:" << lstCylinderWidget.count();
    }

    if (cylNumber <= lstCylinderWidget.count() - 1) { // 当将要重新检测的个数小于等于360时

```

You must add a `bool m_debugLoggingEnabled;` member to the `CylinderInfoWidget` class in the corresponding header file (`cylinderinfowidget.h`). Optionally, provide a public setter method to allow toggling debug logging at runtime:

```cpp
void setDebugLoggingEnabled(bool enabled) { m_debugLoggingEnabled = enabled; }
```
</issue_to_address>

### Comment 4
<location> `application/main.cpp:81` </location>
<code_context>
+    qDebug() << "executCmd called with command:" << strCmd;
     QProcess proc;
 #if QT_VERSION_MAJOR > 5
+    qDebug() << "QT_VERSION_MAJOR > 5, using split command start.";
     QStringList list = strCmd.split(" ");
     proc.start(list.at(0), QStringList() << list.at(1));
 #else
+    qDebug() << "QT_VERSION_MAJOR <= 5, using direct command start.";
     proc.start(strCmd);
 #endif
</code_context>

<issue_to_address>
Command splitting in executCmd may not handle arguments with spaces or special characters.

Splitting the command by spaces and using only the first two elements can break when arguments contain spaces or special characters. Use a more reliable parsing method or pass the full command string to QProcess.
</issue_to_address>

### Comment 5
<location> `application/widgets/customcontrol/passwordinputdialog.cpp:175` </location>
<code_context>

 void PasswordInputDialog::setTitleText(const QString &text)
 {
+    qDebug() << "PasswordInputDialog::setTitleText called with text:" << text;
+    // This function seems to be empty, so no action needed other than logging.
+    qDebug() << "PasswordInputDialog::setTitleText finished";
 }

</code_context>

<issue_to_address>
Logging in a function that performs no action may be unnecessary.

If this function is intended for future use, add a TODO comment. Otherwise, consider removing it to avoid unnecessary code.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
void PasswordInputDialog::setTitleText(const QString &text)
{
+    qDebug() << "PasswordInputDialog::setTitleText called with text:" << text;
+    // This function seems to be empty, so no action needed other than logging.
+    qDebug() << "PasswordInputDialog::setTitleText finished";
}
=======
void PasswordInputDialog::setTitleText(const QString &text)
{
    // TODO: Implement setTitleText functionality if needed in the future.
}
>>>>>>> REPLACE

</suggested_fix>

### Comment 6
<location> `application/widgets/customcontrol/waterloadingwidget.cpp:58` </location>
<code_context>
     int value = (m_waterProgress->value() + qrand() % 10);
+    qDebug() << "QT_VERSION_MAJOR <= 5, generated value:" << value;
 #endif
     value > 99 ? value = 99 : value;
     m_waterProgress->setValue(value);
+    qDebug() << "Water progress value set to:" << value;
</code_context>

<issue_to_address>
The ternary expression does not assign the result; use an if-statement instead.

The current ternary expression does not update 'value' when 'value <= 99'. Use 'if (value > 99) value = 99;' for correct behavior and better readability.
</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.

Comment thread application/widgets/infoshowwidget.cpp Outdated
Comment thread application/partedproxy/dmdbushandler.cpp
Comment thread application/widgets/cylinderinfowidget.cpp
Comment thread application/main.cpp
Comment thread application/widgets/customcontrol/passwordinputdialog.cpp
Comment thread application/widgets/customcontrol/waterloadingwidget.cpp
Add more logs for application. 86.21%

Log: More logs for application.
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@re2zero re2zero merged commit 55eaaa7 into linuxdeepin:master Jul 7, 2025
16 of 17 checks passed
@re2zero re2zero deleted the bugfix branch July 7, 2025 06:03
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