Log recording method and device of embedded equipment, electronic equipment and medium
By establishing a well-known pipeline for each thread in the embedded device and using system call functions for monitoring, the problem of confusing logging and low efficiency during multi-thread concurrency is solved, and more accurate and efficient logging is achieved.
Patent Information
- Application Number
- CN202410912929.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2044-07-09
AI Technical Summary
In the prior art, when embedded devices have multiple threads concurrently, log recording is prone to confusion and low efficiency due to preemption, and cannot effectively solve the problems of incomplete content recording and long processing time between multiple threads.
By selecting the logging thread and other threads in the business core program to establish a named pipe, and using the logging thread to monitor the preset data events under each named pipe in the structure array, and using the system call function to perform polling monitoring , generate the final log record.
It avoids the problems of incomplete content recording and long processing time caused by multi-thread preemption, and improves the accuracy and efficiency of log recording.
Smart Images

Figure CN118796642A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a log recording method, device, electronic device and medium for an embedded device. Background Art
[0002] Embedded systems are application-centric, based on computer technology, and can be customized in terms of hardware and software. They are suitable for special computer systems that have strict requirements on functions, reliability, cost, volume, and power consumption. Embedded systems have been widely used in many different fields. With the delivery and use of embedded devices, technological updates and iterations, log management is an issue that embedded device manufacturers must consider. In order to facilitate the provision of subsequent security services, a stable log recording and query mechanism needs to be provided.
[0003] However, in the prior art, log data of embedded devices are usually recorded by calling a log recording function, and multi-thread preemption often occurs, resulting in log recording disorder and low log recording efficiency. Summary of the invention
[0004] In view of this, the purpose of the present application is to provide a logging method, apparatus, electronic device and medium for an embedded device, so as to solve the problem of log recording disorder and low log recording efficiency caused by multi-thread preemption.
[0005] In a first aspect, an embodiment of the present application provides a log recording method for an embedded device, comprising:
[0006] Select a logging thread for logging from multiple threads corresponding to the business core program, and establish a named pipeline between the logging thread and other threads;
[0007] Create a structure array to reflect the triggering status of preset data events in other threads. Each element in the structure array corresponds to a named pipe.
[0008] The logging thread is used to monitor the preset data events under each named pipe in the structure array to generate the final log record according to the monitoring results.
[0009] Optionally, a logging thread is used to monitor preset data events under each named pipe in the structure array, including: using the logging thread to call a system call function, and polling and monitoring the preset data events under each named pipe in the structure array through the system call function, and the system call function is used to monitor changes in the status of multiple file descriptors.
[0010] Optionally, a structure array is created to reflect the triggering conditions of preset data events in other threads, including: creating a structure array according to the number of named pipes; and for each element in the structure array, setting the named pipe corresponding to the element and the preset data event corresponding to the named pipe.
[0011] Optionally, the preset data events under each named pipe in the structure array are polled and monitored through a system call function, including: obtaining the return value of the system call function, and determining whether the return value is greater than a preset threshold; if it is greater than the preset threshold, traversing each element in the structure array to determine the target named pipe that triggers the preset data event.
[0012] Optionally, the final log record is generated in the following manner: for a target named pipe, log data is obtained according to a preset data event corresponding to the target named pipe; and the log data is processed using a log record function to obtain a final log record.
[0013] Optionally, the log data is processed using a logging function to obtain a final log record, including: extracting target log information from the log data; filling a log record structure with the target log information, and obtaining log time header information based on the current system time; and generating a final log record based on the log category and log time header information corresponding to the log data.
[0014] Optionally, log time header information is obtained according to the current system time, including: calling the log file path index function to determine the time index category corresponding to the log time; generating a target file path corresponding to the time index category to obtain the log time header information according to the target file path.
[0015] In a second aspect, an embodiment of the present application further provides a log recording device for an embedded device, the device comprising:
[0016] A logging thread selection module is used to select a logging thread for logging from multiple threads corresponding to the business core program, and to establish a named pipeline between the logging thread and the other threads;
[0017] The structure creation module is used to create a structure array for reflecting the triggering conditions of preset data events in other threads. Each element in the structure array corresponds to a named pipeline.
[0018] The event monitoring module is used to monitor the preset data events under each named pipeline in the structure array by using the log recording thread to generate the final log record according to the monitoring results.
[0019] In a third aspect, an embodiment of the present application further provides an electronic device, comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate through the bus, and when the machine-readable instructions are executed by the processor, the steps of the logging method for the embedded device as described above are performed.
[0020] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the logging method for an embedded device as described above are executed.
[0021] The embodiments of the present application bring the following beneficial effects:
[0022] The embodiments of the present application provide a logging method, device, electronic device and medium for an embedded device. When multiple threads of the embedded device are concurrent, the method can record log data exclusively through a selected logging thread, and other business threads establish named pipelines, thereby avoiding the problems of incomplete content recording and excessive processing time caused by the mutual preemption of multiple threads when simply calling a logging function to record log data. Compared with the logging method for embedded devices in the prior art, the method solves the problems of disordered logging and low logging efficiency caused by the preemption of multiple threads.
[0023] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0025] Figure 1 A flow chart of a log recording method for an embedded device provided in an embodiment of the present application is shown;
[0026] Figure 2 A flow chart of a logging method based on a logging function provided in an embodiment of the present application is shown;
[0027] Figure 3 A schematic diagram showing the structure of a log recording device for an embedded device provided in an embodiment of the present application is shown;
[0028] Figure 4A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0029] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application usually described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, each other embodiment obtained by those skilled in the art without making creative work belongs to the scope of protection of the present application.
[0030] It is worth noting that before the present application was proposed, the embedded system was application-centered, based on computer technology, and the software and hardware could be tailored. It was suitable for application systems with strict requirements on functions, reliability, cost, volume, and power consumption. Now, embedded systems have been widely used in many different fields. With the delivery and use of embedded devices, technology updates and iterations, log management is an issue that embedded device manufacturers must consider. In order to facilitate the provision of subsequent guarantee services, a stable log recording and query mechanism needs to be provided. However, in the prior art, the log data of embedded devices is usually recorded by calling a log recording function. Since the log recording content is large, such as successful business interaction, abnormal data content, abnormal temperature detected by the internal sensor of the device, abnormal ambient parameters, etc., these data need to be recorded, and different businesses have their own processing threads. Therefore, in actual applications, there may be a need to record a large number of data packets in a short period of time, and the prior art usually uses a log recording function for log recording, which is easy to cause multi-thread preemption, resulting in incomplete content recording and long log processing time.
[0031] Based on this, an embodiment of the present application provides a log recording method for an embedded device to improve the accuracy and efficiency of log recording.
[0032] The terms involved in the embodiments of the present application are explained below.
[0033] Named pipe: is an inter-process communication mechanism that allows unrelated processes to communicate. The main difference between a named pipe (FIFO) and an unnamed pipe (pipe) is that a named pipe has a name and can be referenced and operated like a file. This communication method allows one process to write data to the pipe, while another process can read data from the pipe.
[0034] File descriptor: The kernel uses file descriptors to access files. File descriptors are non-negative integers. When opening an existing file or creating a new file, the kernel returns a file descriptor. Reading and writing files also require the use of file descriptors to specify the file to be read or written. Each file descriptor corresponds to an open file, and different file descriptors can point to the same file. The same file can be opened by different processes or multiple times in the same process.
[0035] See also Figure 1 , Figure 1 This is a flow chart of a log recording method for an embedded device provided in an embodiment of the present application. Figure 1 As shown, the logging method of the embedded device provided by the embodiment of the present application includes:
[0036] Step S101 , selecting a logging thread for logging from a plurality of threads corresponding to the business core program, and establishing a named pipe between the logging thread and the other threads.
[0037] The business core program may refer to the main program used to implement business functions in an embedded device.
[0038] In order to realize business functions, the business core program will create multiple threads to process business data in parallel.
[0039] In the embodiment of the present application, assuming that the business core program of the embedded device has created 4 threads in total, then one thread set in advance is selected from the 4 threads as the log recording thread for recording logs, and the remaining 3 threads are used as business threads. At the same time, a named pipe is established between the log business thread and the other 3 business threads. Wherein, a named pipe is also called a named pipe, and the number of named pipes is 3, and a named pipe is established between each of the remaining threads and the log recording thread.
[0040] Step S102, creating a structure array for reflecting the triggering conditions of preset data events in other threads.
[0041] In this step, the structure array may refer to an array of the pollfd structure type, and each element in the structure array corresponds to a named pipe.
[0042] Each element in the structure array corresponds to a named pipe, so that the corresponding named pipe can be monitored by monitoring the data changes of the element.
[0043] In an embodiment of the present application, a structure array is created according to the number of named pipes. Taking the above example as an example, the number of named pipes is 3, and the number of elements in the created structure array is also 3. Then the structure array is initialized, that is, for each element in the structure array, the named pipe corresponding to the element and the preset data event corresponding to the named pipe are set. Taking the above example as an example, the file descriptor of the named pipe can be assigned to the corresponding element in the structure array, that is, the fd field of the pollfd structure is set to the file descriptor of the named pipe to establish the correspondence between the element and the named pipe. At the same time, the preset data event to be monitored is set for each element. For example: if it is desired to monitor whether the pipeline has readable data, the event field events of the element in the pollfd structure is set to POLLIN. Among them, the preset data events include but are not limited to: data is readable, data is writable, and errors occur.
[0044] Step S103, using a log record thread to monitor the preset data events under each named pipe in the structure array, so as to generate a final log record according to the monitoring result.
[0045] In this step, since the log recording thread is used to record logs exclusively, the problem of multi-thread preemption is avoided, so that not only the problem of incomplete log recording can be solved, but also the log recording efficiency can be improved.
[0046] In the embodiment of the present application, the logging thread can be used to call the system call function, and the preset data events under each named pipe in the structure array can be polled and monitored through the system call function. The system call function can refer to the poll function, and the system call function is used to monitor the status changes of multiple file descriptors.
[0047] Taking the above example, the four threads are thread A, thread B, thread C and thread D, where thread A is the thread for receiving logs, i.e., the log recording thread, and thread B, thread C and thread D are business threads. The business threads are responsible for sending their respective log data to be recorded to the log recording thread A through their respective corresponding named pipes, which is equivalent to having three pipes connected to thread A and transmitting data to thread A. Thread A needs to determine which business thread the data comes from. If the received log data is parsed and found to be correct, it starts to receive the transmitted log data.
[0048] For example, the named pipes are elements 0, 1, and 2 in the structure array corresponding to threads B, C, and D respectively. The pollfd structure array fds setting method can be implemented by the following code:
[0049] struct pollfd fds[3];
[0050] fds[0].fd=open(FIFO_B,O_RDONLY|O_NONBLOCK);
[0051] fds[0].events = POLLIN;
[0052] fds[1].fd=open(FIFO_C,O_RDONLY|O_NONBLOCK);
[0053] fds[1].events = POLLIN;
[0054] fds[2].fd=open(FIFO_D,O_RDONLY|O_NONBLOCK);
[0055] fds[2].events=POLLIN.
[0056] The three elements in the structure array fds are three pollfd type structures, corresponding to three named pipes respectively. The logging thread calls the poll function to obtain the return value of the system call function poll. Then, determine whether the return value of the poll function is greater than the preset threshold, where the preset threshold can be 0. If it is greater than the preset threshold, for example: the return value of the poll function is 1, it means that at least one file descriptor is ready, then traverse each element in the structure array, obtain the value of the revents field of each element, to determine the target named pipe that triggers the preset data event, and determine the target named pipe that triggers the preset data time to determine the monitoring result, for example: the second named pipe is the target named pipe. Here, the above polling process can be implemented by the following code:
[0057] for(int i=0;i<3;i++)
[0058] {if(fds[i].revents&POLLIN);
[0059] {read(fds[i].fd,buffer,sizeof(buffer)-1);
[0060] printf("Received log:%s",buffer);}
[0061] }.
[0062] Among them, the pollfd fds[3] structure array has three elements in total. The revents element is maintained by the Linux kernel, which means that if there is log data to be received, it is maintained by the Linux kernel. For example, if there is log data to be received in the second named pipe, the return value of the poll function is greater than 0. Then, when the for loop is used for polling, it should be when i is equal to 1, that is, when fds[1].revents&POLLIN==1 of the pollfd fds[3] structure is established, it can be determined that there is log data to be received in the second named pipe. If there is log data to be received in the first named pipe, fds[0].revents&POLLIN==1 should be established.
[0063] After determining the target named pipe, the final log record can be generated in the following way: for the target named pipe, log data is obtained according to the preset data event corresponding to the target named pipe; the log data is processed by the log recording function to obtain the final log record. For example: if the preset data event corresponding to the target named pipe is data readable or data writable, the first log data for recording the log event name and the specific content of the log can be obtained from the remaining business threads corresponding to the target named pipe, and the obtained log data is sent to the log recording function; if the preset data event corresponding to the target named pipe is an error, the second log data for recording the log event name is obtained, and the obtained log data is sent to the log recording function.
[0064] When using the logging function to process log data, the target log information can be extracted from the log data; the log record structure is filled with the target log information, and the log time header information is obtained according to the current system time; and the final log record is generated according to the log category and log time header information corresponding to the log data.
[0065] Refer to the following Figure 2 To introduce the processing of logging functions.
[0066] Figure 2 A flow chart of a logging method based on a logging function provided in an embodiment of the present application is shown, such as Figure 2 As shown, the processing of the logging function includes:
[0067] Step S1031, obtaining target log information of log data.
[0068] Here, after receiving the log data packet, the log recording function splits the log data packet according to the data packet communication protocol to obtain the target log information. The target log information includes log type, data domain, data length, event name, event importance level, whether to record only the event name, whether to record the event content, and event occurrence time.
[0069] Step S1032, creating a log record structure.
[0070] Specifically, the log record structure is not a pollfd structure, it is just a simple structure.
[0071] In the embodiment of the present application, it is assumed that the embedded device receives a reset instruction, and it is necessary to record the relevant information of the reset instruction. One case is to record only the event name, that is, to record in the log when the reset event occurred; the other case is to record the event name and event content, that is, to record the time when the reset event occurred and the detailed reset instruction content through the log record structure.
[0072] Step S1033, determine the log category and log time header information.
[0073] Here, the log category can be determined based on the log data. The log category can refer to the category set by the system, including but not limited to: network anomaly, algorithm module anomaly, resource completeness check anomaly, and structure anomaly. After determining the log category, it is necessary to extract the current time of the system to encapsulate the log time header information according to the current time of the system, wherein the log time header information is used to determine the storage path of the log record.
[0074] When determining the log time header information based on the current system time, the log file path index function can be called to determine the time index category corresponding to the log time (event occurrence time), and generate a target file path corresponding to the time index category to determine the log time header information based on the target file path.
[0075] The time index categories include year, month, and day. The following describes the process of obtaining the target file path under different time index categories.
[0076] If the time index category is year, first get the current system time, determine whether the log time is abnormal based on the current system time, and exit if the log time is abnormal. If the log time is normal, generate the target file path under the time index category of "year", and determine whether the folder under the target file path exists. If the folder under the target file path exists, return the target file path directly, and extract the log time header information from the target file path to store the log according to the log time header information. If the folder under the target file path does not exist, create the corresponding folder under the target file path, and return the final target file path to extract the log time header information from the final target file path.
[0077] If the time index category is month, the system current time is also obtained first, and the year in the log time is determined to be abnormal according to the system current time. If the year in the log time is abnormal, it exits directly. If the year in the log time is normal, the year target file path is generated, and it is determined whether the folder under the year target file path exists. If the folder under the year target file path exists, it is determined whether the month in the log time is abnormal. If the folder under the year target file path does not exist, a folder under the year target file path is created to determine whether the month in the log time is abnormal. When determining whether the month in the log time is abnormal, if the month is abnormal, it exits directly. If the month is normal, the month target file path is assembled and generated, and it is determined whether the folder under the month target file path exists. If the folder under the month target file path does not exist, a folder under the month target file path is created. If the folder under the month target file path exists, the month target file path is directly returned as the final target file path to extract the log time header information from the final target file path.
[0078] If the time index category is day, first obtain the current system time, and determine whether the year of the log time is abnormal according to the current system time. If the year in the log time is abnormal, exit directly. If the year in the log time is normal, assemble and generate the year target file path, and determine whether the folder under the year target file path exists. If the folder under the year target file path exists, determine whether the month in the log time is abnormal, and return the target file path according to the abnormal judgment result of the month; if the folder under the year target file path does not exist, create the corresponding folder under the year target file path, and then determine whether the month in the log time is abnormal. When determining whether the month in the log time is abnormal, if the month in the log time is abnormal, exit directly; if the month in the log time is normal, generate the month target file path, and determine whether the folder under the month target file path exists. If the folder under the month target file path exists, determine whether the day (date) in the log time is abnormal. If the folder under the month target file path does not exist, create the folder under the month target file path, and determine whether the day in the log time is abnormal. When determining whether the date in the log time is abnormal, if the date is abnormal, exit directly; if the date is normal, assemble and generate the target file path for the date, and determine whether the folder under the target file path for the date exists. If the folder under the target file path for the date does not exist, create the folder under the target file path for the date; if the folder under the target file path for the date exists, directly return the target file path for the date as the final target file path, so as to extract the log time header information from the final target file path.
[0079] Step S1034, determine the log record name and log record method.
[0080] A log record name corresponding to the log category can be generated, and a specific log record method can be determined according to the value of events, wherein the log record method includes a record method that only records the event name and an event write record method that only records the event name and time.
[0081] Step S1035, start recording logs.
[0082] After determining the log record name and log record method, the log data can be recorded according to the log record name and the specific log record method until the log record is completed, and the log record structure of the completed log record is stored in the final target file storage path corresponding to the log time header information.
[0083] Compared with the logging method for embedded devices in the prior art, the present application can, when multiple threads of the embedded device are concurrent, record log data specifically through a selected logging thread, and establish a named pipeline for other business threads, thereby avoiding the problem of incomplete content recording and long processing time caused by the mutual preemption of multiple threads when simply calling the logging function to record log data. Compared with the logging method for embedded devices in the prior art, the present application solves the problem of log recording confusion and low log recording efficiency caused by multi-thread preemption.
[0084] Based on the same inventive concept, the embodiment of the present application also provides a log recording device for an embedded device corresponding to the log recording method for an embedded device. Since the principle of solving the problem by the device in the embodiment of the present application is similar to the log recording method for the embedded device in the embodiment of the present application, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.
[0085] See also Figure 3 , Figure 3 This is a schematic diagram of the structure of a log recording device for an embedded device provided in an embodiment of the present application. Figure 3 As shown in , the logging device 200 of the embedded device includes:
[0086] The logging thread selection module 201 is used to select a logging thread for logging from multiple threads corresponding to the business core program, and to establish a named pipeline between the logging thread and other threads;
[0087] A structure creation module 202 is used to create a structure array for reflecting the triggering conditions of preset data events in other threads, and each element in the structure array corresponds to a named pipeline;
[0088] The event monitoring module 203 is used to monitor the preset data events under each named pipeline in the structure array by using the log recording thread, so as to generate a final log record according to the monitoring result.
[0089] In a possible example, the event monitoring module 203 includes a polling detection module, which is used to: use the logging thread to call the system call function, and poll and monitor the preset data events under each named pipe in the structure array through the system call function, and the system call function is used to monitor the status changes of multiple file descriptors.
[0090] In a possible example, the structure creation module 202 is specifically used to: create a structure array according to the number of named pipes; and for each element in the structure array, set the named pipe corresponding to the element and the preset data event corresponding to the named pipe.
[0091] In a possible example, the polling detection module is specifically used to: obtain the return value of the system call function and determine whether the return value is greater than a preset threshold; if it is greater than the preset threshold, traverse each element in the structure array to determine the target named pipeline that triggers the preset data event.
[0092] In a possible example, the event monitoring module 203 also includes a log generation module, which includes a log data acquisition module and a log record generation module. The log data acquisition module is used to: obtain log data for a target named pipe according to a preset data event corresponding to the target named pipe; the log record generation module is used to process the log data using a log record function to obtain a final log record.
[0093] In a possible example, the log record generation module includes an information extraction module, a time header information acquisition module and a log recording module. The information extraction module is used to extract target log information from the log data; the time header information acquisition module is used to fill the log record structure with the target log information, and obtain the log time header information according to the current system time; the log recording module is used to generate the final log record according to the log category and log time header information corresponding to the log data.
[0094] In a possible example, the time header information acquisition module is specifically used to: call the log file path index function to determine the time index category corresponding to the log time; generate a target file path corresponding to the time index category to obtain the log time header information according to the target file path.
[0095] See also Figure 4 , Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 4 As shown in , the electronic device 300 includes a processor 310 , a memory 320 and a bus 330 .
[0096] The memory 320 stores machine-readable instructions executable by the processor 310. When the electronic device 300 is running, the processor 310 communicates with the memory 320 via the bus 330. When the machine-readable instructions are executed by the processor 310, the above-mentioned Figure 1 The steps of the log recording method for an embedded device in the method embodiment shown in the figure, and the specific implementation method thereof can be referred to the method embodiment, which will not be described in detail here.
[0097] The present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the computer program can execute the above-mentioned Figure 1The steps of the log recording method for an embedded device in the method embodiment shown in the figure, and the specific implementation method thereof can be referred to the method embodiment, which will not be described in detail here.
[0098] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0099] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0100] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0101] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0102] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present application can essentially be embodied in the form of a software product, or in other words, the part that contributes to the prior art or the part of the technical solution. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0103] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the above-mentioned embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-mentioned embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A logging method for an embedded device, characterized in that: include: Selecting a logging thread for logging from multiple threads corresponding to the business core program, and establishing a named pipeline between the logging thread and the remaining threads; Creating a structure array for reflecting the triggering conditions of preset data events in the remaining threads, each element in the structure array corresponds to a named pipeline; The log record thread is used to monitor the preset data events under each named pipeline in the structure array to generate a final log record according to the monitoring result.
2. The method according to claim 1, characterized in that The method of using the log recording thread to monitor the preset data events under each named pipeline in the structure array includes: The logging thread is used to call a system call function, and the system call function is used to poll and monitor preset data events under each named pipe in the structure array. The system call function is used to monitor changes in the states of multiple file descriptors.
3. The method according to claim 1, characterized in that The creating of a structure array for reflecting the triggering conditions of the preset data events in the remaining threads includes: Create an array of structures according to the number of named pipes; For each element in the structure array, a named pipe corresponding to the element and a preset data event corresponding to the named pipe are set.
4. The method according to claim 2, characterized in that The polling and monitoring of the preset data events under each named pipe in the structure array by the system call function includes: Obtaining a return value of the system call function, and determining whether the return value is greater than a preset threshold; If it is greater than the preset threshold, each element in the structure array is traversed to determine the target named pipeline that triggers the preset data event.
5. The method according to claim 4, characterized in that The final log record is generated by: For the target named pipe, log data is obtained according to the preset data event corresponding to the target named pipe; The log data is processed using a log record function to obtain a final log record.
6. The method according to claim 5, characterized in that The log data is processed by the log record function to obtain a final log record, including: Extract target log information from log data; Fill the log record structure with the target log information, and obtain the log time header information according to the current system time; A final log record is generated according to the log category corresponding to the log data and the log time header information.
7. The method according to claim 6, characterized in that The log time header information is obtained according to the current system time, including: Call the log file path index function to determine the time index category corresponding to the log time; A target file path corresponding to the time index category is generated to obtain log time header information according to the target file path.
8. A log recording device for an embedded device, characterized in that: include: A logging thread selection module is used to select a logging thread for logging from multiple threads corresponding to the business core program, and to establish a named pipeline between the logging thread and the remaining threads; A structure creation module, used for creating a structure array for reflecting the triggering conditions of preset data events in the remaining threads, wherein each element in the structure array corresponds to a named pipeline; The event monitoring module is used to monitor the preset data events under each named pipeline in the structure array by using the log recording thread, so as to generate a final log record according to the monitoring result.
9. An electronic device, characterized in that: include: A processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the steps of the logging method for an embedded device as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the logging method for an embedded device as claimed in any one of claims 1 to 7 are executed.
Citation Information
Patent Citations
Method and system for responding user request information
CN101729415A
Inter-thread message monitoring method, device, computer device and storage medium
CN107729221A
Write-ahead logging through plurality of logging buffers using nvm
CN108694231A
Industrial information log alarm method and device, electronic equipment and storage medium
CN116319054A
Log recording method and device of GNSS processor, storage medium and vehicle
CN117555856A
