Log acquisition method and device and electronic equipment
By using single-threaded log crawling threads in the vehicle computer system to obtain log data and optimize storage, the problem of high resource consumption during log acquisition is solved, and the system performance and log management efficiency is improved.
Patent Information
- Application Number
- CN202411146941.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-20
- Publication Date
- 2024-12-13
AI Technical Summary
The log acquisition process in the existing vehicle and computer systems consumes a lot of processing resources, affecting system performance.
A single-threaded log grab thread is used to obtain all log data in the vehicle system, and write it to the corresponding location according to log parameters, including determining the log buffer type and performing data compression to optimize storage.
It reduces the consumption of processing resources for log acquisition, ensures the order and integrity of log data, and improves the overall performance of the vehicle and computer system and the efficiency of log management.
Smart Images

Figure CN119127642A_ABST
Abstract
Description
[Technical field]
[0001] The present invention relates to the field of data processing, and in particular to a method, device, electronic device and computer-readable storage medium for obtaining logs. [Background technology]
[0002] With the development of automobile electronics and intelligence, the car system has become an indispensable part of modern cars. The car system integrates multiple functions such as navigation, entertainment, and communication. Its stability and user experience directly affect driving safety and comfort. In order to ensure the stable operation of the car system and timely discover and solve problems in the system, the acquisition and management of log data has become particularly important.
[0003] The log acquisition of existing vehicle-mounted systems mainly relies on the built-in operating system or application log system to obtain log data through a thread pool. However, multi-threaded log capture increases the CPU load, consumes valuable processing resources, and affects the overall performance of the vehicle-mounted system.
[0004] Therefore, how to reduce the consumption of processing resources for log acquisition in the vehicle system is a technical problem that needs to be solved in this field. [Summary of the invention]
[0005] In order to effectively solve the problem of high resource consumption in the log acquisition process in the prior art, the present invention provides a log acquisition method.
[0006] A method for obtaining logs, comprising:
[0007] Create a log capture thread, where the log capture thread is a single thread;
[0008] Call the log capture thread to capture all log data in the vehicle system;
[0009] The log parameters of each log data are obtained, and the log data is written into a corresponding position according to the log parameters.
[0010] Optionally, calling the log capture thread to capture all log data in the vehicle system includes:
[0011] Execute the all command to view all first log buffers;
[0012] The log capture thread is called to capture all log data in the first log buffer, and store the log data in the second log buffer.
[0013] Optionally, obtaining log parameters of each log data and writing the log data into a corresponding position according to the log parameters includes:
[0014] Determine the type of a first log buffer where each log data is located, where the types of the first log buffer include a main log buffer, a system event buffer, a wireless message buffer, and a system log buffer;
[0015] Each piece of log data is written from the second log buffer to a folder corresponding to the type of the first log buffer in the disk.
[0016] Optionally, the step of writing each piece of log data from the second log buffer into a folder corresponding to the type of the first log buffer in the disk includes:
[0017] Detecting the size of log data in the second log buffer;
[0018] When the size of the log data exceeds a first threshold, each log data is written from the second log buffer into the folder.
[0019] Optionally, the step of writing each piece of log data from the second log buffer into a folder corresponding to the type of the first log buffer in the disk includes:
[0020] Each piece of log data is written from the second log buffer into the folder at every preset time period.
[0021] Optionally, after obtaining log parameters of each log data and writing the log data into a corresponding position according to the log parameters, the method further includes:
[0022] Get the size of the log data at the current position;
[0023] When the size of the log data exceeds a second threshold, the log data is compressed.
[0024] Optionally, before creating the log capture thread, the method further includes:
[0025] Get the hardware attribute parameters of the vehicle system;
[0026] The parsing method, storage format and storage path of the log data are determined according to the hardware attribute parameters.
[0027] A log acquisition device, comprising:
[0028] Create a log capture thread, where the log capture thread is a single thread;
[0029] Call the log capture thread to capture all log data in the vehicle system;
[0030] The log parameters of each log data are obtained, and the log data is written into a corresponding position according to the log parameters.
[0031] An electronic device, comprising:
[0032] A processor and a memory, wherein the memory is used to store at least one instruction, and when the instruction is loaded and executed by the processor, the method for obtaining logs as described in any one of the above is implemented.
[0033] A computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements any of the log acquisition methods described above.
[0034] The log acquisition method provided by the embodiment of the present invention has at least the following beneficial effects:
[0035] The present invention creates a single-threaded log capture thread, then calls the log capture thread to capture all log data in the vehicle system, and finally obtains the log parameters of each log data, and writes the log data to the corresponding position according to the log parameters. The log acquisition method of the present invention realizes the capture of all log data in the vehicle system by creating a single-threaded log capture thread, avoiding resource competition and potential log data conflict problems in a multi-threaded environment. The single-threaded operation mechanism ensures the order and integrity of the log data, while reducing the consumption of processing resources for log acquisition in the vehicle system, and improving the overall performance of the vehicle system. At the same time, by analyzing the parameters of each log data and writing the log to a predetermined location according to these parameters, the accuracy and efficiency of log management are enhanced, making the storage and subsequent analysis of the log more orderly and convenient, and providing strong data support for the stable operation and fault diagnosis of the vehicle system.
Brief Description of the Drawings
[0036] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0037] Figure 1 A flow chart of a log acquisition method provided by an embodiment of the present invention;
[0038] Figure 2 A flowchart of another log acquisition method provided by an embodiment of the present invention;
[0039] Figure 3 A schematic diagram of the structure of a log acquisition device provided by an embodiment of the present invention. [Specific implementation method]
[0040] In order to better understand the technical solution of the present invention, the embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0041] It should be clear that the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0042] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "an", "the" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.
[0043] It should be understood that the term "and / or" used in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0044] The log acquisition of existing vehicle-mounted systems mainly relies on the built-in operating system or application log system to obtain log data through a thread pool. However, multi-threaded log capture increases the CPU load, consumes valuable processing resources, and affects the overall performance of the vehicle-mounted system.
[0045] Therefore, the present invention provides a log acquisition method to solve the above problem.
[0046] Please refer to Figure 1 , is a flow chart of a log acquisition method provided by an embodiment of the present invention, comprising the following steps:
[0047] Step S01, create a log capture thread, the log capture thread is a single thread.
[0048] Since the computing resources of the vehicle computer system are limited, multi-threaded log capture increases the CPU load. The CPU processing resources occupied by the log service reach about 50%, which greatly affects the overall performance of the vehicle computer system.
[0049] In this embodiment, a single-threaded log capture thread is created to capture all log data generated in the vehicle system. Since the log data output of the vehicle system is low, the efficiency of using a single-threaded log capture thread to capture logs is basically the same as that of a multi-threaded log capture thread.
[0050] Moreover, the single-threaded approach to log capture solves the log data competition and synchronization problems that may occur in a multi-threaded environment, ensuring the consistency and integrity of log data. The single-threaded model simplifies the complexity of log management, avoids data loss or damage that may occur during concurrent writing, and also reduces resource consumption caused by thread switching and synchronization mechanisms, thereby improving the overall performance and stability of the system.
[0051] In some embodiments, a single-threaded log capture thread is created, which can be specifically achieved by initializing a special log management class in the software architecture of the vehicle system, which is responsible for starting a log capture task, which runs as a single thread. This thread will be given the responsibility of monitoring and accessing all log sources in the vehicle system, and collecting various log information sequentially according to the established polling interval or event trigger mechanism. The collected log information will be formatted and stored in the specified cache area or directly written to the persistent storage according to the preset rules and log parameters, such as timestamp, log level, message content, etc. In the whole process, due to the single-threaded operation, data competition and consistency problems that may occur during concurrent access by multiple threads can be effectively avoided, while also reducing the overhead of thread management, and adapting to the limited resources and high requirements for stability of the vehicle system.
[0052] In some embodiments, there are many types of hardware platforms for vehicle systems, including a variety of processor architectures, memory specifications, storage solutions, and network communication capabilities. These hardware differences lead to special requirements for the log system, including optimization of log data processing, storage, and analysis. If a fixed configuration method is used on a variety of hardware platforms, it will lead to inefficient log acquisition, waste of storage space, and even failure to meet specific performance requirements in some cases. In addition, the readability and maintainability of the log will also be affected by platform differences, increasing the complexity of cross-platform development and maintenance.
[0053] Therefore, in order to improve the adaptability of the log acquisition method to different hardware platforms, before executing step S01 to create a log capture thread, the following steps may also be performed:
[0054] Step S11, obtaining the hardware attribute parameters of the vehicle system.
[0055] Step S12, determining the parsing method, storage format and storage path of the log data according to the hardware attribute parameters.
[0056] In some embodiments, determining the parsing method, storage format, and storage path of log data according to hardware attribute parameters may specifically include the following steps:
[0057] 1) Obtaining hardware attribute parameters:
[0058] Query the CPU model, frequency, and number of cores of the vehicle system to evaluate the processing power.
[0059] Detect memory size and type (e.g., DDR3, DDR4) to determine cache and temporary storage requirements.
[0060] Identify storage device types (e.g., SSD, HDD, eMMC) and capacities to assess storage needs and performance.
[0061] 2) Determine the parsing method:
[0062] Choose a suitable log parsing algorithm based on the number of CPU cores and frequency to match the system's processing power. For example, use a more complex parsing method on a high-performance processor and a simpler method on a low-performance processor.
[0063] Based on the memory capacity, determine the memory size that can be allocated to the log parsing task to avoid memory overflow.
[0064] 3) Storage format selection:
[0065] Choose a suitable storage format based on the performance of the storage medium and the access pattern of the log data. For example, for SSDs, you can choose a more efficient storage format, while for HDDs, you may need to consider a format that reduces disk seek time.
[0066] 4) Storage path determination:
[0067] Determine the best storage path based on the read and write speed of the storage device and the importance of the log data. For example, store critical logs on faster storage media and store less important logs on lower-cost media.
[0068] Through the above steps, it can be ensured that the creation and configuration of the log capture thread fully considers the hardware characteristics of the vehicle system, thereby achieving efficient log management while optimizing system performance and resource utilization.
[0069] Step S02, calling the log capture thread to capture all log data in the vehicle system.
[0070] In this embodiment, the log capture thread is called to capture all log data in the vehicle system, so as to realize continuous monitoring and capture of all log information generated in the vehicle system. This process involves reading various log files or streams generated during system operation, including log data from the operating system, application program or hardware driver. The purpose of this embodiment is to realize centralized management and analysis of log data, so as to monitor system status, track user behavior, diagnose faults and optimize performance. By using a dedicated thread to handle log capture, the real-time and integrity of log data can be ensured, while avoiding interference with the main business process and improving the overall stability and reliability of the system.
[0071] In some embodiments, calling a log capture thread to capture all log data in the vehicle system may specifically include: first, initializing and starting a dedicated log capture thread, which will be configured to run continuously in the background of the vehicle system. This thread will use the API provided by the vehicle operating system or directly interact with the system log daemon to monitor and access the log stream generated by the system. Next, the thread will filter and capture key log entries, including error reports, system warnings, user operation records, and performance indicators, according to the preset log level and filtering rules. Subsequently, these log data will be formatted and written to the cache area in the memory or directly persisted to the storage device in accordance with the established storage strategy, such as timestamp, log level, and message type. During the whole process, the log capture thread can also handle the rolling, compression, and encryption of the log to optimize storage efficiency and ensure data security. In addition, in order to ensure the integrity and accuracy of the log data, error detection, exception handling, and consistency verification of the log data can also be performed during the execution of the thread. In this way, the vehicle system can fully monitor and record its operating status, providing important data support for system maintenance, troubleshooting, and performance optimization.
[0072] Step S03, obtaining log parameters of each log data, and writing the log data into a corresponding position according to the log parameters.
[0073] In this embodiment, the log parameters may include the level and type of log data, such as bottom-level logs, middle-level logs, upper-level logs, and side-branch performance monitoring logs. The vehicle system can improve the retrievability and manageability of log data by identifying different levels and types of log data and storing them in appropriate locations, ensuring that relevant information can be quickly located and accessed during system monitoring, troubleshooting, and performance analysis, thereby optimizing the system maintenance process and improving user experience.
[0074] In some embodiments, since the storage space of the vehicle computer system is limited, in order to effectively manage the storage space and prevent the unlimited growth of log data from causing the exhaustion of storage resources, after executing step S03 to obtain the log parameters of each log data and writing the log data to the corresponding position according to the log parameters, the following steps may also be performed:
[0075] Get the size of the log data at the current position;
[0076] When the size of the log data exceeds a second threshold, the log data is compressed.
[0077] In some embodiments, the second threshold may be set to 600M.
[0078] This embodiment determines the amount of log data by setting a second threshold. When it is detected that the volume of log data has grown beyond the preset second threshold, that is, when it reaches a critical point that may affect system performance and storage efficiency, the system will automatically trigger a compression operation to optimize storage space, reduce the physical storage space occupied by log data, and avoid consuming precious storage resources due to excessive expansion of log files. At the same time, the compressed log data is faster to read and process, reducing the delay of I / O operations and improving the overall response speed of the system.
[0079] Based on the above technical solution, the present invention creates a single-threaded log capture thread, then calls the log capture thread to capture all log data in the vehicle system, and finally obtains the log parameters of each log data, and writes the log data to the corresponding position according to the log parameters. The log acquisition method of the present invention realizes the capture of all log data in the vehicle system by creating a single-threaded log capture thread, avoiding resource competition and potential log data conflict problems in a multi-threaded environment. The single-threaded operation mechanism ensures the order and integrity of the log data, while reducing the consumption of processing resources for log acquisition in the vehicle system, and improving the overall performance of the vehicle system. At the same time, by analyzing the parameters of each log data and writing the log to a predetermined location according to these parameters, the accuracy and efficiency of log management are enhanced, making the storage and subsequent analysis of the log more orderly and convenient, and providing strong data support for the stable operation and fault diagnosis of the vehicle system.
[0080] On the basis of the above embodiments, in some embodiments, in order to achieve comprehensive collection of log data and ensure the integrity of information, the calling log capture thread mentioned in step S02 captures all log data in the vehicle system, which can be specifically achieved by executing the all command.
[0081] Please refer to Figure 2 , which is a flow chart of another log acquisition method provided by an embodiment of the present invention, comprises the following steps:
[0082] Step S01, creating a log capture thread, wherein the log capture thread is a single thread.
[0083] Step S021, execute the all command to view all first log buffers.
[0084] In this embodiment, the all command is executed to view all first log buffers. The system can be accessed through the command line interface or terminal of the vehicle system, and the all command is entered in the command line interface. The system will respond and list the contents of all first log buffers.
[0085] Step S022: calling the log capture thread to capture all log data in the first log buffer and storing the log data in the second log buffer.
[0086] In the present embodiment, the application generates logs during operation, and these logs are collected and stored in the first buffer. Wherein the first buffer is a plurality of circular buffers (a data structure is used to represent a fixed size, head-to-tail connected buffer, suitable for caching data streams) reserved by the Android log recording system for log messages. To realize the comprehensive collection of log data and ensure the integrity of information, the present embodiment checks all the first log buffers by executing the all command, and calls the log capture thread to capture the log data in all the first log buffers, and stores it in the second log buffer. The safe transfer of log data between different buffers is realized, and reliable data support is provided for subsequent log analysis, problem diagnosis and performance monitoring. In this way, the loss of log data can be effectively avoided, and the integrity and traceability of log information are ensured, thereby improving the stability and reliability of the vehicle system operation.
[0087] Step S031, determining the type of the first log buffer where each piece of log data is located.
[0088] In this embodiment, the types of the first log buffer include a main log buffer, a system event buffer, a wireless message buffer, and a system log buffer, wherein:
[0089] Main log buffer: used to store the main operation and event logs of the vehicle system. These logs record key information of system operation, such as startup, shutdown, errors and warnings.
[0090] System event buffer: Dedicated to recording system-level events, such as system updates, configuration changes, or other important system-level activities.
[0091] Wireless message buffer: used to store logs related to wireless communication, such as the use of Bluetooth, Wi-Fi, or other wireless technologies, including information such as connection, disconnection, and transmission errors.
[0092] System log buffer: used to store more detailed system operation logs, which may include the status of system services, performance indicators, and the execution of background tasks.
[0093] The settings of these buffers help to monitor and analyze the operating status of the vehicle system by category, so that the system administrator or automatic monitoring system can quickly locate the problem according to the type of log, and improve the efficiency of troubleshooting and system maintenance. By managing and analyzing the logs in different buffers, we can better understand the operating status of the system, optimize system performance, and ensure the stability and security of the system.
[0094] Step S032, writing each log data from the second log buffer into a folder corresponding to the type of the first log buffer in the disk.
[0095] In this embodiment, by storing in categories, the log data is made more orderly, easy to manage and retrieve, and the accessibility and readability of the data can be improved. Moreover, the log data stored in categories is convenient for rapid analysis using log analysis tools, helping to quickly locate problems. At the same time, transferring the log data from the memory buffer to the disk can release memory resources, optimize system performance, and provide flexibility for future log data backup, migration or archiving.
[0096] In some embodiments, in order to release memory resources in time, prevent data overflow, ensure persistent data storage and system stability, and improve the efficiency and accuracy of log management through automated processing, it is also possible to decide whether to write to a folder based on the size of the log data. That is, as mentioned in step S032, each log data is written from the second log buffer to a folder corresponding to the type of the first log buffer in the disk, which can be specifically:
[0097] Detecting the size of log data in the second log buffer;
[0098] When the size of the log data exceeds the first threshold, each log data is written from the second log buffer into the folder.
[0099] In some embodiments, in order to balance system performance and data integrity, avoid frequent I / O operations caused by immediate writing of log data, reduce the occupation of system resources, ensure orderly storage and easy management of log data, improve data accessibility and system reliability, log data can also be written to the folder every preset time period. That is, as mentioned in step S032, each log data is written from the second log buffer to the folder corresponding to the type of the first log buffer in the disk, which can be specifically:
[0100] Each piece of log data is written from the second log buffer into the folder at every preset time period.
[0101] Based on the above technical solution, this embodiment ensures the comprehensive collection of log data, avoids resource competition and data confusion caused by multi-threading, improves system stability and log processing efficiency, and at the same time provides convenience for centralized management and further data analysis, and enhances the system monitoring and fault diagnosis capabilities.
[0102] Please refer to Figure 3 , is a schematic diagram of the structure of a log acquisition device provided by an embodiment of the present invention, the log acquisition device comprising:
[0103] The thread creation module 100 is used to create a log capture thread, and the log capture thread is a single thread;
[0104] The calling module 200 is used to call the log capture thread to capture all log data in the vehicle system;
[0105] The first acquisition module 300 is used to acquire log parameters of each log data and write the log data into a corresponding position according to the log parameters.
[0106] Based on the above embodiment, in a specific embodiment, the calling module 200 can be specifically used for:
[0107] Execute the all command to view all first log buffers;
[0108] The log capture thread is called to capture all log data in the first log buffer and store the log data in the second log buffer.
[0109] Based on the above embodiment, in a specific embodiment, the first acquisition module 300 can be specifically used for:
[0110] Determine the type of the first log buffer where each log data is located, the types of the first log buffer include a main log buffer, a system event buffer, a wireless message buffer, and a system log buffer;
[0111] Each log data is written from the second log buffer to a folder corresponding to the type of the first log buffer in the disk.
[0112] Based on the above embodiment, in a specific embodiment, the first acquisition module 300 can be specifically used for:
[0113] Detecting the size of log data in the second log buffer;
[0114] When the size of the log data exceeds the first threshold, each log data is written from the second log buffer into the folder.
[0115] Based on the above embodiment, in a specific embodiment, the log acquisition device may further include:
[0116] The second acquisition module is used to obtain the size of the log data at the current position;
[0117] The log compression module is used to compress the log data when the size of the log data exceeds a second threshold.
[0118] Based on the above embodiment, in a specific embodiment, the log acquisition device may further include:
[0119] The third acquisition module is used to obtain the hardware attribute parameters of the vehicle system;
[0120] The determination module is used to determine the parsing method, storage format and storage path of the log data according to the hardware attribute parameters.
[0121] This embodiment provides an electronic device, including a processor and a memory, the memory is used to store at least one instruction, and when the instruction is loaded and executed by the processor, the above-mentioned log acquisition method is implemented. Its execution method and beneficial effects are similar and will not be repeated here.
[0122] An embodiment of the present invention provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned log acquisition method is implemented. The execution method and beneficial effects thereof are similar and will not be described in detail here.
[0123] It should be noted that although the above describes the various steps in a specific order, it does not mean that the various steps must be executed in the above specific order. In fact, some of these steps can be executed concurrently or even in a different order as long as the required functions can be achieved.
[0124] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for obtaining logs, characterized in that: include: Create a log capture thread, where the log capture thread is a single thread; Call the log capture thread to capture all log data in the vehicle system; The log parameters of each log data are obtained, and the log data is written into a corresponding position according to the log parameters.
2. The method according to claim 1, characterized in that The calling of the log capture thread to capture all log data in the vehicle system includes: Execute the all command to view all first log buffers; The log capture thread is called to capture all log data in the first log buffer, and store the log data in the second log buffer.
3. The method according to claim 2, characterized in that The obtaining of log parameters of each log data and writing the log data into a corresponding position according to the log parameters includes: Determine the type of a first log buffer where each log data is located, where the types of the first log buffer include a main log buffer, a system event buffer, a wireless message buffer, and a system log buffer; Each piece of log data is written from the second log buffer to a folder corresponding to the type of the first log buffer in the disk.
4. The method according to claim 3, characterized in that The step of writing each piece of log data from the second log buffer into a folder corresponding to the type of the first log buffer in the disk comprises: Detecting the size of log data in the second log buffer; When the size of the log data exceeds a first threshold, each log data is written from the second log buffer into the folder.
5. The method according to claim 3, characterized in that: The step of writing each piece of log data from the second log buffer into a folder corresponding to the type of the first log buffer in the disk comprises: Each piece of log data is written from the second log buffer into the folder at every preset time period.
6. The method according to claim 1, characterized in that After obtaining the log parameters of each log data and writing the log data into the corresponding position according to the log parameters, the method further includes: Get the size of the log data at the current position; When the size of the log data exceeds a second threshold, the log data is compressed.
7. The method according to any one of claims 1 to 6, characterized in that: Before creating the log capture thread, the method further includes: Get the hardware attribute parameters of the vehicle system; The parsing method, storage format and storage path of the log data are determined according to the hardware attribute parameters.
8. A device for obtaining logs, characterized in that: include: A thread creation module, used to create a log capture thread, wherein the log capture thread is a single thread; A calling module, used to call the log capture thread to capture all log data in the vehicle system; The first acquisition module is used to acquire the log parameters of each log data and write the log data into a corresponding position according to the log parameters.
9. An electronic device, characterized in that: include: A processor and a memory, wherein the memory is used to store at least one instruction, and when the instruction is loaded and executed by the processor, the method for obtaining logs according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for obtaining logs as described in any one of claims 1 to 7 is implemented.
