Log processing method and device, equipment, medium, product and vehicle

By using two queues in shared memory in intelligent driving systems and switching their read and write characteristics when specific conditions are met, the problems of long log write delay and excessive processor resource consumption are solved, and efficient log processing and storage are achieved.

CN120011331APending Publication Date: 2025-05-16CHONGQING CHANGAN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510094843.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-21
Publication Date
2025-05-16

AI Technical Summary

Technical Problem

In intelligent driving systems, the log writing delay is long, which affects the operation of the program, and the processor resource consumption is too high, resulting in low log storage efficiency and easy loss.

Method used

Two queues in shared memory are adopted, one for log writing and the other for log reading, and their read and write characteristics are switched when specific conditions are met to improve the writing and reading efficiency of log information.

Benefits of technology

By switching the read and write characteristics of the queue, the mutual influence between log writing and reading is avoided, the delay of log writing is reduced, the efficiency of log processing is improved, and the consumption of processor resources is reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120011331A_ABST
    Figure CN120011331A_ABST
Patent Text Reader

Abstract

The invention relates to a log processing method and device, equipment, a medium, a product and a vehicle, and relates to the technical field of data processing. The method at least solves the technical problems that in the related technology, program running is affected due to long log writing time delay, and processor resource consumption is too high in the log storage process, and comprises the steps that log information to be written is written into a first queue in a shared memory, and the shared memory comprises the first queue and a second queue, the read-write characteristics of the first queue and the second queue are any one of log writing and log reading, and the read-write characteristics of the first queue and the second queue are different; under the condition that the first queue and the second queue meet the switching condition, switching read-write characteristics of the first queue and the second queue; and reading the log information stored in the switched first queue to generate a log file, and writing newly generated log information in the switched second queue.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and specifically to a log processing method, device, equipment, medium, product and vehicle. Background Art

[0002] With the continuous development of vehicle intelligent driving technology, applications related to business such as perception and planning control involved in intelligent driving systems need to process a large amount of lidar and camera-related information in real time, and make reasonable driving decisions in a timely manner based on this information. Therefore, the log storage of these applications has very high requirements for processor performance and latency. When the chip computing power in the intelligent driving controller is limited, the log storage process requires the consumption of as little processor power as possible, and the business thread is required to write the log in the shortest possible time to avoid affecting the subsequent business processing flow of the application.

[0003] In the related art, the log information of each process is first saved in a lock-free queue in the shared memory, and the log center process reads the log from the lock-free queue in the shared memory for log persistent storage. Although this method records the log information in the lock-free queue of the shared memory, the application log writing and the log center process reading the log are both operated on the same lock-free queue. When the number of processes and threads is large, once the log center process cannot read the log in the lock-free queue in time, it will intensify the competition for log writing, thereby increasing the delay of log writing and causing the loss of a large number of logs. Therefore, when storing the logs of the application, there is a long delay, which affects the operation of the application, resulting in low log storage efficiency and easy loss of logs. Summary of the invention

[0004] The present application provides a log processing method, device, equipment, medium, product and vehicle to at least solve the technical problems in the related art that the long log writing delay affects the program operation and the processor resource consumption is too high during the log storage process. The technical solution of the present application is as follows:

[0005] According to a first aspect of the present application, a log processing method is provided, the method comprising: writing log information to be written into a first queue in a shared memory, the shared memory comprising a first queue and a second queue, the read-write characteristics of the first queue and the second queue being respectively any one of log writing and log reading, the read-write characteristics of the first queue and the second queue being different, the queue whose read-write characteristic is log writing is used to store log information to be written, and the queue whose read-write characteristic is log reading is used to read written log information to generate a log file; when the first queue and the second queue meet a switching condition, switching the read-write characteristics of the first queue and the second queue; reading the log information stored in the switched first queue to generate a log file, and writing the newly generated log information in the switched second queue.

[0006] According to the above-mentioned technical means, the present application can write the log information to be written into the first queue whose read-write characteristic is log writing in the shared memory, and switch the read-write characteristics of the first queue and the second queue in the shared memory when the first queue and the second queue meet the switching condition. Thereby, after the read-write characteristics of the first queue and the second queue are switched, the log information stored in the first queue after switching can be read to generate a log file, and the newly generated log information is written in the second queue after switching. In this way, since the shared memory includes the first queue and the second queue with different read-write characteristics, there will be a queue for log writing and a queue for log reading in the two queues at the same time. Based on this, the log information to be written can be written into the queue whose read-write characteristic is log writing at any time, and the log information stored in the queue whose read-write characteristic is log reading can be read in time to generate a log file. Therefore, writing log information and reading log information do not affect each other, and the efficiency of log information writing and reading can be improved by two queues, thereby reducing the delay of log writing.

[0007] In a possible implementation, the switching condition includes at least one of the following: the remaining storage space of the first queue is less than a preset threshold, and the duration of the switch between the read and write characteristics of the first queue and the second queue reaches a preset duration.

[0008] According to the above technical means, the present application can switch the read-write characteristics of the first queue and the second queue when the remaining storage space of the first queue is less than a preset threshold, or when the duration of the switch between the read-write characteristics of the first queue and the second queue reaches a preset duration. In this way, the read-write characteristics of the two queues can be switched in a timely manner without affecting the reading or writing process of the log information, thereby improving the processing efficiency of the log information.

[0009] In a possible implementation, the above-mentioned switching of the read and write characteristics of the first queue and the second queue when the first queue and the second queue meet the switching conditions includes: switching the read and write characteristics of the first queue and the second queue when the first queue and the second queue meet the switching conditions and each log information stored in the second queue is read.

[0010] According to the above technical means, when the first queue and the second queue meet the switching conditions, the present application can further consider whether each log information stored in the second queue has been read, so as to ensure that each log information stored in the second queue has been read, and then switch the read and write characteristics of the first queue and the second queue. Thus, the log information stored in the second queue will not be omitted, and the missing log information is avoided, resulting in incomplete logs.

[0011] In a possible implementation, the method further includes: if any log information stored in the second queue has not been read and the remaining storage space of the first queue is smaller than the storage space required for the log information to be written, discarding the log information to be written.

[0012] According to the above technical means, when the log information stored in the second queue has not been fully read, if the remaining storage space of the first queue cannot write the new log information to be written, the log information to be written can be discarded. This ensures the normal operation of the application and avoids abnormal conditions in the system caused by the inability to write logs.

[0013] In a possible implementation, the log information to be written is log information generated by multiple applications; the above-mentioned reading of the log information stored in the first queue after switching to generate a log file includes: traversing the log information stored in the first queue after switching, determining the correspondence between each log information and each of the multiple applications, so as to determine at least one log information of each application in the multiple applications; for each application in the multiple applications, reading at least one log information of each application from the first queue after switching in turn, and generating a log file for each application.

[0014] According to the above technical means, the present application can traverse the log information stored in the first queue after switching to determine the application to which each log information belongs, thereby determining at least one log information corresponding to each application. In this way, when reading log information from the first queue after switching to generate a log file, all log information of the same application stored in the first queue after switching can be read simultaneously each time according to different applications to generate a log file for each application. In this way, multiple readings of the first queue after switching can be avoided, thereby improving the efficiency of reading log information and the efficiency of generating log files.

[0015] In a possible implementation, the first queue after switching includes multiple slots, each slot is used to store a log information; the above-mentioned traversal of the log information stored in the first queue after switching, determining the correspondence between each log information and each application in the multiple applications, to determine at least one log information of each application in the multiple applications, includes: traversing the log information stored in each slot in the first queue after switching, generating a slot-application correspondence table, the slot-application correspondence table including the slot identifier of at least one slot corresponding to each application in the multiple applications, and the log information of each application is stored in at least one slot corresponding to each application.

[0016] According to the above technical means, the present application can traverse the log information stored in each slot in the first queue after switching to generate a slot-application correspondence table. In this way, when reading the log information stored in the first queue after switching, all log information of the application can be read from the corresponding slot according to the slot identifier of at least one slot corresponding to each application stored in the slot-application correspondence table. Without the need to analyze the application to which each log information belongs when reading the log information, the reading speed of the log information can be improved, and the processing efficiency of the log information can be improved.

[0017] In a possible implementation, for each application among the multiple applications, at least one log information of each application is read in turn from the first queue after switching to generate a log file for each application, including: for each application among the multiple applications, based on a slot-to-application correspondence table, log information stored in at least one slot corresponding to each application is read in turn from a queue with a read-write characteristic of log reading to generate a log file for each application.

[0018] According to the above technical means, when reading the log information stored in the first queue after switching, the present application can read the log information stored in the corresponding slot from the slot corresponding to the application in sequence according to different applications, based on the slot identifier of at least one slot corresponding to each application stored in the slot-application correspondence table. When reading the log information, it is not necessary to analyze the application to which each log information belongs, which can improve the reading speed of the log information and the processing efficiency of the log information.

[0019] In a possible implementation, the first queue and the second queue are lock-free queues.

[0020] According to the above technical means, the present application can store log information of different applications in the same queue by setting the first queue and the second queue as lock-free queues. And the log reading and log writing are distinguished by the two queues to avoid mutual influence between log reading and log writing. Thus, the processing efficiency of log information can be improved.

[0021] According to a second aspect provided by the present application, a log processing device is provided, the log processing device comprising: a processing module; the processing module is used to write the log information to be written into a first queue in a shared memory, the shared memory comprising a first queue and a second queue, the read and write characteristics of the first queue and the second queue are respectively any one of log writing and log reading, the read and write characteristics of the first queue and the second queue are different, the queue with the read and write characteristics of log writing is used to store the log information to be written, and the queue with the read and write characteristics of log reading is used to read the written log information to generate a log file; the processing module is also used to switch the read and write characteristics of the first queue and the second queue when the first queue and the second queue meet the switching condition; the processing module is also used to read the log information stored in the switched first queue to generate a log file, and write the newly generated log information in the switched second queue.

[0022] In a possible implementation, the switching condition includes at least one of the following: the remaining storage space of the first queue is less than a preset threshold, and the duration of the switch between the read and write characteristics of the first queue and the second queue reaches a preset duration.

[0023] In a possible implementation, the processing module is specifically configured to switch the read and write characteristics of the first queue and the second queue when the first queue and the second queue meet the switching condition and each log information stored in the second queue is read.

[0024] In a possible implementation, the processing module is further configured to discard the log information to be written if any log information stored in the second queue has not been read and the remaining storage space of the first queue is smaller than the storage space required for the log information to be written.

[0025] In a possible implementation, the log information to be written is log information generated by multiple applications; the processing module is specifically used to traverse the log information stored in the first queue after switching, determine the correspondence between each log information and each application in the multiple applications, so as to determine at least one log information of each application in the multiple applications; the processing module is specifically used to read at least one log information of each application from the first queue after switching in turn for each application in the multiple applications, and generate a log file for each application.

[0026] In a possible implementation, the first queue after switching includes multiple slots, each slot is used to store a log information; the processing module is specifically used to traverse the log information stored in each slot in the first queue after switching, and generate a slot-application correspondence table, the slot-application correspondence table includes the slot identifier of at least one slot corresponding to each application among multiple applications, and the log information of each application is stored in at least one slot corresponding to each application.

[0027] In one possible implementation, the processing module is specifically used to read the log information stored in at least one slot corresponding to each application in a queue with a read-write characteristic of log reading in turn for each application among multiple applications based on a slot-to-application correspondence table, and generate a log file for each application.

[0028] In a possible implementation, the first queue and the second queue are lock-free queues.

[0029] According to the third aspect provided by the present application, an electronic device is provided, comprising: a processor and a memory; wherein the memory is used to store one or more programs, and the one or more programs include computer execution instructions. When the electronic device is running, the processor executes the computer execution instructions stored in the memory, and the electronic device executes the method of the above-mentioned first aspect and any possible implementation method thereof.

[0030] According to the fourth aspect provided by the present application, a computer-readable storage medium is provided. When the computer instructions stored in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device executes the method of the above-mentioned first aspect and any possible implementation method thereof.

[0031] According to the fifth aspect provided by the present application, a computer program product is provided, the computer program product comprising computer instructions, when the computer instructions are executed on an electronic device, the electronic device executes the method of the above-mentioned first aspect and any possible implementation manner thereof.

[0032] According to a sixth aspect provided by the present application, a vehicle is provided, the vehicle comprising a log processing device as in the second aspect, and the vehicle is used to implement the method of the above-mentioned first aspect and any possible implementation manner thereof.

[0033] Therefore, the above technical features of the present application have the following beneficial effects:

[0034] (1) The present application can write the log information to be written into the first queue whose read-write characteristic is log writing in the shared memory, and switch the read-write characteristics of the first queue and the second queue when the first queue and the second queue in the shared memory meet the switching condition. Thus, after the read-write characteristics of the first queue and the second queue are switched, the log information stored in the switched first queue can be read to generate a log file, and the newly generated log information can be written in the switched second queue. In this way, since the shared memory includes the first queue and the second queue with different read-write characteristics, there will be a queue for log writing and a queue for log reading in the two queues at the same time. Based on this, the log information to be written can be written into the queue whose read-write characteristic is log writing at any time, and the log information stored in the queue whose read-write characteristic is log reading can be read in time to generate a log file. Therefore, writing log information and reading log information do not affect each other, and the efficiency of writing and reading log information can be improved through the two queues, thereby reducing the delay of log writing.

[0035] (2) The present application can switch the read-write characteristics of the first queue and the second queue when the remaining storage space of the first queue is less than a preset threshold, or when the duration of the switch between the read-write characteristics of the first queue and the second queue reaches a preset duration. In this way, the read-write characteristics of the two queues can be switched in a timely manner without affecting the reading or writing process of the log information, thereby improving the processing efficiency of the log information.

[0036] (3) When the first queue and the second queue meet the switching condition, the present application can further consider whether each log information stored in the second queue has been read, so as to ensure that each log information stored in the second queue has been read before switching the read and write characteristics of the first queue and the second queue. In this way, the log information stored in the second queue will not be omitted, and the missing log information will be avoided, resulting in incomplete logs.

[0037] (4) When the log information stored in the second queue has not been fully read, the application can discard the log information to be written if the remaining storage space in the first queue cannot write the new log information to be written. This ensures the normal operation of the application and avoids abnormal conditions in the system caused by the inability to write logs.

[0038] (5) The present application can traverse the log information stored in the first queue after switching to determine the application to which each log information belongs, thereby determining at least one log information corresponding to each application. In this way, when reading log information from the first queue after switching to generate a log file, all log information of the same application stored in the first queue after switching can be read simultaneously each time according to different applications to generate a log file for each application. In this way, multiple readings of the first queue after switching can be avoided, thereby improving the efficiency of reading log information and the efficiency of generating log files.

[0039] (6) The present application can traverse the log information stored in each slot in the first queue after switching to generate a slot-application correspondence table. In this way, when reading the log information stored in the first queue after switching, all log information of the application can be read from the corresponding slot according to the slot identifier of at least one slot corresponding to each application stored in the slot-application correspondence table. There is no need to analyze the application to which each log information belongs when reading the log information, which can improve the reading speed of the log information and the processing efficiency of the log information.

[0040] (7) When reading the log information stored in the first queue after switching, the present application can read the log information stored in the corresponding slots from the slots corresponding to the applications according to the slot identifier of at least one slot corresponding to each application stored in the slot-application correspondence table. This eliminates the need to analyze the application to which each log information belongs when reading the log information, thereby improving the reading speed of the log information and the processing efficiency of the log information.

[0041] (8) The present application can store log information of different applications in the same queue by setting the first queue and the second queue as lock-free queues. In addition, log reading and log writing are distinguished by the two queues to avoid mutual influence between log reading and log writing. Thus, the processing efficiency of log information can be improved.

[0042] It should be noted that the technical effects brought about by any implementation method in the second to sixth aspects can refer to the technical effects brought about by the corresponding implementation method in the first aspect, and will not be repeated here.

[0043] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] The drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present application, and together with the specification are used to explain the principles of the present application, and do not constitute improper limitations on the present application.

[0045] Figure 1 is a structural schematic diagram of a log processing system according to an exemplary embodiment;

[0046] Figure 2 is a flow chart of a log processing method according to an exemplary embodiment;

[0047] Figure 3 is a flow chart of another log processing method according to an exemplary embodiment;

[0048] Figure 4 is a structural schematic diagram of another log processing system according to an exemplary embodiment;

[0049] Figure 5 is a schematic diagram of a shared memory according to an exemplary embodiment;

[0050] Figure 6 is a flow chart of another log processing method according to an exemplary embodiment;

[0051] Figure 7 is a block diagram of a log processing device according to an exemplary embodiment;

[0052] Figure 8 is a block diagram of an electronic device according to an exemplary embodiment;

[0053] Fig. 9 The diagram is a schematic diagram showing the structure of a computer system according to an exemplary embodiment. DETAILED DESCRIPTION

[0054] In order to enable ordinary persons in the art to better understand the technical solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.

[0055] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.

[0056] The log processing method provided in the embodiment of the present application can be applied to a log processing system. Figure 1 A structural diagram of the log processing system is shown in FIG. Figure 1 As shown, the log processing system 10 includes: an application 11 , a shared memory 12 , a log service program 13 and a processor 14 .

[0057] The processor 14 is used to write the log information to be written into the first queue in the shared memory 12. The shared memory 12 includes a first queue and a second queue. The read and write characteristics of the first queue and the second queue are respectively any one of log writing and log reading. The read and write characteristics of the first queue and the second queue are different. The queue with the read and write characteristic of log writing is used to store the log information to be written, and the queue with the read and write characteristic of log reading is used to read the written log information to generate a log file.

[0058] The processor 14 is configured to switch the read and write characteristics of the first queue and the second queue when the first queue and the second queue meet a switching condition.

[0059] The log service program 13 is used to read the log information stored in the switched first queue to generate a log file, and write the newly generated log information into the switched second queue.

[0060] In a possible implementation, the switching condition includes at least one of the following: the remaining storage space of the first queue is less than a preset threshold, and the duration of the switch between the read and write characteristics of the first queue and the second queue reaches a preset duration.

[0061] In a possible implementation, the processor 14 is configured to switch the read / write characteristics of the first queue and the second queue when the first queue and the second queue meet a switching condition and each log information stored in the second queue is read.

[0062] In a possible implementation, the processor 14 is configured to discard the log information to be written if any log information stored in the second queue has not been read and the remaining storage space of the first queue is smaller than the storage space required for the log information to be written.

[0063] In one possible implementation, the log information to be written is log information generated by multiple applications 11; the processor 14 is used to traverse the log information stored in the first queue after switching, determine the correspondence between each log information and each application 11 in the multiple applications 11, so as to determine at least one log information of each application 11 in the multiple applications 11.

[0064] The log service program 13 is used to read at least one log information of each application 11 from the switched first queue in turn for each application 11 among the multiple application programs 11 , and generate a log file for each application program 11 .

[0065] In a possible implementation, the first queue after switching includes multiple slots, each slot is used to store a log information; the log service program 13 is used to traverse the log information stored in each slot in the first queue after switching, and generate a corresponding relationship table between the slots and the application 11, the corresponding relationship table between the slots and the application 11 includes the slot identifier of at least one slot corresponding to each application 11 in the multiple applications 11, and the log information of each application 11 is stored in at least one slot corresponding to each application 11.

[0066] In one possible implementation, the log service program 13 is used to read the log information stored in at least one slot corresponding to each application 11 in a queue with a read-write characteristic of log reading for each application 11 among multiple applications 11 based on a correspondence table between the slot and the application 11, and generate a log file for each application 11.

[0067] In a possible implementation, the first queue and the second queue are lock-free queues.

[0068] In the embodiment of the present application, since the application software in the intelligent driving system is sensitive to latency in processing business data, the business thread cannot be blocked for a long time during the log processing and storage process. Through the embodiment of the present application, the processing latency of log information can be reduced, and the situation of blocking business threads can be reduced. When the chip computing power is limited, the CPU consumption during the log processing and storage process is low, and it will not affect the operation of other application software in the intelligent driving system.

[0069] For ease of understanding, the log processing method provided by this application is specifically introduced below with reference to the accompanying drawings.

[0070] Figure 2 is a flow chart of a log processing method according to an exemplary embodiment, which is applied to an electronic device (processor), such as Figure 2 As shown, the log processing method includes the following S201-S203:

[0071] S201. Write the log information to be written into the first queue in the shared memory.

[0072] Among them, the shared memory includes a first queue and a second queue, the read-write characteristics of the first queue and the second queue are respectively any one of log writing and log reading, and the read-write characteristics of the first queue and the second queue are different. The queue with the read-write characteristic of log writing is used to store log information to be written, and the queue with the read-write characteristic of log reading is used to read the written log information to generate a log file.

[0073] That is, at the current moment, the read-write characteristics of the first queue are log writing, and the read-write characteristics of the second queue are log reading. When the read-write characteristics of the first queue and the second queue are subsequently switched, the read-write characteristics of the first queue are log reading, and the read-write characteristics of the second queue are log writing. In this way, the read-write characteristics of the first queue and the second queue can be continuously switched according to demand.

[0074] It should be noted that the shared memory provided in the embodiment of the present application includes two queues, one of which is used by the application to write log information, and the other is used by the log service program to read the written log information from the queue to generate a log file.

[0075] Since the read and write characteristics of the two queues are different and the read and write characteristics of the two queues can be switched, there will be a log write queue and a log read queue in the shared memory at the same time, so that the application will not affect each other when writing log information or the log service program will not affect each other when reading log information.

[0076] Optionally, in shared memory, multiple log write queues and multiple log read queues can also be included. When a log write queue is filled, the queue can be switched to the log read queue so that the log service program reads the log information from the filled queue to generate a log file, and writes the log information in the next log write queue. After the log information stored in a log read queue is all read by the log service program, the queue can be switched to the log write queue, and the log service program is made to read the log information from the next log read queue.

[0077] In some embodiments, the first queue and the second queue are lock-free queues.

[0078] It can be understood that by setting the first queue and the second queue as lock-free queues, different applications can write log information in the queues in the shared memory respectively. Traditional queues usually implement thread-safe operations by locking (mutual exclusion locks), but locking may cause competition and performance bottlenecks in high concurrency situations. Lock-free queues usually use atomic instructions such as CAS (Compare and Swap) to provide high-performance concurrent operations while ensuring thread safety.

[0079] In the embodiment of the present application, the present application can store log information of different applications in the same queue by setting the first queue and the second queue as lock-free queues. And the log reading and log writing are distinguished by the two queues to avoid mutual influence between log reading and log writing. Thus, the processing efficiency of log information can be improved.

[0080] S202: When the first queue and the second queue meet a switching condition, switch the read and write characteristics of the first queue and the second queue.

[0081] In some embodiments, the switching condition includes at least one of the following: the remaining storage space of the first queue is less than a preset threshold, and the duration of the switch between the read and write characteristics of the first queue and the second queue reaches a preset duration.

[0082] It should be noted that the remaining storage space of the first queue being less than the preset threshold can be understood as: the remaining storage space of the first queue can no longer store the next log information to be written, that is, the storage space occupied by the next log information is greater than the remaining storage space of the first queue.

[0083] Optionally, when the first queue and the second queue meet the switching condition, a switching trigger event can be sent to switch the read and write characteristics of the first queue and the second queue, and notify the log service program to read the log information in the log reading queue. When the first queue and the second queue do not meet the switching condition, the log service program is in a blocked listening state, which keeps a very low CPU overhead.

[0084] Optionally, when it is determined that the remaining storage space of the first queue (i.e., the queue with the read-write characteristic of log writing) is less than a preset threshold (passively triggered switching), it is considered that the first queue has been full and no new log information can be written. At this time, the read-write characteristics of the first queue and the second queue can be switched, that is, the log write queue (i.e., the first queue) is switched to the log read queue (i.e., the first queue after switching), and the log read queue (i.e., the second queue) is switched to the log write queue (i.e., the second queue after switching).

[0085] It is understandable that after the read-write characteristics of the first queue and the second queue were switched last time, when the log information to be written is written into the queue whose read-write characteristics are log writes, the log service program will simultaneously read the log information from the queue whose read-write characteristics are log reads. And usually the speed at which the log service program reads the log information is faster than the speed at which the log information is written, therefore, before the queue whose read-write characteristics are log writes is filled, the log information in the queue whose read-write characteristics are log reads has all been read and becomes an empty queue, therefore, the read-write characteristics of the first queue and the second queue can be switched directly when the queue whose read-write characteristics are log writes is filled.

[0086] Optionally, when the read-write characteristics of the first queue and the second queue are switched, the timer can be used to synchronously time the switch to determine the duration of the switch, so that when the duration of the switch of the read-write characteristics of the first queue and the second queue reaches a preset duration (actively trigger the switch), even if the first queue is not full, the read-write characteristics of the first queue and the second queue can be switched. This is to solve the problem that when the amount of log information is small, the log information stored in the queue can be read in time to generate a log file for storage on the disk.

[0087] In the embodiment of the present application, the present application can switch the read-write characteristics of the first queue and the second queue when the remaining storage space of the first queue is less than a preset threshold, or when the duration of the switch between the read-write characteristics of the first queue and the second queue reaches a preset duration. In this way, the read-write characteristics of the two queues can be switched in time without affecting the reading or writing process of the log information, thereby improving the processing efficiency of the log information.

[0088] In some embodiments, in a log processing method provided by an embodiment of the present application, the above step S202 may specifically include: when the first queue and the second queue meet the switching conditions and each log information stored in the second queue is read, switching the read and write characteristics of the first queue and the second queue.

[0089] Optionally, when the first queue and the second queue meet the switching condition, it can be further determined whether the log information stored in the second queue is all read by the log service program, and after the log information stored in the second queue is all read by the log service program, the read-write characteristics of the first queue and the second queue are switched. If the log information stored in the second queue is not all read by the log service program, the read-write characteristics of the first queue and the second queue can be switched with a delay.

[0090] In the embodiment of the present application, when the first queue and the second queue meet the switching condition, the present application can further consider whether each log information stored in the second queue is read, so as to ensure that each log information stored in the second queue is read, and then switch the read and write characteristics of the first queue and the second queue. Thus, the log information stored in the second queue will not be omitted, and the missing log information is avoided, resulting in incomplete logs.

[0091] In some embodiments, in a log processing method provided by an embodiment of the present application, the method may also include: discarding the log information to be written when any log information stored in the second queue has not been read and the remaining storage space of the first queue is less than the storage space required for the log information to be written.

[0092] Optionally, when the read-write characteristics of the first queue and the second queue are not switched, if the first queue is full, but the log information stored in the second queue is not all read by the log service program, then the read-write characteristics of the first queue and the second queue can be delayed. And because the first queue is full, new log information cannot be written, the log information to be written can be discarded at this time, or the log information to be written can be delayed.

[0093] In the embodiment of the present application, when the log information stored in the second queue has not been fully read, if the remaining storage space of the first queue cannot write the new log information to be written, the log information to be written can be discarded. This ensures the normal operation of the application and avoids abnormal conditions in the system caused by the inability to write logs.

[0094] S203: Read the log information stored in the switched first queue to generate a log file, and write the newly generated log information into the switched second queue.

[0095] Optionally, generating a log file may be understood as storing the read log information in a corresponding log file in a disk (persistent storage area), or generating a log file based on the read log information and storing it in a disk.

[0096] It is understandable that after switching the read-write characteristics of the first queue and the second queue, the log service program can read the stored log information from the first queue after switching (i.e., the queue whose read-write characteristic is log reading). And, since the second queue after switching (i.e., the queue whose read-write characteristic is switched from log reading to log writing) is empty, the newly generated log information can continue to be written in the second queue after switching.

[0097] It should be noted that the reason why the second queue after the switch is empty is that before the switch, all the log information in the queue has been read by the log service program.

[0098] In the embodiment of the present application, the present application can write the log information to be written into the first queue whose read-write characteristic is log writing in the shared memory, and switch the read-write characteristics of the first queue and the second queue in the shared memory when the first queue and the second queue meet the switching condition. Thereby after the read-write characteristics of the first queue and the second queue are switched, the log information stored in the first queue after the switch can be read to generate a log file, and the newly generated log information is written in the second queue after the switch. In this way, since the shared memory includes the first queue and the second queue with different read-write characteristics, therefore, there will be a queue for log writing and a queue for log reading in the two queues at the same time. Based on this, the log information to be written can be written into the queue whose read-write characteristic is log writing at any time, and the log information stored in the queue whose read-write characteristic is log reading can be read in time to generate a log file. Therefore, writing log information and reading log information do not affect each other, and the efficiency of log information writing and reading can be improved by two queues, thereby reducing the delay of log writing.

[0099] In some embodiments, the log information to be written is log information generated by multiple applications; Figure 3 As shown, in a log processing method provided by an embodiment of the present application, the "reading log information stored in the first queue after switching to generate a log file" in the above step S203 can specifically include S301-S302.

[0100] S301. Traverse the log information stored in the switched first queue to determine a corresponding relationship between each piece of log information and each application program in a plurality of application programs, so as to determine at least one piece of log information of each application program in the plurality of application programs.

[0101] Optionally, the log service program may first traverse the log information stored in the first queue after switching, determine the process name of each log information, and determine the correspondence between each log information and each application in the multiple applications, thereby determining which log information in the queue is the log information of each application.

[0102] Specifically, determining the correspondence between each log information and each application in the multiple applications may specifically include: determining the correspondence between each log information and the corresponding log file name, and the log file name corresponds to the application, so that the correspondence between the log information and the application can be determined. The log information of multiple applications may be written into one log file, which is actually determined according to the log file name information carried in the log information when the log information is written.

[0103] In some embodiments, the first queue after switching includes multiple slots, each slot is used to store a log information; in a log processing method provided in an embodiment of the present application, the above step S501 may specifically include: traversing the log information stored in each slot in the first queue after switching, generating a slot-application correspondence table, the slot-application correspondence table including the slot identifier of at least one slot corresponding to each application among multiple applications, and the log information of each application is stored in at least one slot corresponding to each application.

[0104] Optionally, the log service program can also determine the index position (ie slot identifier) ​​of each log message in the queue when traversing the log messages stored in the first queue after switching, thereby generating a corresponding relationship table between the slots and the application programs (eg, a hash table).

[0105] In an embodiment of the present application, the present application can traverse the log information stored in each slot in the first queue after switching to generate a slot-application correspondence table. In this way, when reading the log information stored in the first queue after switching, all log information of the application can be read from the corresponding slot according to the slot identifier of at least one slot corresponding to each application stored in the slot-application correspondence table. Without having to analyze the application to which each log information belongs when reading the log information, the reading speed of the log information can be improved, and the processing efficiency of the log information can be improved.

[0106] S302 . For each application program among the multiple application programs, read at least one log information of each application program from the switched first queue in turn, and generate a log file for each application program.

[0107] Optionally, according to different applications, all log information of the same application stored in the first queue after switching can be read each time to generate a log file of the application. In this way, multiple log information can be read from the first queue after switching at one time, and all log information of the same application can be stored in the disk at the same time without accessing the disk multiple times.

[0108] In some embodiments, in a log processing method provided by an embodiment of the present application, the above-mentioned step S502 may specifically include: for each application among multiple applications, based on a slot-to-application correspondence table, read the log information stored in at least one slot corresponding to each application in a queue with a read-write characteristic of log reading in turn, and generate a log file for each application.

[0109] Optionally, for each application, the slot-application correspondence table can be traversed to determine the slot identifier of at least one slot corresponding to each application, and based on the slot identifier of at least one slot corresponding to each application, the log information stored in at least one slot corresponding to each application can be read from a queue with a read-write characteristic of log reading.

[0110] In addition, a corresponding log file can be created in the persistent storage area according to the process name of the log information, and the log file can be mapped to the memory space of the log service program, and the log information corresponding to the index position of the process name stored in the slot and application correspondence table in the log reading queue can be copied to the mapped memory. Then it is synchronized to the log file in the persistent storage area, which can reduce the number of copies when the log information is written to the disk and the frequent file access operations, further reducing the CPU overhead.

[0111] In the embodiment of the present application, when reading the log information stored in the first queue after switching, the present application can read the log information stored in the corresponding slot from the slot corresponding to the application in sequence according to different applications according to the slot identifier of at least one slot corresponding to each application stored in the slot-application correspondence table. When reading the log information, it is not necessary to analyze the application to which each log information belongs, which can improve the reading speed of the log information and the processing efficiency of the log information.

[0112] In an embodiment of the present application, the present application can traverse the log information stored in the first queue after switching to determine the application to which each log information belongs, thereby determining at least one log information corresponding to each application. In this way, when reading log information from the first queue after switching to generate a log file, all log information of the same application stored in the first queue after switching can be read simultaneously each time according to different applications to generate a log file for each application. In this way, multiple readings of the first queue after switching can be avoided, thereby improving the efficiency of reading log information and improving the efficiency of generating log files.

[0113] For example, Figure 4As shown, the embodiment of the present application provides a schematic diagram of the overall architecture of log processing, and the architecture includes: an application, a shared memory, and a log service program. The application can be a plurality of applications, mainly generating log information, and writing the generated log information into the log write queue in the shared memory. The shared memory is used as a buffer for storing log information, and is used to temporarily store the log information generated by each application. The log service program mainly reads the log information stored in the log read queue in the shared memory, and drops it to a persistent storage area (such as a disk, hard disk, etc.) after processing. The main function of the log service program is to monitor the triggering read log event (i.e., read the log information in the log read queue), read the log information from the log read queue of the shared memory, process it, and drop it to the log file in the persistent storage area.

[0114] Specifically, the business thread of the application can call the log interface provided by the log interface library, and fill the log information that is expected to be saved when the program runs abnormally into the log interface. In the log interface, the log content, timestamp, process information, thread information, code location of the output log, etc. will be written to the log write queue in the shared memory. At this time, the formatting of the log information will not be completed, thereby avoiding the introduction of a large delay. When the log write queue is full, the read and write characteristics of the log write queue and the log read queue will be switched, and the log write queue full event will be triggered to notify the log service program to read the log information stored in the log read queue.

[0115] Exemplary, combined Figure 4 As shown, when the log service program reads the log information from the log reading queue, the log service program starts to traverse the entire log reading queue, obtains the process information (process name) carried in the log information, and saves the index position and process name of the log information output by the same process in the log reading queue in a hash table (i.e., a slot and application corresponding relationship table). Then traverse the hash table again, create a corresponding log file in the persistent storage area according to the process name in the hash table, and map the created log file to the memory space of the log service program by mmap. According to the index position of the log information corresponding to the process name in the hash table, read the log information in the log queue in turn and complete the formatting of the log information, and then copy it to the memory mapped by the log file. Then synchronize the log information in the memory space of the log service program to the log file in the persistent storage area through msync, and finally release the mapping of the log file to the memory space of the log service program through munmap, and then continue to process the log information corresponding to the subsequent process name of the hash table.

[0116] It should be noted that the size of a single log file stored in the persistent storage area is usually limited to tens of megabytes by the log slice rollback function, and mapping it to the memory space of the log service program does not consume much memory.

[0117] Further, such as Figure 5 As shown, the present application embodiment provides a kind of structural diagram of shared memory, including the diagram before the read-write characteristic is switched and the diagram after the read-write characteristic is switched. When the shared memory is an application program recording log information, it is a bridge for communication with the log service program. The log information generated by the application program is cached in the shared memory, waiting for the reading of the log service program. The shared memory includes two lock-free queues, namely the log write queue and the log read queue, which can switch with the log read queue when the log write queue is full. Shared memory is a kind of multi-producer single consumer model similar to multiple applications, and multiple applications write log information to the log write queue of the shared memory, and the log service program reads log information from the log read queue of the shared memory. But there is no situation that the same queue in the shared memory is written by multiple applications and reads log information by the log service program at the same time.

[0118] For example, Figure 6 As shown, after the application generates log information, the application can call the log interface provided by the log interface library, and obtain the slot of the log write queue in the shared memory, so as to copy the log content, timestamp, process information, thread information and the code position of the output log to the obtained slot. Then determine whether the log write queue is full. When the log write queue is full, switch the read-write characteristics of the log write queue and the log read queue, and trigger the full event to notify the log service program. When the log service program monitors the full event or the timer times out, switch the read-write characteristics of the log write queue and the log read queue, and traverse the log information in the log read queue to obtain the process name. Further, the index position of the process name and the log information generated by the process in the log read queue is stored in a hash table, so as to generate a log file according to the process name by traversing the hash table, and then map the log file to the memory space. In this way, the log information in the index position corresponding to the process name in the log read queue is formatted and copied to the mapped memory. Then the log information of the mapped memory is synchronized to the log file in the persistent storage area to complete the log disk storage.

[0119] The embodiment of the present application has the characteristics of high performance. When the chip computing power is limited, more CPU can be saved for business programs. It also has the characteristics of low latency and low packet loss rate, which is of great significance for scenarios where application software in intelligent driving systems has high real-time requirements, while also ensuring the reliability of log records. By designing two lock-free queues in shared memory, only a small amount of shared memory is consumed, and the logs generated when the application exits abnormally can also be saved in disk files in a timely manner.

[0120] The above mainly introduces the solution provided by the embodiment of the present application from the perspective of the method. In order to achieve the above functions, the log processing device or electronic device includes a hardware structure and / or software module corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0121] The embodiment of the present application can exemplarily divide the functional modules of the log processing device or electronic device according to the above method. For example, the log processing device or electronic device can include various functional modules corresponding to the various functional divisions, or two or more functions can be integrated into one processing module. The above integrated modules can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical functional division. There may be other division methods in actual implementation.

[0122] Figure 7 FIG. 1 is a block diagram of a log processing device according to an exemplary embodiment. Figure 7 The log processing device 700 includes: a processing module 701.

[0123] The processing module 701 is used to write the log information to be written into the first queue in the shared memory. The shared memory includes the first queue and the second queue. The read-write characteristics of the first queue and the second queue are respectively any one of log writing and log reading. The read-write characteristics of the first queue and the second queue are different. The queue with the read-write characteristic of log writing is used to store the log information to be written, and the queue with the read-write characteristic of log reading is used to read the written log information to generate a log file. The processing module 701 is also used to switch the read-write characteristics of the first queue and the second queue when the first queue and the second queue meet the switching conditions. The processing module 701 is also used to read the log information stored in the switched first queue to generate a log file, and write the newly generated log information in the switched second queue.

[0124] In a possible implementation, the switching condition includes at least one of the following: the remaining storage space of the first queue is less than a preset threshold, and the duration of the switch between the read and write characteristics of the first queue and the second queue reaches a preset duration.

[0125] In a possible implementation, the processing module 701 is specifically configured to switch the read / write characteristics of the first queue and the second queue when the first queue and the second queue meet the switching condition and each log information stored in the second queue is read.

[0126] In a possible implementation, the processing module 701 is further configured to discard the log information to be written if any log information stored in the second queue has not been read and the remaining storage space of the first queue is smaller than the storage space required by the log information to be written.

[0127] In a possible implementation, the log information to be written is log information generated by multiple applications; the processing module 701 is specifically used to traverse the log information stored in the first queue after switching, determine the correspondence between each log information and each application in the multiple applications, so as to determine at least one log information of each application in the multiple applications; the processing module 701 is specifically used to read at least one log information of each application from the first queue after switching in turn for each application in the multiple applications, and generate a log file for each application.

[0128] In a possible implementation, the first queue after switching includes multiple slots, each slot is used to store a log information; the processing module 701 is specifically used to traverse the log information stored in each slot in the first queue after switching, and generate a slot-application correspondence table, the slot-application correspondence table includes the slot identifier of at least one slot corresponding to each application among multiple applications, and the log information of each application is stored in at least one slot corresponding to each application.

[0129] In one possible implementation, the processing module 701 is specifically used to, for each application among multiple applications, read the log information stored in at least one slot corresponding to each application in turn from a queue with a read-write characteristic of log reading based on a slot-to-application correspondence table, and generate a log file for each application.

[0130] In a possible implementation, the first queue and the second queue are lock-free queues.

[0131] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0132] Figure 8 FIG. 1 is a block diagram of an electronic device according to an exemplary embodiment. Figure 8 As shown, the electronic device 800 includes but is not limited to: a processor 801 and a memory 802 .

[0133] The memory 802 is used to store executable instructions of the processor 801. It can be understood that the processor 801 is configured to execute instructions to implement the log processing method in the above embodiment.

[0134] It should be noted that those skilled in the art can understand that Figure 8 The electronic device structure shown in the figure does not constitute a limitation on the electronic device, and the electronic device may include Figure 8 More or fewer components may be shown, or certain components may be combined, or the components may be arranged differently.

[0135] The processor 801 is the control center of the electronic device. It uses various interfaces and lines to connect various parts of the entire electronic device. By running or executing software programs and / or modules stored in the memory 802, and calling data stored in the memory 802, it performs various functions of the electronic device and processes data, thereby monitoring the electronic device as a whole. The processor 801 may include one or more processing units. Optionally, the processor 801 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 801.

[0136] The memory 802 can be used to store software programs and various data. The memory 802 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application program required by at least one functional module (such as a processing module, a storage module, etc.), etc. In addition, the memory 802 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0137] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory 802 including instructions. The above instructions can be executed by a processor 801 of an electronic device 800 to implement the log processing method in the above embodiment.

[0138] In actual implementation, Figure 7 The functions of the processing module 701 in Figure 8 The processor 801 in the memory 802 calls the computer program stored in the memory 802. The specific execution process can refer to the description of the log processing method in the above embodiment, which will not be repeated here.

[0139] Optionally, the computer-readable storage medium may be a non-temporary computer-readable storage medium, for example, the non-temporary computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

[0140] In an exemplary embodiment, the embodiment of the present application further provides a computer program product including one or more instructions, and the one or more instructions can be executed by the processor 801 of the electronic device 800 to complete the log processing method in the above embodiment.

[0141] It should be noted that when the instructions in the above-mentioned computer-readable storage medium or one or more instructions in the computer program product are executed by the processor of the electronic device, the various processes of the above-mentioned log processing method embodiment are implemented, and the same technical effect as the above-mentioned log processing method can be achieved. To avoid repetition, they will not be repeated here.

[0142] Fig. 9 A schematic diagram of the structure of a computer system of an electronic device is shown. It should be noted that: Fig. 9 The computer system of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0143] like Fig. 9 As shown, the computer system includes a central processing unit (CPU), which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) or the program loaded from the storage part to the random access memory (RAM), such as executing the method in the above embodiment. In the RAM, various programs and data required for system operation are also stored. The CPU, ROM and RAM are connected to each other through a bus. The input / output (I / O) interface is also connected to the bus. The I / O interface is used to implement functions such as data input, output, communication, and storage, and the storage function can be specifically implemented by removable media.

[0144] The following components are connected to the I / O interface: an input part including a keyboard, a mouse, etc.; an output part including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker; a storage part including a hard disk, etc.; and a communication part including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication part performs communication processing via a network such as the Internet. A drive is also connected to the I / O interface as needed. Removable media, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., are installed on the drive as needed so that a computer program read therefrom is installed into the storage part as needed.

[0145] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication part, and / or installed from a removable medium. When the computer program is executed by a central processing unit (CPU), various functions defined in the system of the present application are executed.

[0146] It should be noted that the computer-readable medium shown in the embodiment of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable computer program is carried. This propagated data signal can take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. A computer program contained on a computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.

[0147] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0148] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, 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 interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0149] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0150] 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. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0151] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or the full classification part or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including a number of instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to execute the full classification part or part of the steps of the methods of each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard drives, ROM, RAM, disks, or optical disks.

[0152] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto, and any changes or substitutions within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A log processing method, characterized in that: The method comprises: Writing the log information to be written into a first queue in a shared memory, the shared memory comprising the first queue and the second queue, the read / write characteristics of the first queue and the second queue being any one of log writing and log reading, the read / write characteristics of the first queue and the second queue being different, the queue with the read / write characteristic being the log writing is used to store the log information to be written, and the queue with the read / write characteristic being the log reading is used to read the written log information to generate a log file; When the first queue and the second queue meet a switching condition, switching the read and write characteristics of the first queue and the second queue; The log information stored in the switched first queue is read to generate a log file, and the newly generated log information is written into the switched second queue.

2. The method according to claim 1, characterized in that: The switching condition includes at least one of the following: the remaining storage space of the first queue is less than a preset threshold, and the duration of the switching of the read-write characteristics of the first queue and the second queue reaches a preset duration.

3. The method according to claim 1, characterized in that When the first queue and the second queue meet a switching condition, switching the read and write characteristics of the first queue and the second queue includes: When the first queue and the second queue meet a switching condition and each piece of log information stored in the second queue is read, the read-write characteristics of the first queue and the second queue are switched.

4. The method according to claim 3, characterized in that The method further comprises: If any piece of log information stored in the second queue has not been read and the remaining storage space of the first queue is smaller than the storage space required for the log information to be written, the log information to be written is discarded.

5. The method according to claim 1, characterized in that The log information to be written is log information generated by multiple applications; The reading the log information stored in the first queue after switching to generate a log file includes: Traversing the log information stored in the first queue after the switch, determining a corresponding relationship between each piece of log information and each application program in the multiple application programs, so as to determine at least one piece of log information for each application program in the multiple application programs; For each application program among the multiple application programs, at least one log information of each application program is read in sequence from the switched first queue to generate a log file of each application program.

6. The method according to claim 5, characterized in that The first queue after the switching includes a plurality of slots, each slot being used to store a piece of log information; The traversing the log information stored in the first queue after the switching, determining the correspondence between each piece of log information and each of the multiple applications, so as to determine at least one piece of log information of each of the multiple applications, includes: Traverse the log information stored in each slot in the first queue after the switch, and generate a slot-to-application correspondence table, wherein the slot-to-application correspondence table includes a slot identifier of at least one slot corresponding to each application among the multiple applications, and the log information of each application is stored in at least one slot corresponding to each application.

7. The method according to claim 6, characterized in that The step of sequentially reading at least one log information of each application program from the switched first queue for each application program among the plurality of application programs to generate a log file for each application program includes: For each of the multiple applications, based on the slot-application correspondence table, log information stored in at least one slot corresponding to each application is read in turn from the queue with the read-write characteristic for the log reading, and a log file for each application is generated.

8. The method according to any one of claims 1 to 7, characterized in that The first queue and the second queue are lock-free queues.

9. A log processing device, characterized in that: The log processing device comprises: a processing module; The processing module is used to write the log information to be written into a first queue in a shared memory, the shared memory includes the first queue and the second queue, the read-write characteristics of the first queue and the second queue are respectively any one of log writing and log reading, the read-write characteristics of the first queue and the second queue are different, the queue with the read-write characteristic of the log writing is used to store the log information to be written, and the queue with the read-write characteristic of the log reading is used to read the written log information to generate a log file; The processing module is further configured to switch the read and write characteristics of the first queue and the second queue when the first queue and the second queue meet a switching condition; The processing module is further used to read the log information stored in the switched first queue to generate a log file, and write the newly generated log information into the switched second queue.

10. An electronic device, characterized in that: include: A processor and a memory; wherein the memory is used to store one or more programs, and the one or more programs include computer-executable instructions. When the electronic device is running, the processor executes the computer-executable instructions stored in the memory, and the electronic device executes the method described in any one of claims 1-8.

11. A computer-readable storage medium, characterized in that: When the computer instructions stored in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device executes the method as claimed in any one of claims 1 to 8.

12. A computer program product, characterized in that The computer program product comprises computer instructions, and when the computer instructions are executed on an electronic device, the electronic device executes the method according to any one of claims 1 to 8.

13. A vehicle, characterized in that: The vehicle comprises the log processing device according to claim 9, and the vehicle is used to implement the method according to any one of claims 1-8.