Skip to content

fix: [log] verbosity configuration initialization order#438

Merged
deepin-bot[bot] merged 2 commits intolinuxdeepin:masterfrom
lichaofan2008:master3
Dec 18, 2025
Merged

fix: [log] verbosity configuration initialization order#438
deepin-bot[bot] merged 2 commits intolinuxdeepin:masterfrom
lichaofan2008:master3

Conversation

@lichaofan2008
Copy link
Contributor

@lichaofan2008 lichaofan2008 commented Dec 17, 2025

  • Added verbosity field to config structure for persistent storage
  • Fixed initialization sequence to load verbosity from config before updating options
  • Ensured debug level is set from saved configuration rather than default options
  • Maintained configuration file compatibility with new verbosity parameter

Log: Fix debug level configuration loading sequence

v20 BUG 分支合一到v25主线
Task: https://pms.uniontech.com/task-view-383481.html

Summary by Sourcery

Persist and load the log verbosity level through the camera configuration so the runtime debug level respects saved settings.

New Features:

  • Add a verbosity field to the camera configuration for persistent log level storage.

Bug Fixes:

  • Correct the initialization sequence so the debug level is derived from the loaded configuration instead of default options.

Enhancements:

  • Update config save/load and option update logic to handle verbosity while keeping existing configuration compatibility.

- Added verbosity field to config structure for persistent storage
- Fixed initialization sequence to load verbosity from config before
updating options
- Ensured debug level is set from saved configuration rather than
default options
- Maintained configuration file compatibility with new verbosity
parameter

Log: Fix debug level configuration loading sequence

v20 BUG 分支合一到v25主线
Task: https://pms.uniontech.com/task-view-383481.html
@sourcery-ai
Copy link

sourcery-ai bot commented Dec 17, 2025

Reviewer's Guide

Adds a persistent verbosity field to the camera configuration, wires it through load/save/update, and changes initialization so the debug log level is taken from the saved config before options are applied.

Sequence diagram for updated camInit configuration and debug level initialization

sequenceDiagram
    participant camInit
    participant config_module
    participant options_t
    participant config_t
    participant debug_level

    camInit->>config_module: config_load(config_file)
    activate config_module
    config_module->>config_t: populate_from_file(verbosity, other_fields)
    deactivate config_module

    camInit->>config_module: config_get()
    config_module-->>camInit: config_t

    camInit->>debug_level: set_from(config_t.verbosity)
    camInit->>options_t: options_t.verbosity = config_t.verbosity

    camInit->>config_module: config_update(options_t)
    activate config_module
    config_module->>config_t: apply_options_verbosity(options_t.verbosity)
    deactivate config_module
Loading

Class diagram for updated camera configuration verbosity handling

classDiagram
    class config_t {
        char* device_name
        char* device_location
        uint32_t format
        char* render
        char* gui
        char* audio
        char* capture
        char* video_codec
        char* audio_codec
        char* profile_name
        char* profile_path
        char* video_name
        char* video_path
        char* photo_name
        char* photo_path
        int video_sufix
        int photo_sufix
        int fps_num
        int fps_denom
        int audio_device
        uint32_t video_fx
        uint32_t audio_fx
        uint32_t osd_mask
        uint32_t crosshair_color
        int verbosity
    }

    class options_t {
        int verbosity
    }

    class debug_level {
        int level
    }

    config_t "1" -- "1" options_t : synchronized_verbosity
    debug_level "1" -- "1" config_t : initialized_from
    debug_level "1" -- "1" options_t : updated_to_match
Loading

File-Level Changes

Change Details Files
Introduce verbosity as a persisted configuration field and ensure it is serialized/deserialized.
  • Extend config_t with an int verbosity member and initialize it with a default value in the static my_config instance.
  • Write verbosity to the config file during config_save alongside other fields.
  • Parse a verbosity key from the config file in config_load and store it into my_config.verbosity.
libcam/libcam/cameraconfig.h
libcam/libcam/cameraconfig.c
Adjust configuration update logic to respect explicit verbosity options while keeping config as the source of truth.
  • In config_update, copy verbosity from options into my_config only if the options verbosity is non-negative.
  • Ensure option-driven verbosity still overrides persisted config when explicitly set by the caller.
libcam/libcam/cameraconfig.c
Fix initialization order so debug_level is derived from configuration rather than raw options.
  • In camInit, load configuration from disk, then retrieve my_config and set debug_level from my_config->verbosity.
  • Mirror my_config->verbosity back into my_options->verbosity before calling config_update so options and config remain consistent.
  • Move the config_update call after debug_level initialization to guarantee the saved config influences the log level.
src/src/LPF_V4L2.c

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

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

  • There’s a new tab/space inconsistency introduced in config_save (the setlocale line is now indented with a tab and misaligned relative to surrounding code); please align it with the existing indentation style in this file.
  • Now that verbosity is persisted and read from config, double-check that any default/initial values for config_t.verbosity and options_t.verbosity are consistently initialized so debug_level is never derived from an unintentionally uninitialized or sentinel value.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- There’s a new tab/space inconsistency introduced in `config_save` (the `setlocale` line is now indented with a tab and misaligned relative to surrounding code); please align it with the existing indentation style in this file.
- Now that `verbosity` is persisted and read from config, double-check that any default/initial values for `config_t.verbosity` and `options_t.verbosity` are consistently initialized so `debug_level` is never derived from an unintentionally uninitialized or sentinel value.

## Individual Comments

### Comment 1
<location> `libcam/libcam/cameraconfig.c:315-317` </location>
<code_context>
                 free(my_config.photo_path);
             my_config.photo_path = strdup(value);
         }
+        else if(strcmp(token, "verbosity") == 0)
+        {
+            my_config.verbosity = (int) strtoul(value, NULL, 10);
+        }
 //		else if(strcmp(token, "video_sufix") == 0)
</code_context>

<issue_to_address>
**issue (bug_risk):** Parsing verbosity with strtoul and casting to int can mis-handle negative or out-of-range values.

Using `strtoul` here means negative inputs are parsed as large positive values, and very large values can overflow when cast to `int` (implementation-defined). If you need to support negative sentinel values or just ensure safe bounds, prefer `strtol`, validate the range against `INT_MIN`/`INT_MAX`, and clamp or reject invalid values before assigning to `my_config.verbosity`.
</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.

…e logging

- Add decode performance monitoring that measures and logs decode time every 5 operations
- Reduce verbose logging frequency in JPEG decoder to print every 5th frame instead of every frame
- Include QElapsedTimer header for timing functionality
- Maintain existing behavior when verbosity is disabled

v20 BUG 分支合一到v25主线
Task: https://pms.uniontech.com/task-view-383481.html
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这个 diff 进行详细的代码审查:

  1. 代码逻辑和功能改进:
  • 添加了 verbosity 配置项,用于控制日志输出的详细程度
  • 实现了日志输出的间隔控制,避免频繁输出影响性能
  • 优化了配置文件的加载和更新顺序
  1. 代码质量问题:
  • 在 jpeg_decoder.c 中使用静态变量 decodeCount 可能会导致线程安全问题
  • majorimageprocessingthread.cpp 中的 decodeCount 同样存在线程安全问题
  • 代码格式不够统一,有些地方使用 tab,有些使用空格
  1. 性能改进:
  • 通过 LOGGING_INTERVAL 控制日志输出频率,减少 I/O 开销
  • 添加了解码时间统计,有助于性能分析
  1. 安全性考虑:
  • config_load() 中使用 strtoul() 转换 verbosity 值时没有做错误检查
  • 多个静态变量在多线程环境下可能存在竞态条件

建议改进:

  1. 线程安全改进:
// 在 jpeg_decoder.c 中
static _Atomic int decodeCount = 0;  // 使用原子变量

// 在 majorimageprocessingthread.cpp 中
// 将计数器作为类成员变量
class MajorImageProcessingThread {
private:
    int decodeCount = 0;
    QElapsedTimer decodeTimer;
};
  1. 错误处理改进:
// 在 config_load() 中
else if(strcmp(token, "verbosity") == 0)
{
    unsigned long val = strtoul(value, NULL, 10);
    if (val <= INT_MAX) {
        my_config.verbosity = (int)val;
    } else {
        // 处理错误情况
        my_config.verbosity = 0;
    }
}
  1. 代码格式统一:
  • 建议统一使用空格缩进
  • 保持一致的代码风格
  1. 其他建议:
  • 考虑将 LOGGING_INTERVAL 定义为可配置项
  • 添加更详细的日志级别控制,而不仅仅是开/关
  • 考虑使用更现代的日志库,如 spdlog

这些改进将使代码更加健壮、安全和可维护。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lichaofan2008, 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

@lichaofan2008
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 18, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit ca30b72 into linuxdeepin:master Dec 18, 2025
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.

4 participants