Log output method, log acquisition method and embedded device
By employing a structured data format and caching mechanism in embedded devices for log output, the problems of resource consumption and blocking in log output are solved, achieving efficient log information transmission and improved system performance.
Patent Information
- Application Number
- CN202510957990.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-11
- Publication Date
- 2025-11-21
AI Technical Summary
The existing log output methods of embedded devices consume a lot of system resources and are prone to blocking, especially affecting system performance in resource-sensitive and timing-critical scenarios.
Log information is organized using a structured data format, and write and read operations are performed asynchronously through a caching mechanism, separating the generation and output of log information and reducing the resource consumption and processing burden on embedded devices.
It effectively avoids blocking and resource consumption of embedded devices by log output, reduces system burden, and meets the needs of application scenarios with high timing requirements.
Smart Images

Figure CN120994527A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of embedded device debugging, and in particular to a log output method, a log acquisition method and an embedded device. BACKGROUND
[0002] When performing embedded development work, debugging and problem positioning are usually performed through simulation or log information viewing.
[0003] Not all development environments have simulation conditions. Therefore, in the process of writing and running embedded software programs, the log information viewing method is generally used to debug and locate problems. The embedded device can print output log information through transmission methods such as UART interface transmission, USB interface transmission, TCP / UDP network log transmission, and the like for debugging use.
[0004] For example, in the transmission method of UART interface transmission, the embedded device first initializes the UART configuration (including but not limited to multiplexing pins, data length, parity bit, baud rate and the like). Then, the USB-to-serial tool is used to realize the physical connection between the embedded device and the external device (such as a personal computer). Subsequently, the external device starts the relevant serial log information printing tool, sets the same UART configuration as the embedded device, and establishes the basis for serial communication between the two. Finally, the log information collected and generated by the embedded device during the running of the program is displayed through the interactive device (such as a display) of the external device, for debugging and problem positioning.
[0005] Although the UART interface transmission method is widely used because it supports asynchronous communication, has a simple hardware interface and a simple communication protocol. However, this log information output method still has defects such as occupying system resources and being prone to blocking, which is not conducive to application in resource-sensitive and high-time sequence requirement scenarios. SUMMARY
[0006] The log output method, the log acquisition method and the embedded device provided by the embodiments of the present application aim to solve at least part of the defects of the log output method of the existing embedded device.
[0007] In a first aspect, an embodiment of the present application provides a log output method. The log output method comprises: in a first period, generating a plurality of log information; each of the log information adopts a preset structured data format, and records state data of a corresponding collection node; performing a write operation to sequentially write the plurality of log information to a cache area; in a second period, performing a read operation to read the plurality of log information from the cache area; encapsulating the read state information into a communication frame conforming to a preset communication format, and sending to an external device; wherein the write operation and the read operation are asynchronously performed in time.
[0008] In a second aspect, an embodiment of the present application provides a log acquisition method. The log acquisition method comprises: establishing a serial communication with an embedded device; receiving a communication frame containing a plurality of log information through the serial communication; extracting the log information contained in the communication frame according to a preset communication format; parsing the log information adopting a preset structured data format to generate corresponding state data; and outputting the state data.
[0009] In a third aspect, an embodiment of the present application provides an embedded device. The embedded device comprises: a memory and a processor, the processor is in communication connection with the memory, the memory stores computer program instructions, and the computer program instructions are called by the processor to make the processor execute the log output method as described above.
[0010] The log output method provided by the embodiment of the present application has the beneficial effects that: by asynchronously performing the write operation and the read operation of the log information, the blocking and interference of the log output process on the operation task of the embedded device can be effectively avoided. Moreover, the log information is recorded in the structured data format, the log information is parsed in the external device, and the processing burden of the embedded device and the resource occupation are reduced. BRIEF DESCRIPTION OF DRAWINGS
[0011] One or more embodiments are exemplarily illustrated by pictures in the drawings corresponding thereto, and the exemplarily illustrations do not constitute a limitation on the embodiments, elements with the same reference numerals in the drawings represent similar elements, unless otherwise specified, and the drawings do not constitute a proportional limitation.
[0012] Figure 1 A schematic diagram of a typical application scenario of an embedded device; Figure 2 A method flowchart of the log output method provided by the embodiment of the present application; Figure 3 A schematic diagram of log information provided by the embodiment of the present application; Figure 4 A schematic diagram of a communication frame provided by the embodiment of the present application; Figure 5 Method flow chart of write operation provided for the embodiment of the present application; Figure 6 Method flow chart of read operation provided for the embodiment of the present application; Figure 7 Schematic diagram of cache area provided for the embodiment of the present application; Figure 8 Method flow chart of log acquisition method provided for the embodiment of the present application; Figure 9 Functional block diagram of log output device provided for the embodiment of the present application; Figure 10 Functional block diagram of log acquisition device provided for the embodiment of the present application; Figure 11 Functional block diagram of embedded device provided for the embodiment of the present application. DETAILED DESCRIPTION
[0013] In order to facilitate the understanding of the present application, the present application will be described in more detail below in conjunction with the drawings and specific embodiments.
[0014] It should be noted that when an element is referred to as being "provided on" another element, it can be directly on the other element or there can be a middle element. When an element is referred to as being "connected" to another element, it can be directly connected to the other element or there can be a middle element, and it can also mean that the two elements are connected by signals to interact with each other. When an element is referred to as being "coupled" to another element, it can be directly coupled to the other element or there can be a middle element, and it can also mean that the two elements are connected by signals to interact with each other.
[0015] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which the present application belongs. The terminology used in the description of the present application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the present application.
[0016] In addition, the technical features involved in the different embodiments of the present application described below can be combined with each other as long as they do not conflict with each other.
[0017] Figure 1 Schematic diagram of a typical embedded development scenario. As shown in Figure 1 The embedded device 10 establishes a connection with the host device 30 through the USB-to-serial tool 20.
[0018] The embedded device 10 refers to a special-purpose computing device with specific functions. It includes but is not limited to a development board based on STM32 series MCU, an IoT device based on ESP32, or other embedded systems using ARM Cortex-M core. It usually contains hardware components such as microcontrollers (MCU), memory, and peripheral interfaces (such as UART interface) to achieve the required functions.
[0019] The USB-to-serial tool 20 is a communication protocol conversion device used to realize data conversion between UART interface and USB interface. It includes but is not limited to conversion modules based on USB-to-serial chips such as CH340, CP2102, FT232, etc. Usually, one end is connected to the UART interface of the embedded device through TX / RX pins, and the other end is connected to the host device through the USB interface, realizing bidirectional conversion of data.
[0020] The host device 30 refers to a general-purpose computing device with strong computing processing capability (relative to the embedded device). It includes but is not limited to personal computers (PCs), workstations, etc. The host device 30 runs a complete operating system (such as Windows, Linux, etc.), can install serial debugging tool software, and has one or more interactive devices for receiving and displaying log information from the embedded device.
[0021] For the sake of simplicity and ease of use, the printf function combined with standard library redirection is often used to achieve the acquisition of log information of the embedded device.
[0022] First, the embedded device 10 converts the log information into string data and sends it to the USB-to-serial tool 20 through the UART interface. Then, the USB-to-serial tool 20 converts the received serial data into a protocol and transmits it to the host device 30 through the USB interface. Finally, the host device 30 receives and displays the log information output by the printf function through the corresponding serial log information printing tool, allowing developers to understand the running status of the embedded device 10 and complete debugging and problem positioning.
[0023] However, the applicant noticed during the implementation of the present application that the printf function needs to perform parsing and processing of formatted strings during execution, which will occupy a large amount of system stack space and processor resources. Especially in scenarios where log information needs to be frequently output, a large number of printf function calls will cause excessive occupation of system resources, which is a great burden for resource-constrained embedded devices.
[0024] In addition, each time the printf function is called, a series of complex operations such as string formatting, parameter analysis, data type conversion, etc. need to be completed, and the execution time is relatively long, and the execution of the printf function will block the current task. This blocking will cause the real-time performance of the system to decline, especially in Bluetooth, WIFI and other communication scenarios with high timing requirements, which may cause communication timing disorder and trigger unpredictable system abnormalities.
[0025] In order to solve the problem of high system resource occupation and easy blocking caused by the above-mentioned printf function, the applicant provides a new log output method. The log information is organized into a predefined structured data format, and the structured log information is written into a preset cache area through a cache mechanism. When the embedded device is idle, the structured log information in the cache area is read and encapsulated according to the preset communication format and then sent to the host device.
[0026] On the one hand, the method of organizing log information into a predefined structured data format transfers the log information parsing work to a host device with sufficient resources, which can significantly reduce the resource occupation of the embedded device. On the other hand, the time-separated write and read operations eliminate the impact of log information output on the real-time performance of the system, so that the system can better meet the needs of application scenarios with high timing requirements.
[0027] According to the above invention idea, the log output method provided by the embodiments of the present application can be generally applied to various electronic devices to reduce the impact of log information output on system resources and system real-time performance. For the sake of understanding, the specific implementation of the log output method provided by the embodiments of the present application is described below. Figure 2
[0028] Figure 2 The schematic diagram of the log output method provided by the embodiments of the present application is shown in FIG. 1. As shown in the figure, the log output method includes: Figure 2 S201, generating a plurality of log information in a first period.
[0029] Among them, one log information is the state data of the corresponding collection node recorded in a preset structured data format.
[0030] The "collection node" is a pre-set log recording point. It is a specific position in the execution flow or device running process. The "state data" is the running related data of the device at the collection node. For example, sensor data (such as temperature, humidity, acceleration, etc.), timer count value, interrupt trigger times, task stack usage, etc.
[0031] The "structured data format" refers to a data representation method of organizing data in a predefined fixed format. It can be composed of one or more fields with fixed meanings and field lengths, for example, a log information contains a type field FLAG and a value field VALUE. The type field FLAG is used to record the type of state data, and the value field VALUE is used to record the value of the state data.
[0032] The log information in the structured format described above transfers the semantic parsing work to the host device 30. The embedded device 10 only needs to organize the original data in a predefined structured format, without the need for time-consuming operations such as string formatting, and without the need to process complex data parsing logic, thereby significantly reducing system overhead.
[0033] Specifically, Figure 3 The log information composed of a type field FLAG and a value field VALUE with a length of 2 bytes is shown in Table 1.
[0034] When the type field FLAG of 2 bytes is used, 65536 (2 raised to the power of 16, 2 bytes are 16-bit binary numbers) different types of state data identifiers can be supported, fully meeting the classification needs of different log information in the embedded device.
[0035] S202, performing a write operation to sequentially write a plurality of log information into a cache area.
[0036] The "write operation" refers to the process of storing structured log information into the cache area. It is executed each time it runs to the log recording point to generate a log information.
[0037] The "cache area" refers to a pre-allocated continuous storage space. Its specific size is configured according to the actual needs, and is not specifically limited here.
[0038] In this embodiment, the term "sequential writing" is used to represent the sequential writing mechanism of writing each log information generated according to the time sequence of the log information into the cache area. In other words, the storage order of the log information in the cache area is consistent with the time sequence of its actual generation, and the newly generated log information is pushed in the preset direction (for example, from low address to high address) and written in the next available position.
[0039] S203, performing a read operation to sequentially read log information from the cache area during the second period.
[0040] The "read operation" refers to a process of obtaining the stored log information from the cache area. Similarly, the term "sequential reading" is used to represent a sequential reading mechanism in which the log information is read one by one in the time sequence in which the log information is stored in the cache area. Thus, the reading sequence of the log information from the cache area is consistent with the time sequence in which the log information is written.
[0041] In the present embodiment, the write operation and the read operation are independent of each other in time sequence, and are two operations that do not need to be strictly performed in a fixed time sequence relationship (hereinafter referred to as: asynchronous execution in time). In this way, the write operation and the read operation that are asynchronous in time are completed in different time periods (for example, the first period and the second period mentioned above), and do not need to wait for each other.
[0042] S204, encapsulate the read state information into a communication frame conforming to a preset communication format, and send to an external device.
[0043] The "communication frame" refers to a data packet organized according to a set communication format. It contains one or more state information, and the external device receiving the communication frame parses the state information based on the unified communication format and displays it to the developer after parsing.
[0044] Specifically, Figure 4 A schematic diagram of the communication frame provided by the embodiment of the present application is shown. As shown in the figure, Figure 4 The communication frame includes a header field Header, a length field Length, a content field PayLoad, and a tail field Trail arranged in sequence.
[0045] The header field Header is a fixed value, used to identify the start of the communication frame. The length field Length is used to indicate the length of the content field. The content field PayLoad contains one or more log information. The tail field Trail is another fixed value, used to identify the end of the communication frame.
[0046] Exemplarily, Figure 4 The field length of the header field Header is 1 byte, and the fixed value is 0xAA (hexadecimal). The field length of the tail field Trail is 2 bytes, and the fixed value is 0xBB (hexadecimal). The field length of the length field Length is 2 bytes, recording the length of the content field.
[0047] 0xAA and 0xBB are special characters in the ASCII code table, which are rarely present in ordinary data, and can reduce the possibility of misjudgment. Moreover, 0xAA and 0xBB have a regular bit alternation pattern in binary and are obviously different, which can facilitate the identification and differentiation of the receiving end device.
[0048] The communication frame enables the external device to accurately identify and extract the complete log information in the continuous data stream through the setting of the header field Header, the length field Length and the tail field Tail, and ensures the data transmission reliability of the communication frame.
[0049] In addition, the communication frame guarantees the integrity of each communication frame through the setting of the header field Header and the tail field Tail, which saves the data check (for example, CRC check), thereby further saving the system resources occupied when outputting the log information.
[0050] In the embodiment, the first period and the second period are two time periods that are independent of each other in time and do not have a fixed timing relationship. Specifically, the first period is a working period in which the embedded device performs task operations, and the second period is an idle period in which the embedded device does not perform task operations.
[0051] For example, the first period can be a running phase of the embedded device, and steps S201 and S202 are performed immediately at the time when the status data needs to be recorded, without waiting for the data transmission to be completed. The second period can be an idle phase (for example, a main task execution gap or an idle process) of the embedded device. Steps S203 and S204 are performed in the second period to avoid resource competition with critical task processing.
[0052] Taking Bluetooth data transmission as an example, the first period is a time period in which the Bluetooth device is in a connection event and is performing task operations such as data packet reception, transmission and processing, and the second period is an idle time period between each connection event.
[0053] The log output method provided by the embodiment separates the generation and output processes of the log information. In the first period, only the collection and caching of the status data are performed (for example, steps S201 and S202), and the resource-intensive operations (for example, steps S203 and S204) are postponed to the second period, which can reduce the influence of log information output on real-time services and effectively avoid task processing delay or performance degradation caused by log output, thereby ensuring the real-time requirement of the system.
[0054] Figure 5 The specific process of the write operation provided by the embodiment is to realize the sequential writing of multiple log information in the cache area by incrementally updating the write position. In some embodiments, as shown in FIG. 2B, step S202 specifically includes: Figure 5 S2021, determining the current write position.
[0055] wherein the "current write position" is position information updated accordingly as the write operation is performed. It indicates the first available storage position in the cache region.
[0056] S2022, write the log information into the cache region from the current write position.
[0057] wherein the current write position is used as the starting position for writing the log information, so that the new state information can be written immediately after the last written state information, realizing the aforementioned sequential writing.
[0058] S2023, incrementally update the write position according to the length of the written log information.
[0059] wherein the "incrementally update" refers to the operation process of moving the write position backward by a corresponding length according to the length of the written log information. Thus, through the incrementally updating of the write position, the write position always points to the next available storage position adjacent to the occupied storage position, avoiding data overlap to realize the sequential writing of the log information.
[0060] Specifically, before performing the write operation, the state of the cache region can also be determined to determine whether it still has available storage positions. For ease of description, "first write state" is used to represent the state of the cache region not being fully occupied and having available storage positions, and "second write state" is used to represent the state of the cache region being fully occupied and having no available storage positions.
[0061] When it is determined that the cache region is in the first write state, the aforementioned write operation is performed, and when it is determined that the cache region is in the second write state, the write operation is stopped to avoid data overlap.
[0062] Figure 6 The specific process of the read operation provided by the embodiments of the present application realizes the sequential reading of the plurality of log information temporarily stored in the cache region by incrementally updating the read position. In some embodiments, as shown in Figure 6 S2031, determine the current read position. S2031, determine the current read position.
[0063] wherein the "current read position" is position information updated accordingly as the read operation is performed. It indicates the first available storage position in the cache region.
[0064] S2032, read the log information written in the cache region from the current read position.
[0065] The log is read by taking the current reading position as the starting position of the reading operation, so that the log information can be read in the order that it can be written.
[0066] S2033. Update the read position incrementally based on the length of the read log information.
[0067] "Incremental update" refers to the process of moving the read position forward by a corresponding length based on the length of the already read log information. By incrementally updating the read position, the read position can be moved sequentially to the next position to be read, ensuring the order of data reading.
[0068] Specifically, before performing a read operation, the state of the buffer area can be determined to see if there are any unread and unsent log messages. For ease of description, the term "first read state" will be used below to indicate that the buffer area still contains unread and unsent log messages, and the term "second read state" will be used below to indicate that the buffer area does not contain any unread and unsent log messages.
[0069] The sequential read operation is performed only when the cache area is determined to be in the first read state. When the cache area is determined to be in the second read state, the read operation is stopped and the system waits for new log information to be written.
[0070] Figure 7 This is a schematic diagram of a cache region provided in an embodiment of this application. In some embodiments, such as Figure 7 As shown, the buffer area is configured as a circular queue structure, with the end position rear of the queue connected to the start position front of the queue.
[0071] exist Figure 7 In this context, the write pointer `write_ptr` indicates the current write position, and the read pointer `read_ptr` indicates the current read position. Initially, both the write pointer `write_ptr` and the read pointer `read_ptr` point to the beginning of the queue, `front`.
[0072] The following combination Figure 7 It describes in detail the changes in the positions of the write pointer and the read pointer during the execution of write and read operations.
[0073] Each time log information needs to be written, the write position pointed to by the write pointer `write_ptr` is used as the initial position for writing the log information, and the log information is written. The write pointer `write_ptr` moves in an increasing direction in the circular queue as log information is written (when the write pointer `write_ptr` moves to the end position `rear` of the queue in the buffer area, it will automatically loop back to the beginning position `front` of the queue to achieve circular writing).
[0074] When the log information needs to be read from the cache area in the second period, the read position pointed by the read pointer read_ptr is taken as the read starting point of the current read operation. The read pointer read_ptr moves in the incremental direction along the circular queue as the log information is read (when the read pointer read_ptr moves to the end position rear of the queue of the cache area, it will automatically loop back to the start position front of the queue, realizing the circular reading).
[0075] It can be understood that, on the one hand, as the write position pointed by the write pointer write_ptr is updated to be the same as the read position currently pointed by the read pointer read_ptr, it indicates that the space of the cache area of the circular queue structure has been fully occupied, and it is in the second write state described above, and the write operation needs to be paused or other corresponding operations are performed.
[0076] On the other hand, as the read position pointed by the read pointer read_ptr is updated to be the same as the write position currently pointed by the write pointer write_ptr, it indicates that the log information temporarily stored in the cache area of the circular queue structure has been completely read, and it is in the second read state described above, and there is no new log information to be output temporarily.
[0077] Based on the log output method provided by the embodiments of the present application, the embodiments of the present application further provide a log acquisition method used in cooperation with the same. The log acquisition method can be executed by the host device 30 described above, and shows the log information to the developer.
[0078] Figure 8 The method flowchart of the log acquisition method provided by the embodiments of the present application. In some embodiments, as shown in Figure 8 the log acquisition method comprises: S301, establishing serial communication with the embedded device.
[0079] Among them, the serial communication establishment means that the serial initialization configuration is performed between the host device 30 and the embedded device 10, so that they are consistent to ensure the correct transmission of the communication frame. It can be set according to the actual needs, and is not limited here.
[0080] S302, receiving a communication frame containing a plurality of log information through serial communication.
[0081] Among them, the communication frame output by the embedded device 30 executing the log output method in one or more embodiments described above is transmitted to the host device 30 based on the serial communication established, and is received by the host device 30.
[0082] S303, extracting log information contained in the communication frame according to a preset communication format.
[0083] The host device 30 extracts log information contained in the communication frame based on a communication format adopted by the communication frame (i.e., the content of the content field).
[0084] S304, parsing the log information in the preset structured data format to generate corresponding state data.
[0085] The type field of the log information identifies the type of the log information. That is, the value of the type field has a predetermined corresponding relationship with the type of the log information. The host device 30 can complete the parsing of the log information based on the corresponding relationship between the value of the type field and the corresponding log information type by using a preconfigured or self-defined script tool to obtain the corresponding state data.
[0086] For example, the value of the type field FLAG of a certain log information is 0x0301, and the value of the value field VALUE is 0x0064. The host device 30 parses and determines that 0x0301 represents that the type of the log information is motor speed, and the unit is rpm, by using a preconfigured script tool (which predefines the mapping relationship between the type field and the type of the log information). Then 0x0064 is converted to the decimal value 100, and finally the corresponding state data is determined to be: the motor speed is 100 rpm according to the parsing rule.
[0087] S305, outputting the state data.
[0088] After the parsing is completed, the host device 30 can display the state data (for example, the motor speed mentioned above) to the developer in the form of visual information through a display or other suitable type of interactive device, so that the developer can understand the current state of the embedded device and complete the debugging work.
[0089] The embodiment of the present application further provides a log output device. As shown in the figure, Figure 9 The log output device 400 includes a log information generation module 410, a log information reading module 420, and a log information sending module 430.
[0090] The log information generation module 410 is configured to generate a plurality of log information and perform a write operation to sequentially write the plurality of log information to a cache area during a first period. The log information is state data of a corresponding collection node recorded in a preset structured data format. The log information reading module 420 is configured to perform a read operation to sequentially read the log information from the cache area during a second period.
[0091] The log information sending module 430 is configured to encapsulate the read state information into a communication frame in a preset communication format, and send the communication frame to an external device. The write operation is asynchronous with the read operation in time.
[0092] Specifically, the first period is a working period in which the embedded device performs a task operation, and the second period is an idle period in which the embedded device does not perform the task operation.
[0093] Specifically, the log information in the preset structured data format includes a type field for recording a state data type and a value field for recording a state data value. The communication frame in the preset communication format includes a header field, a length field, a content field, and a tail field arranged in sequence. The header field is used to identify the start of the communication frame, the length field is used to indicate the length of the content field, the content field is composed of a plurality of log information, and the tail field is used to identify the end of the communication frame.
[0094] In some embodiments, the log information generating module 410 is specifically configured to: when the cache area is in a first write state, determine a current write position; write the log information to the cache area from the current write position; incrementally update the write position according to the length of the written log information; and when the cache area is in a second write state, stop the write operation. The first write state is that the cache area is not fully occupied, and the second write state is that the cache area is fully occupied.
[0095] Correspondingly, the log information reading module 420 is specifically configured to: when the cache area is in a first read state, determine a current read position; read the log information written in the cache area from the current read position; incrementally update the read position according to the length of the read log information; and when the cache area is in a second read state, stop the read operation. The first read state is that the log information written in the cache area is not completely read, and the second read state is that the log information written in the cache area is completely read.
[0096] Specifically, the cache area is a ring queue structure, so that the write position or the read position is reset to the start position of the cache area after being incrementally updated to the end position of the cache area.
[0097] Therefore, before the write operation is performed, if the write position is incrementally updated to the same as the current read position, it is determined that the cache area is in the second write state, otherwise it is determined that the cache area is in the first write state. Before the read operation is performed, if the read position is incrementally updated to the same as the current write position, it is determined that the cache area is in the second read state, otherwise it is determined that the cache area is in the first read state.
[0098] The embodiment of the present application further provides a log acquisition device. As shown in the figure, the log acquisition device 500 comprises a communication module 510, an analysis module 520 and an output module 530. Figure 10
[0099] The communication module 510 is configured to establish serial communication with the embedded device, and receive a communication frame containing a plurality of log information through the serial communication. The analysis module 520 is configured to extract the log information contained in the communication frame according to a preset communication format, and analyze the log information in a preset structured data format to generate corresponding state data. The output module 530 is configured to output the state data.
[0100] The skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the functional modules described above can refer to the corresponding method steps in the foregoing embodiments, which will not be described here. The skilled in the art can use different methods for each specific application to implement the described functions, for example, a computer software program containing the step flow of the method embodiments described above can be stored in a computer readable storage medium, so that the program can implement one or more step flows of the method embodiments described above when executed.
[0101] Figure 11 The structure of the embedded device of the embodiment of the present application is shown, and the embodiment of the present application does not limit the specific implementation of the embedded device.
[0102] As shown in the figure, the embedded device 600 can comprise a processor 610, a communication interface 620, a memory 630 and a communication bus 640. Figure 11
[0103] The processor 610, the communication interface 620 and the memory 630 complete the communication among each other through the communication bus 640. The communication interface 620 is configured to communicate with other external devices. The processor 610 is configured to execute the program 650 to implement the log output method in one or more embodiments described above.
[0104] Specifically, the program 650 can comprise program codes, and the program codes comprise computer operation instructions. When the program 650 is called, the processor 610 executes the computer operation instructions, thereby implementing the steps in the log output method in one or more embodiments.
[0105] According to different actual application scenarios, the processor 610 can be of a corresponding type, including but not limited to a microcontroller (MCU), a mainstream embedded processor such as an ARM architecture processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), and other types of processors, as long as they can provide the required operation and control capabilities to meet the actual application scenarios.
[0106] The memory 630 is used to store the program 650. It includes a program storage area and a data storage area. The program storage area is used to store firmware programs, embedded applications, and various functional modules; the data storage area is used to store data and operation results during program running. For example, the memory 630 can include on-chip RAM memory (for temporary storage of data during program running), on-chip Flash memory (for storing program code and configuration data), and EEPROM or other types of non-volatile memory (for storing parameters that need to be saved during power failure).
[0107] The embodiments of the present application also provide a computer readable storage medium. The computer readable storage medium can be a non-volatile computer readable storage medium. The computer readable storage medium stores a computer program.
[0108] The computer program is executed by the processor to implement one or more steps of the log output method or the log acquisition method disclosed in the embodiments of the present application. The complete computer program product is embodied on one or more computer readable storage media containing the computer program disclosed in the embodiments of the present application.
[0109] The above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; under the idea of the present application, the technical features in the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other changes of different aspects of the present application as described above, which are not provided in detail; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A log output method, characterized in that, include: During the first period, several log messages are generated; The log information is the status data of the corresponding collection node recorded using a preset structured data format; Perform a write operation to sequentially write several log messages into the cache area; During the second period, a read operation is performed to sequentially read the log information from the cache area; The read status information is encapsulated into a communication frame conforming to a preset communication format and sent to an external device; The write operation and the read operation are executed asynchronously in time.
2. The log output method according to claim 1, characterized in that, The log information using a preset structured data format includes: The type field is used to record the type of the status data; Numerical fields are used to record the numerical values of the status data.
3. The log output method according to claim 1, characterized in that, The communication frame conforming to the preset communication format includes: a header field, a length field, a content field, and a tail field arranged in sequence; The header field is used to identify the start of the communication frame; the length field is used to indicate the length of the content field; the content field consists of several log information entries; and the tail field is used to identify the end of the communication frame.
4. The log output method according to claim 1, characterized in that, The write operation, which sequentially writes several log messages into the cache area, specifically includes: When the cache area is in the first write state, determine the current write position; Write the log information to the cache area from the current write position; The write position is incremented and updated according to the length of the written log information; The write operation is stopped when the cache area is in the second write state; Wherein, the first write state is when the cache area is not fully occupied; the second write state is when the cache area is fully occupied.
5. The log output method according to claim 4, characterized in that, During the second period, a read operation is performed to read several log messages from the cache area, specifically including: When the cache area is in the first read state, determine the current read position; Read the log information written to the cache area from the current read position; The reading position is incremented and updated based on the length of the read log information; The read operation is stopped when the cache area is in the second read state; The first read state is when the log information written in the cache area has not been fully read; the second read state is when the log information written in the cache area has been fully read.
6. The log output method according to claim 5, characterized in that, When the write position is incremented to be the same as the current read position, the cache area is determined to be in the second write state; When the read position is incremented to match the current write position, the cache region is determined to be in the second read state.
7. The log output method according to claim 5 or 6, characterized in that, The cache area is a circular queue structure.
8. The log output method according to claim 1, characterized in that, The first period is the working period during which the embedded device performs task operations, and the second period is the idle period during which the embedded device does not perform task operations.
9. A log acquisition method, characterized in that, include: Establish serial communication with the embedded device; The serial communication receives communication frames containing several log information. According to the preset communication format, extract the log information contained in the communication frame; Parse log information using a preset structured data format and generate corresponding status data; Output the status data.
10. An embedded device, characterized in that, include: A memory and a processor, the processor being communicatively connected to the memory, the memory storing computer program instructions that, when invoked by the processor, cause the processor to execute the log output method as described in any one of claims 1-8.