Method and apparatus for generating log files
By compressing the target module name in the log file, the time when the parameter value is received, and the parameter value data, the problem of excessive memory occupancy and long opening of the log file is solved, and efficient storage and fast return visits of the log file are achieved.
Patent Information
- Application Number
- CN202111569455.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-21
- Publication Date
- 2025-06-17
- Estimated Expiration
- 2041-12-21
AI Technical Summary
Log files take up too much memory, so it takes a long time to open the return file, and the number of log files stored is limited.
By receiving multiple parameter values output by the target module, obtaining the name of the target module and the time when multiple parameter values are received, and compressing these data, generating compressed log data, and finally generating a log file based on the compressed log data.
Reduce the size of log data and generate log files that take up less storage space, thereby increasing the speed of log file opening and return visits and enhancing the storage of log files.
Smart Images

Figure CN114443590B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of intelligent vehicles, and in particular, to a method and device for generating a log file. Background Art
[0002] With the development of the Internet, log files are increasingly used to record necessary and valuable information such as servers and applications, providing an important basis for the maintenance of relevant programs or electronic devices and the query of working status. By continuously collecting log data to generate corresponding log files, it is convenient to view the working status of the modules corresponding to the log data. Therefore, the collection and storage of continuously generated log files have become an important part that cannot be ignored. However, unprocessed log files occupy too much memory, take a long time to open and review again, and at the same time limit the number of log files stored. Summary of the Invention
[0003] This application aims to at least partly solve the problems in the related art that log files occupy too much memory, take a long time to open and review again, and at the same time limit the number of log files stored.
[0004] To this end, the first object of this application is to propose a method for generating a log file.
[0005] The second object of this application is to propose a device for generating a log file.
[0006] The third object of this application is to propose a vehicle.
[0007] The fourth object of this application is to propose an electronic device.
[0008] The fifth object of this application is to propose a computer-readable storage medium.
[0009] To achieve the above object, an embodiment of the first aspect of this application proposes a method for generating a log file, including: receiving a plurality of parameter values output by a target module, obtaining the name of the target module and the time when the plurality of parameter values are received; compressing at least one of the name of the target module, the time when the plurality of parameter values are received, and the plurality of parameter values to generate compressed log data; generating a log file according to the compressed log data.
[0010] The technical solution provided by the embodiment of this application compresses any one or more of the three types of data: the name of the target module, the time when a plurality of parameter values are received, and the plurality of parameter values, reduces the size of the log data, generates a log file that occupies less storage space, thereby improving the speed of opening and reviewing the log file, and enhancing the storage capacity of the log file.
[0011] According to an embodiment of the present application, the compressed log data includes a file header, and the file header includes compressed name data. Compressing the name of the target module to generate the compressed log data includes: compressing the name of the target module to generate the compressed name data.
[0012] According to an embodiment of the present application, the compressed name data includes an identifier of the target module. Compressing the name of the target module to generate the compressed name data includes: compressing the name of the target module according to the identifier of the target module to generate the compressed name data, and the length of the identifier of the target module is less than the length of the name of the target module.
[0013] According to an embodiment of the present application, the compressed log data includes a file header, and the file header includes compressed time data. Compressing the time when the multiple parameter values are received to generate the compressed log data includes: compressing the time when the multiple parameter values are received to generate the compressed time data.
[0014] According to an embodiment of the present application, the compressed time data includes a start time and a time interval at which the multiple parameter values are generated. Compressing the time when the multiple parameter values are received to generate the compressed time data includes: determining the start time and the time interval according to the time when the multiple parameter values are received.
[0015] According to an embodiment of the present application, the compressed log data includes compressed parameter data. Compressing the multiple parameter values to generate the compressed log data includes: compressing the multiple parameter values to generate the compressed parameter data.
[0016] According to an embodiment of the present application, compressing the multiple parameter values to generate the compressed parameter data includes: compressing the multiple parameter values according to the order in which the parameter values appear to generate the compressed parameter data.
[0017] According to an embodiment of the present application, the number of the compressed parameter data is the same as the number of different parameter values among the multiple parameter values. The compressed parameter data includes the parameter value and an order index value at which the parameter value appears. The parameter values in different compressed parameter data are different. Compressing the multiple parameter values according to the order in which the parameter values appear to generate the compressed parameter data includes: determining the order index value according to the order in which the parameter values appear.
[0018] According to an embodiment of the present application, the compressed log data includes a file header and compressed parameter data. Generating a log file based on the compressed log data includes: calculating the number of bits occupied by the order index value of the parameter value occurrence in the compressed parameter data; sequentially storing the file header, the parameter value in the compressed parameter data, the number of bits occupied by the order index value of the parameter value occurrence, and the order index value of the parameter value occurrence in the log file.
[0019] To achieve the above object, an embodiment of the second aspect of the present application provides a log file generation device, including: a receiving module, configured to receive multiple parameter values output by a target module; an obtaining module, configured to obtain the name of the target module and the time when the multiple parameter values are received; a compression module, configured to compress at least one of the name of the target module, the time when the multiple parameter values are received, and the multiple parameter values to generate compressed log data; and a generation module, configured to generate a log file based on the compressed log data.
[0020] According to an embodiment of the present application, the compressed log data includes a file header, and the file header includes compressed name data. The compression module is specifically configured to: compress the name of the target module to generate the compressed name data.
[0021] According to an embodiment of the present application, the compressed name data includes an identifier of the target module. The compression module is further configured to: compress the name of the target module according to the identifier of the target module to generate the compressed name data, and the length of the identifier of the target module is less than the length of the name of the target module.
[0022] According to an embodiment of the present application, the compressed log data includes a file header, and the file header includes compressed time data. The compression module is specifically configured to: compress the time when the multiple parameter values are received to generate the compressed time data.
[0023] According to an embodiment of the present application, the compressed time data includes a start time and a time interval at which the multiple parameter values are generated. The compression module is further configured to: determine the start time and the time interval according to the time when the multiple parameter values are received.
[0024] According to an embodiment of the present application, the compressed log data includes compressed parameter data. The compression module is specifically configured to: compress the multiple parameter values to generate the compressed parameter data.
[0025] According to an embodiment of the present application, the compression module is further configured to: compress the multiple parameter values according to the order in which the parameter values appear, so as to generate the compressed parameter data.
[0026] According to an embodiment of the present application, the number of the compressed parameter data is the same as the number of different parameter values among the multiple parameter values. The compressed parameter data includes the parameter values and the order index values of the appearance of the parameter values. The parameter values in different compressed parameter data are different. The compression module is further configured to: determine the order index value according to the order in which the parameter values appear.
[0027] According to an embodiment of the present application, the compressed log data includes a file header and the compressed parameter data. The generation module is specifically configured to: calculate the number of bits occupied by the order index value of the appearance of the parameter values in the compressed parameter data; sequentially store the file header, the parameter values in the compressed parameter data, the number of bits occupied by the order index value of the appearance of the parameter values, and the order index value of the appearance of the parameter values in the log file.
[0028] To achieve the above object, an embodiment of the third aspect of the present application provides a vehicle, including: a log file generation device as described in the embodiment of the second aspect of the present application.
[0029] To achieve the above object, an embodiment of the fourth aspect of the present application provides an electronic device, including: a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the method for generating a log file as described in the embodiment of the first aspect of the present application is implemented.
[0030] To achieve the above object, an embodiment of the fifth aspect of the present application provides a computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, the method for generating a log file as described in the embodiment of the first aspect of the present application is implemented. Description of the Drawings
[0031] Figure 1 is a flowchart of a method for generating a log file shown according to an exemplary embodiment of the present application;
[0032] Figure 2 is a flowchart of a method for generating a log file shown according to another exemplary embodiment of the present application;
[0033] Figure 3 is a schematic diagram of the storage structure of the compressed parameter data in a method for generating a log file shown according to an exemplary embodiment of the present application;
[0034] Figure 4 is a block diagram of a log file generation device shown according to an exemplary embodiment of the present application;
[0035] Figure 5 is a schematic structural diagram of a vehicle according to an exemplary embodiment of the present application;
[0036] Figure 6 is a schematic structural diagram of an electronic device according to an exemplary embodiment of the present application. Detailed implementation manners
[0037] The embodiments of the present application will be described in detail below. The examples of the embodiments are shown in the accompanying drawings, where the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to explain the present application and should not be construed as limiting the present application.
[0038] Figure 1 is a flowchart of a log file generation method shown according to an exemplary embodiment of the present application. As Figure 1 shown, the log file generation method includes the following steps:
[0039] S101, receiving a plurality of parameter values output by a target module.
[0040] The log file generation method of the embodiments of the present application can be applied to an in-vehicle system to generate log files of relevant modules. The execution subject of the log file generation method of the embodiments of the present application can be the log file generation device of the embodiments of the present application, and the log file generation device can be set on a vehicle.
[0041] The log data generated when the intelligent vehicle system is working is huge, including multiple modules in the vehicle, such as a clock module, an image processing module, and a sensor module, etc., which generate corresponding log data when working, and log data of multiple load threads of a Graphics Processing Unit (GPU) or a Central Processing Unit (CPU).
[0042] In specific implementation, the module or thread for which the log file is to be generated can be used as the target module, and multiple parameter values output by the target module are received. Each received parameter value can be regarded as a piece of log data to be processed. In the related art, in order for technicians to clearly obtain information corresponding to a certain parameter value when viewing the log, it is usually necessary to add information such as the timestamp corresponding to the parameter value and the module corresponding to the parameter value to each log. For example, the traditional log format: log generation time - target module name - parameter value, such as: 2021-10-15 19:32:44Line1 1698. Among them, the parameter value can be the CPU occupancy rate at a certain moment or the number of bits received or sent by a load thread, etc.
[0043] S102, obtain the name of the target module and the time when multiple parameter values are received.
[0044] It is not difficult to understand that technicians need to analyze the log data by combining the name of the module corresponding to the parameter value and the timestamp corresponding to the parameter value in the log data, so as to diagnose the working state of the module at a specific time. Since the time when the target module outputs the parameter value and the time when the parameter value is received are almost equal, generally the time when the parameter value is received is used as the timestamp corresponding to the parameter value for generating the log file.
[0045] In the embodiment of the present application, the name of the target module corresponding to multiple parameter values and the time when each parameter value is received are obtained. For example, the name of the target module can be obtained by sending a request to the target module, and the time when the parameter value is received can be obtained from the system clock. As a feasible implementation manner, when multiple parameter values are received from the target module, the name of the target module can be obtained only once, so as to reduce the occupation of communication resources.
[0046] S103, compress at least one of the name of the target module, the time when multiple parameter values are received, and the multiple parameter values to generate compressed log data.
[0047] In the embodiment of the present application, in order to reduce the storage space occupied by the log data, the log data is compressed to generate compressed log data to reduce the size of the log data. Among them, at least one of the name of the target module, the time when multiple parameter values are received, and the multiple parameter values can be compressed.
[0048] S104, generate a log file according to the compressed log data.
[0049] In the embodiment of the present application, a log file is generated according to the compressed log data generated in step S103, so that technicians can obtain information such as parameter values, the name of the target module corresponding to the parameter values, and the timestamp corresponding to the parameter values according to the log file.
[0050] In the embodiments of the present application, multiple parameter values output by a target module are received, the name of the target module and the time when the multiple parameter values are received are obtained, and at least one of the name of the target module, the time when the multiple parameter values are received, and the multiple parameter values is compressed to generate compressed log data, and a log file is generated according to the compressed log data. In the embodiments of the present application, by compressing at least one of the name of the target module, the time when the multiple parameter values are received, and the multiple parameter values in the log data, the size of the log data is reduced to generate a log file that occupies less storage space, thereby improving the speed of opening and revisiting the log file and enhancing the storage capacity of the log file.
[0051] Based on the above embodiments, at least one of the three types of data, namely the name of the target module, the time when the multiple parameter values are received, and the multiple parameter values, can be compressed to reduce the memory space occupied by the log data. It is not difficult to understand that the embodiments of the present application can generate compressed log data in multiple formats. For example, only the name of the target module and the multiple parameter values are compressed, and the time when the multiple parameter values are received is not compressed, or only the name of the target module and the time when the multiple parameter values are received are compressed, and the multiple parameter values are not compressed, or the name of the target module, the time when the multiple parameter values are received, and the multiple parameter values are compressed in multiple ways. The compression methods for the name of the target module, the time when the multiple parameter values are received, and the multiple parameter values are described below respectively:
[0052] As a feasible implementation manner, the name of the target module is compressed to generate compressed name data, and the compressed name data is stored in the file header part, and on this basis, compressed log data is generated.
[0053] In some embodiments, the name of the target module corresponding to the multiple parameter values obtained is stored in the file header. For the multiple parameter values corresponding to the same target module, the name of the target module only needs to be stored once in the file header. Compared with the traditional log format in which the name of the target module is recorded once in each log, this method can be considered as compressing the name of the target module in multiple logs, reducing the storage space occupied by the name of the target module, and reducing the size of the log data.
[0054] Furthermore, when compressing the name of the target module, an identifier for the target module can also be set according to the name of the target module, and the identifier is used to replace the name of the target module. The length of the identifier of the target module is less than the length of the name of the target module. For example, the load thread Line1 can be identified by the identifier "0", further reducing the storage space occupied by the name of the target module.
[0055] In addition, when storing the log data corresponding to multiple target modules in a log file, the names of the target modules can be stored in the file header, and the logs corresponding to the target modules are identified by the identifiers corresponding to the target modules in the file content part, so as to better distinguish the logs corresponding to different modules, and at the same time reduce the size of the log file, enabling the log file to be quickly opened during return visits to view the logs of different modules.
[0056] As another feasible implementation, the time when multiple parameter values are received can be compressed to generate compressed time data, and the compressed time data is stored in the file header, and on this basis, compressed log data is generated.
[0057] In some embodiments, when compressing the time when multiple parameter values are received, the start time of the multiple parameter values is extracted from the time when the multiple parameter values are received. This start time can be understood as the time when the first parameter value in the multiple parameter values is received. The end time of the multiple parameter values can also be extracted from the time when the multiple parameter values are received, that is, the time when the last parameter value in the multiple parameter values is received.
[0058] In addition, the time interval for generating multiple parameter values can also be determined by obtaining the interval for the target module to generate log data (parameter values). For example, the time interval for generating the above multiple parameters is determined according to the refresh rate of the system or the interval for generating log data preset by the target module.
[0059] According to the start time and the time interval when multiple parameter values are received, the time when each parameter value is received, that is, the time stamp corresponding to each parameter value, can be obtained. Compared with recording the time when the parameter value is received once in each log in the traditional log format, this method can be considered as compressing the time when the parameter value is received in multiple logs (that is, compressing the time when multiple parameter values are received), reducing the storage space occupied by the time when multiple parameter values are received, and reducing the size of the log data. At the same time, compared with generating compressed time data according to the end time and the time interval, it is more convenient to obtain the start time, and only the time when the first parameter value of the target module is received needs to be recorded, without having to determine whether a certain parameter value is the last parameter value.
[0060] Taking the load thread Line1 that records the CPU frequency at the current moment as an example, the time when the first parameter value output by Line1 is received is 2021 / 8 / 27 12:00:00, and the time interval for Line1 to generate log data (parameter values) is 1 second. Then, 2021 / 8 / 27 12:00:00 is taken as the start time for generating multiple parameter values corresponding to the load thread Line1, 1 second is taken as the time interval, and the start time and time interval are stored in the file header. Thus, the generation time of the second parameter value in the log file can be obtained based on the start time and time interval in the file header: 2021 / 8 / 27 12:00:01; the generation time of the third parameter value: 2021 / 8 / 27 12:00:02, etc.
[0061] Thus, in the embodiments of the present application, the file header may include, but is not limited to, compressed name data, the start time and time interval for generating multiple parameter values, so as to extract the data that needs to appear repeatedly and regularly in the log data to reduce the size of the log data.
[0062] As another feasible implementation manner, multiple parameter values are compressed to generate compressed parameter data, and on this basis, compressed log data is generated.
[0063] In some embodiments, multiple parameter values are compressed according to the order of the multiple parameter values, where the order in which the parameter values appear can be interpreted as the order in which the parameter values are output by the target module.
[0064] Still taking the load thread Line1 that records the CPU frequency at the current moment as an example, as shown in Table 1, the first parameter value received from the output of Line1 is 100, then the order in which the parameter value appears is 0, indicating that 100 appears for the 0th time, that is: the first log records that the CPU frequency obtained for the 0th time is 100 megahertz (Mhz); the second parameter value received from the output of Line1 is 150, then the order in which the parameter value appears is 1, indicating that 150 appears for the 1st time, that is: the second log records that the CPU frequency obtained for the 1st time is 150 Mhz; the third parameter value received from the output of Line1 is 100, then the order in which the parameter value appears is 2, indicating that 100 appears for the 2nd time, that is: the third log records that the CPU frequency obtained for the 2nd time is 100 Mhz.
[0065] Table 1 Corresponding relationship table between parameter values, their orders, and the content they represent
[0066] Parameter values and their order Represented content 100:0 The frequency of the CPU obtained for the 0th time is 100Mhz 150:1 The frequency of the CPU obtained for the 1st time is 150Mhz 100:2 The frequency of the CPU obtained for the 2nd time is 100Mhz 300:3 The frequency of the CPU obtained for the 3rd time is 300Mhz 100:4 The frequency of the CPU obtained for the 4th time is 100Mhz 150:5 The frequency of the CPU obtained for the 5th time is 150Mhz 100:6 The frequency of the CPU obtained for the 6th time is 100Mhz
[0067] For example, when compressing multiple parameter values according to the order in which they appear, the CPU frequency of 150Mhz obtained for the first time and the CPU frequency of 150Mhz obtained for the fifth time can be represented as 150:15. In this way, the value 150 only needs to be stored once in the log file, avoiding storing the repeatedly occurring parameter values multiple times. Compared with the method of implementing parameter data compression by encoding the parameter values, this method can save more storage resources.
[0068] Thus, by combining and representing the same parameter values among multiple parameter values, compressed parameter data is generated, and the remaining parameter values after the combination process are different parameter values. In addition, the time when the parameter value is received can be calculated according to the order in which the parameter value appears. The time of receiving the parameter value = initial time + order in which the parameter value appears * time interval.
[0069] In order to further compress the log data and reduce the size of the log file in the embodiments of the present application, the embodiments of the present application introduce an order index value to replace the order in which the parameter value appears, where the order index value is less than or equal to the order, so as to reduce the storage space occupied by the order.
[0070] In some embodiments, to compress the size of the log data by using the order index value to replace the order in which the parameter value appears, only the parameter value and multiple order index values corresponding to the parameter value need to be recorded, where the order index value can be determined according to the order in which the parameter value appears. For example, as shown in Table 2, the order index value can be set as the difference between the order and the sum of the order index values, where the sum of the order index values is the sum of the order index values corresponding to the same parameter value that has appeared before.
[0071] Table 2 Corresponding relationship table before and after parameter data compression
[0072] Parameter data format before compression Parameter data format after compression 100:0 100:0 2 2 2 150:1 150:1 4 100:2 300:3 300:3 100:4 150:5 100:6
[0073] Thus, the number of compressed parameter data is the same as the number of different parameter values among the multiple parameter values, and the parameter values in different compressed parameter data are different.
[0074] Based on the above embodiments, the compressed log data may include: a file header storing the compressed name data and compressed time data, and the compressed parameter data. As Figure 2 shown, step S103 "generating a log file according to the compressed log data" may specifically include the following steps:
[0075] S201, calculating the number of bits occupied by the order index value of the parameter value in the compressed parameter data.
[0076] In an embodiment of the present application, when storing the compressed parameter data, calculate the number of bits occupied by the order index value of the parameter value in the compressed parameter data, and allocate storage space for the order index value of the parameter value according to the number of bits.
[0077] S202. Store the file header, the parameter values in the compressed parameter data, the number of bits occupied by the order index value of the parameter value, and the order index value of the parameter value in the log file in sequence.
[0078] In an embodiment of the present application, the file header, the parameter values in the compressed parameter data, the number of bits occupied by the order index value of the parameter value, and the order index value of the parameter value generated in the above embodiment are stored in sequence. Compared with directly storing the compressed log data, this method can save unnecessary storage space and improve the utilization rate of storage resources.
[0079] As a feasible implementation, as Figure 3 shown, the number of bits occupied by the order index value of the parameter value can be stored in the first 6 bits, and the real data of the order index value is stored thereafter. An int - type data can occupy at most 4 bytes, that is, 32 bits. The binary representation of 32 is 100000. Therefore, 6 bits can meet the storage requirements for the number of bits occupied by the order index value of the parameter value. Allocate the corresponding storage space according to the number of bits occupied by the order index value, which reduces the memory occupation to a certain extent and reduces the waste of storage space.
[0080] For example, when storing the order index value 1, use 6 bits to store the number of bits 1 occupied by the order index value 1, and then use 1 bit to store the order index value 1. A total of 6 bits + 1 bit = 7 bits of storage space are required.
[0081] For example, when storing the order index value 256, use 6 bits to store the number of bits 9 occupied by the order index value 256, and then use 9 bits to store the order index value 256. A total of 6 bits + 9 bits = 15 bits of storage space are required.
[0082] Thus, by calculating the number of bits occupied by the order index value of the parameter value and allocating storage space for the order index value of the parameter value according to the number of bits, the storage space required for the log file is reduced, the waste of storage space is reduced, and the storage capacity of the log file is enhanced.
[0083] Figure 4 is a block diagram of a log - file generation device shown according to an exemplary embodiment of the present application. As Figure 4 shown, the log - file generation device 300 includes: a receiving module 301, an obtaining module 302, a compression module 303, and a generating module 304.
[0084] A receiving module 301, configured to receive a plurality of parameter values output by a target module.
[0085] An obtaining module 302, configured to obtain the name of the target module and the time when the plurality of parameter values are received.
[0086] A compression module 303, configured to compress at least one of the name of the target module, the time when the plurality of parameter values are received, and the plurality of parameter values to generate compressed log data.
[0087] A generating module 304, configured to generate a log file according to the compressed log data.
[0088] In an embodiment of the present application, the compressed log data includes a file header, and the file header includes compressed name data. The compression module 303 is specifically configured to: compress the name of the target module to generate compressed name data.
[0089] In an embodiment of the present application, the compressed name data includes an identifier of the target module. The compression module 303 is further configured to: compress the name of the target module according to the identifier of the target module to generate compressed name data, and the length of the identifier of the target module is less than the length of the name of the target module.
[0090] In an embodiment of the present application, the compressed log data includes a file header, and the file header includes compressed time data. The compression module 303 is specifically configured to: compress the time when the plurality of parameter values are received to generate compressed time data.
[0091] In an embodiment of the present application, the compressed time data includes a start time and a time interval at which the plurality of parameter values are generated. The compression module 303 is further configured to: determine the start time and the time interval according to the time when the plurality of parameter values are received.
[0092] In an embodiment of the present application, the compressed log data includes compressed parameter data. The compression module 303 is specifically configured to: compress the plurality of parameter values to generate compressed parameter data.
[0093] In an embodiment of the present application, the compression module 303 is further configured to: compress the plurality of parameter values according to the order in which the parameter values appear to generate compressed parameter data.
[0094] In an embodiment of the present application, the number of the compressed parameter data is the same as the number of different parameter values among the plurality of parameter values. The compressed parameter data includes a parameter value and an order index value at which the parameter value appears. The parameter values in different compressed parameter data are different. The compression module 303 is further configured to: determine the order index value according to the order in which the parameter values appear.
[0095] In the embodiment of the present application, the compressed log data includes a file header and compressed parameter data. The generating module 304 is specifically configured to: calculate the number of bits occupied by the order index value of the parameter value in the compressed parameter data; sequentially store the file header, the parameter value in the compressed parameter data, the number of bits occupied by the order index value of the parameter value, and the order index value of the parameter value in the log file.
[0096] It should be noted that the above explanation of the embodiment of the log file generation method also applies to the log file generation device in the embodiment of the present application, and the specific process will not be elaborated here.
[0097] In the embodiment of the present application, a plurality of parameter values output by a target module are received, the name of the target module and the time when the plurality of parameter values are received are obtained, and at least one of the name of the target module, the time when the plurality of parameter values are received, and the plurality of parameter values is compressed to generate compressed log data, and a log file is generated according to the compressed log data. In the embodiment of the present application, by compressing at least one of the name of the target module, the time when the plurality of parameter values are received, and the plurality of parameter values in the log data, the size of the log data is reduced to generate a log file that occupies less storage space, thereby improving the speed of opening and revisiting the log file and enhancing the storage capacity of the log file.
[0098] To implement the above embodiment, the embodiment of the present application also proposes a vehicle 400, as Figure 5 shown. The vehicle 400 may specifically include: a log file generation device 300 as shown in the above embodiment.
[0099] To implement the above embodiment, the embodiment of the present application also proposes an electronic device 500, as Figure 6 shown. The electronic device 500 may specifically include: a memory 501, a processor 502, and a computer program stored on the memory 501 and executable on the processor 502. When the processor 502 executes the program, the log file generation method as shown in the above embodiment is implemented.
[0100] To implement the above embodiment, the embodiment of the present application also proposes a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the log file generation method as shown in the above embodiment is implemented.
[0101] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, features defined with "first" and "second" may explicitly or implicitly include one or more of such features. In the description of the present application, "a plurality" means two or more unless otherwise specifically defined.
[0102] In the description of this specification, the description with reference to terms such as "an embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, without contradiction, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0103] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and should not be construed as limiting the present application. Those of ordinary skill in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of the present application.
Claims
1. A method for generating a log file, characterized in that, It includes: Receiving a plurality of parameter values output by a target module; Obtaining the name of the target module and the time when the plurality of parameter values are received; Compressing at least one of the name of the target module, the time when the plurality of parameter values are received, and the plurality of parameter values to generate compressed log data; Generating a log file according to the compressed log data; Among them, compressing the plurality of parameter values to generate the compressed log data includes: Compressing the plurality of parameter values according to the order in which the parameter values appear to generate compressed parameter data; Determining an order index value according to the order in which the parameter values appear; using the order index value to replace the order in which the parameter values appear in the compressed parameter data, and the order index value is set to the difference between the sum of the order and the order index value, and the sum of the order index values is the sum of the order index values corresponding to the same parameter value that appeared before; the compressed parameter data includes the parameter value and the order index value of the appearance of the parameter value, the compressed log data includes the compressed parameter data, and the number of the compressed parameter data is the same as the number of different parameter values in the plurality of parameter values, and the parameter values in different compressed parameter data are different.
2. The method for generating a log file according to claim 1, characterized in that, The compressed log data includes a file header, and the file header includes compressed name data. Compressing the name of the target module to generate the compressed log data includes: Compressing the name of the target module to generate the compressed name data.
3. The method for generating a log file according to claim 2, characterized in that, The compressed name data includes an identifier of the target module. Compressing the name of the target module to generate the compressed name data includes: Compressing the name of the target module according to the identifier of the target module to generate the compressed name data, and the length of the identifier of the target module is less than the length of the name of the target module.
4. The method for generating a log file according to claim 1, characterized in that, The compressed log data includes a file header, and the file header includes compressed time data. Compressing the time when the plurality of parameter values are received to generate the compressed log data includes: Compressing the time when the plurality of parameter values are received to generate the compressed time data.
5. The method for generating a log file according to claim 4, characterized in that, The compressed time data includes a start time and a time interval when the plurality of parameter values are generated. Compressing the time when the plurality of parameter values are received to generate the compressed time data includes: Determining the start time and the time interval according to the time when the plurality of parameter values are received.
6. The method for generating a log file according to claim 1, characterized in that, The compressed log data includes a file header and compressed parameter data. Generating a log file according to the compressed log data includes: Calculating the number of bits occupied by the order index value of the appearance of the parameter value in the compressed parameter data; Sequentially storing the file header, the parameter value in the compressed parameter data, the number of bits occupied by the order index value of the appearance of the parameter value, and the order index value of the appearance of the parameter value in the log file.
7. A device for generating a log file, characterized in that, It includes: A receiving module, configured to receive a plurality of parameter values output by a target module; An obtaining module, configured to obtain the name of the target module and the time when the plurality of parameter values are received; A compressing module, configured to compress at least one of the name of the target module, the time when the plurality of parameter values are received, and the plurality of parameter values to generate compressed log data; A generating module, configured to generate a log file according to the compressed log data; Wherein, the compressing module is specifically configured to: Compress the plurality of parameter values according to the order in which the parameter values appear to generate compressed parameter data; Determine an order index value according to the order in which the parameter values appear; use the order index value to replace the order in which the parameter values appear in the compressed parameter data, and the order index value is set to the difference between the sum of the order and the order index value, and the sum of the order index values is the sum of the order index values corresponding to the same parameter value that has appeared before; the compressed parameter data includes parameter values and the order index values at which the parameter values appear, the compressed log data includes the compressed parameter data, and the number of the compressed parameter data is the same as the number of different parameter values in the plurality of parameter values, and the parameter values in different compressed parameter data are different.
8. The device for generating a log file according to claim 7, characterized in that, The compressed log data includes a file header, and the file header includes compressed name data. The compressing module is specifically configured to: Compress the name of the target module to generate the compressed name data.
9. The device for generating a log file according to claim 8, characterized in that,The compressed name data includes an identifier of the target module. The compressing module is further configured to: Compress the name of the target module according to the identifier of the target module to generate the compressed name data, and the length of the identifier of the target module is less than the length of the name of the target module.
10. The generating device of the log file according to claim 7, wherein, The compressed log data includes a file header, and the file header includes compressed time data. The compressing module is specifically configured to: Compress the time when the plurality of parameter values are received to generate the compressed time data.
11. The generating device of the log file according to claim 10, wherein, The compressed time data includes a start time and a time interval at which the plurality of parameter values are generated. The compressing module is further configured to: Determine the start time and the time interval according to the time when the plurality of parameter values are received.
12. The generating device of the log file according to claim 7, wherein, The compressed log data includes a file header and compressed parameter data. The generating module is specifically configured to: Calculate the number of bits occupied by the order index value at which the parameter value appears in the compressed parameter data; Successively store the file header, the parameter values in the compressed parameter data, the number of bits occupied by the order index value at which the parameter value appears, and the order index value at which the parameter value appears in the log file.
13. A vehicle, wherein, Comprising: The log file generating device according to any one of claims 7-12.
14. An electronic device, wherein, Comprising: A memory, a processor, and a computer program stored on the memory and executable on the processor, wherein when the processor executes the program, a method for generating a log file as described in any one of claims 1-6 is implemented.
15. A computer-readable storage medium, on which a computer program is stored, wherein, When the program is executed by the processor, a method for generating a log file as described in any one of claims 1-6 is implemented.
Citation Information
Patent Citations
Log processing method and device
CN111651417A