Embedded system asynchronous log processing method and device, equipment and medium

By employing an asynchronous log processing method in the embedded system, and utilizing double buffer swapping and dynamic delay algorithms, the problems of log output blocking and buffer overflow were solved, achieving efficient log transmission and improved system stability.

CN120973630APending Publication Date: 2025-11-18GUANGZHOU BAOLUN ELECTRONICS CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202511089429.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-05
Publication Date
2025-11-18

AI Technical Summary

Technical Problem

In existing technologies, the log output methods of embedded systems are prone to causing system response delays or crashes in high-concurrency scenarios, buffer overflows are easy to occur, and it is difficult to adapt to different performance platforms, affecting system stability and resource utilization efficiency.

Method used

Multiple concurrent tasks are used to generate structured log entries. A double buffer exchange mechanism between the first-level and second-level consumers, combined with queue level judgment and dynamic delay algorithm, enables asynchronous log processing, avoids buffer overflow and blocking, and dynamically adjusts the sending interval to match the system load.

Benefits of technology

It effectively balances log processing efficiency with system overhead, ensures the continuity and timeliness of log processing, and improves the stability and resource utilization efficiency of embedded systems under complex working conditions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120973630A_ABST
    Figure CN120973630A_ABST
Patent Text Reader

Abstract

The invention provides an asynchronous log processing method and device for an embedded system, equipment and a medium, and the method comprises the steps: generating structured log entries through a plurality of concurrent tasks, and writing the log entries into a first-stage buffer queue; a first-level consumer obtains log entries from the queue buffer, performs processing based on a queue water level judgment mechanism, monitors the state of an active buffer area in real time through a sentinel mechanism, marks a switching demand when the filling rate exceeds a preset threshold value or the buffer area is full, or inserts dynamic delay to realize flow control; and judging and executing exchange between the active buffer area and the ready buffer area based on the double trigger conditions, generating a synchronization signal to inform a secondary consumer, reading data items of the ready buffer area by the secondary consumer for formatting, and adjusting the next sending interval based on a dynamic delay algorithm. The key of the method is to solve the problems that the embedded system logs block key tasks, high-concurrency logs are lost and the existing scheme is poor in adaptability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of embedded system software design, and in particular relates to an asynchronous log processing method, apparatus, device and medium for embedded systems. Background Technology

[0002] With the continued application of microcontroller chips in industrial automation and the Internet of Things (IoT), embedded systems have evolved from simple switch control and data acquisition to comprehensive applications integrating multi-device collaborative work, real-time environmental monitoring, and complex logic judgment. Their stable operation directly depends on the efficient troubleshooting and monitoring of abnormal data during program execution. Logs, as the core carrier for recording system operating parameters and error conditions, have become a key factor affecting system reliability due to their processing capabilities.

[0003] However, existing technologies have significant drawbacks: traditional synchronous log output methods severely block the main program's execution, easily leading to system response delays or even crashes in high-concurrency scenarios; log systems using simple queue structures rely solely on a single queue for log storage, and when the queue is full, new logs are either discarded or the log producer is blocked; furthermore, most log systems lack dynamic flow control mechanisms, and when log bursts occur, the buffer is prone to overflow due to overload, further exacerbating the risk of data loss. These problems are even more pronounced in resource-constrained embedded environments, mainly due to the limited memory capacity and CPU performance of low-end MCUs. Existing solutions struggle to balance log integrity with the real-time performance of core tasks, necessitating an efficient log processing architecture adapted to embedded scenarios.

[0004] In summary, the problems existing in the current technology urgently need to be solved. Summary of the Invention

[0005] This application proposes an asynchronous log processing method, apparatus, device, and medium for embedded systems, which aims to solve the problems of log output blocking critical tasks in embedded systems, resulting in slow system response, buffer overflow causing log loss under high concurrency, and existing solutions being difficult to adapt to different performance platforms.

[0006] This invention provides an asynchronous log processing method for an embedded system, comprising:

[0007] Structured log entries are generated through multiple concurrent tasks and written to a first-level buffer queue. The log entries include timestamps, task identifiers, module identifiers, log levels, error codes, and fixed-length message bodies.

[0008] The first-level consumer retrieves log entries from the queue buffer, performs processing based on the queue level judgment mechanism, and monitors the status of the activity buffer in real time through the sentinel mechanism. When the fill rate exceeds the preset threshold or the buffer is full, a switching requirement is marked; otherwise, a dynamic delay is inserted to achieve flow control.

[0009] Based on the dual trigger condition judgment, the active buffer and the ready buffer are exchanged, and a synchronization signal is generated. The synchronization signal is then used to notify the secondary consumer. The secondary consumer responds to the synchronization signal, reads the data entries in the ready buffer, performs formatting processing, and adjusts the next transmission interval based on the dynamic delay algorithm.

[0010] According to an embedded system asynchronous log processing method provided by the present invention, the queue water level judgment mechanism specifically includes:

[0011] When the amount of data in the queue exceeds the high watermark threshold, a fast processing mode is activated to continuously and non-blockingly acquire data entries; when the amount of data in the queue is lower than or equal to the high watermark threshold, data entries are acquired one by one with a slight delay.

[0012] Specifically, the secondary buffer includes an active buffer and a ready buffer. The active buffer is used to receive logs written after processing by the primary consumer, while the ready buffer is used to temporarily store logs to be sent. When the active buffer fill rate exceeds a preset threshold or is full, it is exchanged with the ready buffer through a switching mechanism to achieve orderly temporary storage and preparation for sending logs, avoiding single buffer overflow or blocking.

[0013] According to an embedded system asynchronous log processing method provided by the present invention, the dual triggering conditions include:

[0014] Capacity trigger condition: The active buffer fill rate reaches a preset capacity threshold;

[0015] Time-triggered condition: The continuous idle time of the active buffer reaches a preset time threshold.

[0016] According to an embedded system asynchronous log processing method provided by the present invention, the dynamic delay algorithm specifically includes:

[0017] Delay = T base ×(1-α×(F / F max ) n )

[0018] Among them, T base The base delay parameter, α is the adjustment coefficient, and F is the current buffer fill rate. max The maximum fill rate is given by n, which is a non-linear exponential parameter.

[0019] The sending interval is dynamically adjusted based on the historical fill rate, and the sending interval is negatively correlated with the historical fill rate.

[0020] The present invention also provides an embedded system asynchronous log processing device, characterized in that the device comprises:

[0021] The generation module is used to generate structured log entries through multiple concurrent tasks and write the log entries into a first-level buffer queue, wherein the log entries include timestamp, task identifier, module identifier, log level, error code and fixed-length message body;

[0022] The monitoring module is used by the primary consumer to obtain log entries from the queue buffer, perform processing based on the queue level judgment mechanism, and monitor the status of the active buffer in real time through the sentinel mechanism. When the fill rate exceeds the preset threshold or the buffer is full, a switching requirement is marked; otherwise, a dynamic delay is inserted to achieve flow control.

[0023] The adjustment module is used to perform the exchange between the active buffer and the ready buffer based on the dual trigger condition judgment, and generate a synchronization signal. The generated synchronization signal notifies the secondary consumer, which responds to the synchronization signal, reads the data entries in the ready buffer for formatting, and adjusts the next transmission interval based on the dynamic delay algorithm.

[0024] According to an embedded system asynchronous log processing device provided by the present invention, the queue water level judgment mechanism specifically includes:

[0025] When the amount of data in the queue exceeds the high watermark threshold, a fast processing mode is activated to continuously and non-blockingly acquire data entries; when the amount of data in the queue is lower than or equal to the high watermark threshold, data entries are acquired one by one with a slight delay.

[0026] Specifically, the secondary buffer includes an active buffer and a ready buffer. The active buffer is used to receive logs written after processing by the primary consumer, while the ready buffer is used to temporarily store logs to be sent. When the active buffer fill rate exceeds a preset threshold or is full, it is exchanged with the ready buffer through a switching mechanism to achieve orderly temporary storage and preparation for sending logs, avoiding single buffer overflow or blocking.

[0027] According to an embedded system asynchronous log processing device provided by the present invention, the dual triggering conditions include:

[0028] Capacity trigger condition: The active buffer fill rate reaches a preset capacity threshold;

[0029] Time-triggered condition: The continuous idle time of the active buffer reaches a preset time threshold.

[0030] According to an embedded system asynchronous log processing device provided by the present invention, the dynamic delay algorithm specifically includes:

[0031] Delay = T base ×(1-α×(F / F max ) n )

[0032] Among them, T base The base delay parameter, α is the adjustment coefficient, and F is the current buffer fill rate. max The maximum fill rate is given by n, which is a non-linear exponential parameter.

[0033] The sending interval is dynamically adjusted based on the historical fill rate, and the sending interval is negatively correlated with the historical fill rate.

[0034] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the embedded system asynchronous log processing method as described above.

[0035] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the embedded system asynchronous log processing method as described above.

[0036] This invention provides an asynchronous log processing method, apparatus, device, and medium for embedded systems. Through an innovatively designed log processing mechanism and dynamic adjustment strategy, it brings several significant benefits: First, it adopts a dual-mode processing logic based on a high-water threshold. During log traffic surges, a fast processing mode efficiently digests queue backlogs, while during low loads, single-entry processing and minimal latency are used to rationally allocate resources, effectively balancing processing efficiency and system overhead. Second, it utilizes a dual-buffer switching mechanism with dual trigger conditions, combined with capacity thresholds and idle timeout detection, to achieve intelligent buffer management. This avoids the risk of single-buffer overflow and prevents long-term log retention, ensuring the continuity and timeliness of log processing. Third, by constructing a closed-loop control system of "buffer load detection - reverse adjustment of sending interval - load growth suppression," and using a dynamic delay algorithm to precisely match the sending rate with the real-time load, it ensures efficient log transmission while avoiding excessive CPU resource consumption that could affect critical business operations, significantly improving the stability and resource utilization efficiency of the embedded system under complex operating conditions. Attached Figure Description

[0037] To more clearly illustrate the technical solution of this application, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0038] Figure 1 This is a flowchart illustrating an asynchronous log processing method for an embedded system provided by the present invention.

[0039] Figure 2This is a flowchart illustrating an embodiment of an asynchronous log processing method for embedded systems provided by the present invention.

[0040] Figure 3 This is a schematic diagram of the structure of an embedded system asynchronous log processing device provided by the present invention;

[0041] Figure 4 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation

[0042] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Furthermore, the technical features involved in the various embodiments of this invention described below can be combined with each other as long as they do not conflict with each other.

[0043] With the continued application of microcontroller chips in industrial automation and the Internet of Things (IoT), embedded systems have evolved from simple switch control and data acquisition to comprehensive applications integrating multi-device collaborative work, real-time environmental monitoring, and complex logic judgment. Their stable operation directly depends on the efficient troubleshooting and monitoring of abnormal data during program execution. Logs, as the core carrier for recording system operating parameters and error conditions, have become a key factor affecting system reliability due to their processing capabilities.

[0044] However, existing technologies have significant drawbacks: traditional synchronous log output methods severely block the main program's execution, easily leading to system response delays or even crashes in high-concurrency scenarios; log systems using simple queue structures rely solely on a single queue for log storage, and when the queue is full, new logs are either discarded or the log producer is blocked; furthermore, most log systems lack dynamic flow control mechanisms, and when log bursts occur, the buffer is prone to overflow due to overload, further exacerbating the risk of data loss. These problems are even more pronounced in resource-constrained embedded environments, mainly due to the limited memory capacity and CPU performance of low-end MCUs. Existing solutions struggle to balance log integrity with the real-time performance of core tasks, necessitating an efficient log processing architecture adapted to embedded scenarios.

[0045] Example 1

[0046] To address the problems in existing technologies, this invention proposes an asynchronous log processing method for embedded systems. This method solves the problems of slow system response due to log output blocking critical tasks, log loss caused by buffer overflows under high concurrency, and the difficulty of adapting existing solutions to different performance platforms. Figure 1 As shown, including but not limited to the following steps:

[0047] Step 110: Generate structured log entries through multiple concurrent tasks and write the log entries into the first-level buffer queue, wherein the log entries include timestamp, task identifier, module identifier, log level, error code and fixed-length message body.

[0048] In step 110, multiple concurrent task modules (such as device drivers, business logic, and network protocol processing modules) act as log producers, generating structured log entries containing various types of information through the external interface provided by the log module. These log entries specifically include timestamps accurate to microseconds, the task handle that generated the log (i.e., task identifier), the business module ID (i.e., module identifier), log levels 0-5, business error codes defined by the module, and fixed-length message bodies.

[0049] Step 120: The first-level consumer retrieves log entries from the queue buffer, performs processing based on the queue level judgment mechanism, and monitors the status of the active buffer in real time through the sentinel mechanism. When the fill rate exceeds the preset threshold or the buffer is full, a switching requirement is marked; otherwise, a dynamic delay is inserted to achieve flow control.

[0050] In step 120, the primary consumer, as the core relay node of the log processing link, adopts an adaptive scheduling strategy based on queue level when retrieving log entries from the queue buffer; it continuously samples the buffer fill rate, and immediately sets the buffer switching flag when the fill rate exceeds the preset threshold or the physical storage of the buffer reaches the upper limit; for scenarios where the threshold is not reached, traffic shaping is achieved by inserting microsecond-level dynamic delays, which ensures that CPU resources are tilted towards critical business tasks and avoids starvation in the log processing link.

[0051] Step 130: Based on the dual trigger condition judgment, the active buffer and the ready buffer are exchanged, and a synchronization signal is generated. The synchronization signal is then used to notify the secondary consumer. The secondary consumer responds to the synchronization signal, reads the data entries in the ready buffer, performs formatting processing, and adjusts the next transmission interval based on the dynamic delay algorithm.

[0052] In step 130, when the dual triggering conditions are met, the log buffer exchange module will initiate an atomic exchange operation between the active buffer and the ready buffer. A dual-buffer pool mutex lock ensures thread safety during the switching process, avoiding resource contention in critical sections. The system generates synchronization notifications by sending semaphores issued by the task, achieving event synchronization between the first-level and second-level consumers. After capturing the signal, the second-level consumer immediately traverses the structure array in the ready buffer, performs structured transformation of log metadata according to a preset protocol, and calls the NetProtPack interface for network protocol encapsulation.

[0053] As a further optional embodiment, the queue water level determination mechanism specifically includes:

[0054] When the amount of data in the queue exceeds the high watermark threshold, a fast processing mode is activated to continuously and non-blockingly acquire data entries; when the amount of data in the queue is lower than or equal to the high watermark threshold, data entries are acquired one by one with a slight delay.

[0055] Specifically, the secondary buffer includes an active buffer and a ready buffer. The active buffer is used to receive logs written after processing by the primary consumer, while the ready buffer is used to temporarily store logs to be sent. When the active buffer fill rate exceeds a preset threshold or is full, it is exchanged with the ready buffer through a switching mechanism to achieve orderly temporary storage and preparation for sending logs, avoiding single buffer overflow or blocking.

[0056] For easier understanding, please refer to Figure 2 , Figure 2 This is a flowchart illustrating one embodiment of an asynchronous log processing method for an embedded system.

[0057] In a preferred embodiment, the log producer writes log content through the external interface provided by the log module. This interface encapsulates the log information into standard log entries and automatically writes them into a first-level buffer queue. The log receiving task, as a first-level consumer, continuously extracts log entries from the queue buffer and processes them. Its processing logic is dynamically adjusted according to the current number of logs in the queue: when the number of logs in the queue exceeds a preset high watermark, the system automatically switches to a fast processing mode. In this mode, the log receiving task continuously and non-blockingly extracts log entries from the queue and writes them into the active buffer, while updating the fill rate of the active buffer in real time. When the number of logs in the queue is lower than or equal to the high watermark, a conventional processing mode is adopted, that is, only one log entry is extracted from the queue and written into the active buffer at a time. Through this dynamic processing mechanism based on queue load, it is possible to quickly digest backlogged data when log traffic surges and to reasonably allocate system resources when the load is low, avoiding interference with critical business tasks.

[0058] As a further optional embodiment, the dual triggering conditions include:

[0059] Capacity trigger condition: The active buffer fill rate reaches a preset capacity threshold;

[0060] Time-triggered condition: The continuous idle time of the active buffer reaches a preset time threshold.

[0061] In a preferred embodiment, after each log write is completed, the log buffer exchange module comprehensively evaluates the capacity threshold flag and idle timeout status to determine whether to perform a buffer switch. The switch operation is protected by a mutex lock to ensure data consistency during the exchange of active and ready buffers.

[0062] The dynamic delay algorithm specifically includes:

[0063] Delay = T base ×(1-α×(F / F max ) n )

[0064] Among them, T base The base delay parameter, α is the adjustment coefficient, and F is the current buffer fill rate. max The maximum fill rate is given by n, which is a non-linear exponential parameter.

[0065] The sending interval is dynamically adjusted based on the historical fill rate, and the sending interval is negatively correlated with the historical fill rate.

[0066] In one embodiment, the base latency parameter is set to 10, the adjustment coefficient is set to 1, the maximum fill rate is 100%, and the nonlinear exponent parameter is 2, i.e., the dynamic latency parameter = 10 * (1 - current cache fill rate). 2 This is used to dynamically calculate latency parameters based on the cache fill rate.

[0067] Upon receiving a send notification transmitted via semaphore, the log sending task initiates the processing flow of the ready buffer: first, it iterates through all log entries stored in the ready buffer, performs formatting processing sequentially, and then executes the send operation through the network protocol encapsulation interface. To achieve dynamic adaptation between the sending rate and system load, after each log entry is sent, the system triggers a negative feedback dynamic delay control algorithm. Based on the current active buffer fill rate, it calculates the interval for the next send. When the fill rate is high (buffer is close to saturation), the calculated delay value automatically decreases, thereby accelerating the sending pace to quickly alleviate backlog; when the fill rate is low, the delay value increases accordingly, reducing CPU resource consumption by decreasing the sending frequency. This adaptive adjustment mechanism based on real-time load achieves precise matching between the log sending rate and system load, ensuring efficient log transmission while avoiding excessive system resource consumption that could impact critical business operations.

[0068] This application brings several significant benefits through its innovative log processing mechanism and dynamic adjustment strategy: First, it adopts a dual-mode processing logic based on a high-water threshold. During log traffic surges, a fast processing mode efficiently digests queue backlogs, while during low loads, single-entry processing and minimal latency are used to rationally allocate resources, effectively balancing processing efficiency and system overhead. Second, it utilizes a dual-buffer switching mechanism with dual trigger conditions, combined with capacity thresholds and idle timeout detection, to achieve intelligent buffer management. This avoids the risk of single-buffer overflow and prevents long-term log retention, ensuring the continuity and timeliness of log processing. Third, by constructing a closed-loop control system of "buffer load detection - reverse adjustment of sending interval - load growth suppression," and using a dynamic delay algorithm to precisely match the sending rate with the real-time load, it ensures efficient log transmission while avoiding excessive CPU resource consumption that could affect critical business operations, significantly improving the stability and resource utilization efficiency of the embedded system under complex operating conditions.

[0069] Example 2

[0070] The following describes an embedded system asynchronous log processing device provided by the present invention, such as... Figure 3 As shown, the embedded system asynchronous log processing device described below and the embedded system asynchronous log processing method described above can be referred to in correspondence.

[0071] An embedded system asynchronous log processing device, characterized in that the device comprises:

[0072] The generation module is used to generate structured log entries through multiple concurrent tasks and write the log entries into a first-level buffer queue, wherein the log entries include timestamp, task identifier, module identifier, log level, error code and fixed-length message body;

[0073] The monitoring module is used by the primary consumer to obtain log entries from the queue buffer, perform processing based on the queue level judgment mechanism, and monitor the status of the active buffer in real time through the sentinel mechanism. When the fill rate exceeds the preset threshold or the buffer is full, a switching requirement is marked; otherwise, a dynamic delay is inserted to achieve flow control.

[0074] The adjustment module is used to perform the exchange between the active buffer and the ready buffer based on the dual trigger condition judgment, and generate a synchronization signal. The generated synchronization signal notifies the secondary consumer, which responds to the synchronization signal, reads the data entries in the ready buffer for formatting, and adjusts the next transmission interval based on the dynamic delay algorithm.

[0075] As a further optional embodiment, the queue water level determination mechanism specifically includes:

[0076] When the amount of data in the queue exceeds the high watermark threshold, a fast processing mode is activated to continuously and non-blockingly acquire data entries; when the amount of data in the queue is lower than or equal to the high watermark threshold, data entries are acquired one by one with a slight delay.

[0077] Specifically, the secondary buffer includes an active buffer and a ready buffer. The active buffer is used to receive logs written after processing by the primary consumer, while the ready buffer is used to temporarily store logs to be sent. When the active buffer fill rate exceeds a preset threshold or is full, it is exchanged with the ready buffer through a switching mechanism to achieve orderly temporary storage and preparation for sending logs, avoiding single buffer overflow or blocking.

[0078] In a preferred embodiment, the log producer writes log content through the external interface provided by the log module. This interface encapsulates the log information into standard log entries and automatically writes them into a first-level buffer queue. The log receiving task, as a first-level consumer, continuously extracts log entries from the queue buffer and processes them. Its processing logic is dynamically adjusted according to the current number of logs in the queue: when the number of logs in the queue exceeds a preset high watermark, the system automatically switches to a fast processing mode. In this mode, the log receiving task continuously and non-blockingly extracts log entries from the queue and writes them into the active buffer, while updating the fill rate of the active buffer in real time. When the number of logs in the queue is lower than or equal to the high watermark, a conventional processing mode is adopted, that is, only one log entry is extracted from the queue and written into the active buffer at a time. Through this dynamic processing mechanism based on queue load, backlogged data can be quickly digested when log traffic surges, and system resources can be reasonably allocated when the load is low, avoiding interference with critical business tasks.

[0079] As a further optional embodiment, the dual triggering conditions include:

[0080] Capacity trigger condition: The active buffer fill rate reaches a preset capacity threshold;

[0081] Time-triggered condition: The continuous idle time of the active buffer reaches a preset time threshold.

[0082] In a preferred embodiment, after each log write is completed, the log buffer exchange module comprehensively evaluates the capacity threshold flag and idle timeout status to determine whether to perform a buffer switch. The switch operation is protected by a mutex lock to ensure data consistency during the exchange of active and ready buffers.

[0083] The dynamic delay algorithm specifically includes:

[0084] Delay = T base ×(1-α×(F / F max ) n )

[0085] Among them, T base The base delay parameter, α is the adjustment coefficient, and F is the current buffer fill rate. max The maximum fill rate is given by n, which is a non-linear exponential parameter.

[0086] The sending interval is dynamically adjusted based on the historical fill rate, and the sending interval is negatively correlated with the historical fill rate.

[0087] In one embodiment, the base latency parameter is set to 10, the adjustment coefficient is set to 1, the maximum fill rate is 100%, and the nonlinear exponent parameter is 2, i.e., the dynamic latency parameter = 10 * (1 - current cache fill rate). 2 This is used to dynamically calculate latency parameters based on the cache fill rate.

[0088] Upon receiving a send notification transmitted via semaphore, the log sending task initiates the processing flow of the ready buffer: first, it iterates through all log entries stored in the ready buffer, performs formatting processing sequentially, and then executes the send operation through the network protocol encapsulation interface. To achieve dynamic adaptation between the sending rate and system load, after each log entry is sent, the system triggers a negative feedback dynamic delay control algorithm. Based on the current active buffer fill rate, it calculates the interval for the next send. When the fill rate is high (buffer is close to saturation), the calculated delay value automatically decreases, thereby accelerating the sending pace to quickly alleviate backlog; when the fill rate is low, the delay value increases accordingly, reducing CPU resource consumption by decreasing the sending frequency. This adaptive adjustment mechanism based on real-time load achieves precise matching between the log sending rate and system load, ensuring efficient log transmission while avoiding excessive system resource consumption that could impact critical business operations.

[0089] This application brings several significant benefits through its innovative log processing mechanism and dynamic adjustment strategy: First, it adopts a dual-mode processing logic based on a high-water threshold. During log traffic surges, a fast processing mode efficiently digests queue backlogs, while during low loads, single-entry processing and minimal latency are used to rationally allocate resources, effectively balancing processing efficiency and system overhead. Second, it utilizes a dual-buffer switching mechanism with dual trigger conditions, combined with capacity thresholds and idle timeout detection, to achieve intelligent buffer management. This avoids the risk of single-buffer overflow and prevents long-term log retention, ensuring the continuity and timeliness of log processing. Third, by constructing a closed-loop control system of "buffer load detection - reverse adjustment of sending interval - load growth suppression," and using a dynamic delay algorithm to precisely match the sending rate with the real-time load, it ensures efficient log transmission while avoiding excessive CPU resource consumption that could affect critical business operations, significantly improving the stability and resource utilization efficiency of the embedded system under complex operating conditions.

[0090] Example 3

[0091] Figure 4 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 4 As shown, the electronic device may include: a processor 310, a communication interface 320, a memory 330, and a communication bus 340, wherein the processor 310, the communication interface 320, and the memory 330 communicate with each other through the communication bus 340. The processor 310 can call logical instructions in the memory 330 to execute an embedded system asynchronous log processing method, which includes:

[0092] Structured log entries are generated through multiple concurrent tasks and written to a first-level buffer queue. The log entries include timestamps, task identifiers, module identifiers, log levels, error codes, and fixed-length message bodies.

[0093] The first-level consumer retrieves log entries from the queue buffer, performs processing based on the queue level judgment mechanism, and monitors the status of the activity buffer in real time through the sentinel mechanism. When the fill rate exceeds the preset threshold or the buffer is full, a switching requirement is marked; otherwise, a dynamic delay is inserted to achieve flow control.

[0094] Based on the dual trigger condition judgment, the active buffer and the ready buffer are exchanged, and a synchronization signal is generated to notify the secondary consumer. The secondary consumer reads the data entries in the ready buffer, performs formatting processing, and adjusts the next transmission interval based on the dynamic delay algorithm.

[0095] Furthermore, the logical instructions in the aforementioned memory 330 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0096] On the other hand, the present invention also provides a computer program product, the computer program product comprising a computer program that can be stored on a non-transitory computer-readable storage medium, wherein when the computer program is executed by a processor, the computer is able to execute an embedded system asynchronous log processing method provided by the above methods, the method comprising:

[0097] Structured log entries are generated through multiple concurrent tasks and written to a first-level buffer queue. The log entries include timestamps, task identifiers, module identifiers, log levels, error codes, and fixed-length message bodies.

[0098] The first-level consumer retrieves log entries from the queue buffer, performs processing based on the queue level judgment mechanism, and monitors the status of the activity buffer in real time through the sentinel mechanism. When the fill rate exceeds the preset threshold or the buffer is full, a switching requirement is marked; otherwise, a dynamic delay is inserted to achieve flow control.

[0099] Based on the dual trigger condition judgment, the active buffer and the ready buffer are exchanged, and a synchronization signal is generated to notify the secondary consumer. The secondary consumer reads the data entries in the ready buffer, performs formatting processing, and adjusts the next transmission interval based on the dynamic delay algorithm.

[0100] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, is implemented to perform an embedded system asynchronous log processing method provided by the methods described above, the method comprising:

[0101] Structured log entries are generated through multiple concurrent tasks and written to a first-level buffer queue. The log entries include timestamps, task identifiers, module identifiers, log levels, error codes, and fixed-length message bodies.

[0102] The first-level consumer retrieves log entries from the queue buffer, performs processing based on the queue level judgment mechanism, and monitors the status of the activity buffer in real time through the sentinel mechanism. When the fill rate exceeds the preset threshold or the buffer is full, a switching requirement is marked; otherwise, a dynamic delay is inserted to achieve flow control.

[0103] Based on the dual trigger condition judgment, the active buffer and the ready buffer are exchanged, and a synchronization signal is generated to notify the secondary consumer. The secondary consumer reads the data entries in the ready buffer, performs formatting processing, and adjusts the next transmission interval based on the dynamic delay algorithm.

[0104] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0105] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0106] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. An asynchronous log processing method for an embedded system, characterized in that, include: Structured log entries are generated through multiple concurrent tasks and written to a first-level buffer queue. The log entries include timestamps, task identifiers, module identifiers, log levels, error codes, and fixed-length message bodies. The first-level consumer retrieves log entries from the queue buffer, performs processing based on the queue level judgment mechanism, and monitors the status of the activity buffer in real time through the sentinel mechanism. When the fill rate exceeds the preset threshold or the buffer is full, a switching requirement is marked; otherwise, a dynamic delay is inserted to achieve flow control. Based on the dual trigger condition judgment, the active buffer and the ready buffer are exchanged, and a synchronization signal is generated to notify the secondary consumer. The secondary consumer reads the data entries in the ready buffer, performs formatting processing, and adjusts the next transmission interval based on the dynamic delay algorithm.

2. The embedded system asynchronous log processing method according to claim 1, characterized in that, The queue water level determination mechanism specifically includes: When the amount of data in the queue exceeds the high watermark threshold, a fast processing mode is activated to continuously and non-blockingly acquire data entries; when the amount of data in the queue is lower than or equal to the high watermark threshold, data entries are acquired one by one with a slight delay.

3. The embedded system asynchronous log processing method according to claim 1, characterized in that, The dual triggering conditions specifically include: Capacity trigger condition: The active buffer fill rate reaches a preset capacity threshold; Time-triggered condition: The continuous idle time of the active buffer reaches a preset time threshold.

4. The embedded system asynchronous log processing method according to claim 1, characterized in that, The dynamic delay algorithm specifically includes: Delay=T base ×(1-α×(F / F max ) n ) Among them, T base The base delay parameter, α is the adjustment coefficient, and F is the current buffer fill rate. max The maximum fill rate is given by n, which is a non-linear exponential parameter. The sending interval is dynamically adjusted based on the historical fill rate, and the sending interval is negatively correlated with the historical fill rate.

5. An embedded system asynchronous log processing device, characterized in that, include: The generation module is used to generate structured log entries through multiple concurrent tasks and write the log entries into a first-level buffer queue, wherein the log entries include timestamp, task identifier, module identifier, log level, error code and fixed-length message body; The monitoring module is used by the primary consumer to obtain log entries from the queue buffer, perform processing based on the queue level judgment mechanism, and monitor the status of the active buffer in real time through the sentinel mechanism. When the fill rate exceeds the preset threshold or the buffer is full, a switching requirement is marked; otherwise, a dynamic delay is inserted to achieve flow control. The adjustment module is used to perform the exchange between the active buffer and the ready buffer based on the dual trigger condition judgment, and generate a synchronization signal to notify the secondary consumer. The secondary consumer responds to the synchronization signal, reads the data entries in the ready buffer for formatting, and adjusts the next transmission interval based on the dynamic delay algorithm.

6. An embedded system asynchronous log processing device according to claim 5, characterized in that, The queue water level determination mechanism specifically includes: When the amount of data in the queue exceeds the high watermark threshold, a fast processing mode is activated to continuously and non-blockingly acquire data entries; when the amount of data in the queue is lower than or equal to the high watermark threshold, data entries are acquired one by one with a slight delay.

7. An embedded system asynchronous log processing device according to claim 5, characterized in that, The dual triggering conditions include: Capacity trigger condition: The active buffer fill rate reaches a preset capacity threshold; Time-triggered condition: The continuous idle time of the active buffer reaches a preset time threshold.

8. An embedded system asynchronous log processing device according to claim 5, characterized in that, The dynamic delay algorithm specifically includes: Delay=T base ×(1-α×(F / F max ) n ) Among them, T base The base delay parameter, α is the adjustment coefficient, and F is the current buffer fill rate. max The maximum fill rate is given by n, which is a non-linear exponential parameter. The sending interval is dynamically adjusted based on the historical fill rate, and the sending interval is negatively correlated with the historical fill rate.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the embedded system asynchronous log processing method as described in any one of claims 1 to 8.

10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the embedded system asynchronous log processing method as described in any one of claims 1 to 8.

Citation Information

Cited By

  • Mixed log acquisition and alarm method and system

    CN122240424A