Log management method and electronic equipment
By merging and compressing duplicate and short log structures in electronic devices, the loss problem caused by excessive log printing is solved, and the log storage efficiency and aggregation degree are improved.
Patent Information
- Application Number
- CN202311182726.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-13
- Publication Date
- 2025-03-21
AI Technical Summary
Some logs are lost due to excessive log printing, affecting the log analysis and storage efficiency of electronic devices.
By implementing the merging and compression of log structures in electronic devices, if the information of the log structure is the same as that of the log structure in the cache pool, the timestamp is merged into the existing log structure, and when the preset conditions are met, the merged log structure is written to the socket buffer.
It reduces the probability of log loss, improves the storage efficiency and aggregation of log files, and saves the storage resources of electronic devices.
Smart Images

Figure CN119669170A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of information processing technology, and in particular to a log management method and electronic device. Background Art
[0002] With the continuous development of electronic devices, electronic devices (such as mobile phones, etc.) have gradually become indispensable daily necessities for people. People can use electronic devices to watch videos, read news, etc. When users use electronic devices, electronic devices will generate a large amount of log data, which is generally stored in a log buffer. If the remaining space in the log buffer is insufficient, the electronic device will not be able to store new log data in the log buffer, resulting in log data loss, which may cause the electronic device to be unable to accurately use the log data for problem analysis. Summary of the invention
[0003] The embodiments of the present application provide a log management method and an electronic device, which are used to solve the problem of partial log loss due to excessive log printing and reduce the probability of log loss.
[0004] To achieve the above objectives, the embodiments of the present application adopt the following technical solutions:
[0005] In the first aspect, a log management method is provided, which is applied to an electronic device, in which a first application is installed. In the method, the electronic device receives a log structure issued by a log driver, wherein the log structure is a structure corresponding to a log file generated by the first application. If the log information of the first log structure is the same as the log information of the second log structure in the buffer pool, the timestamp of the first log structure is added to the second log structure to obtain a merged second log structure; wherein the first log structure is any log structure issued by the log driver, and the second log structure is any log structure in the buffer pool. Afterwards, when the preset conditions are met, multiple log structures in the buffer pool are written to the socket buffer.
[0006] In the embodiment of the present application, if the log information of the first log structure is the same as the log information of the second log structure in the buffer pool, it indicates that the first log structure is a duplicate log, therefore, the timestamp of the first log structure can be added to the second log structure, so that the duplicate log files can be merged into one log file, which can improve the aggregation degree of the log files while saving the storage resources of the electronic device, provide storage space for the log files generated subsequently, reduce the occurrence of log loss caused by insufficient storage space of the electronic device, reduce the log loss rate, and improve the storage efficiency of the log files. In addition, only when the preset conditions are met, the log structure in the buffer pool is sent to the socket buffer, so that the storage resources of the electronic device can be saved to the greatest extent, and the storage space of the log can be improved.
[0007] In a possible implementation manner of the first aspect, the method further includes: if the log information of the first log structure is different from the log information of all log structures in the cache pool, storing the first log structure in the cache pool; wherein, during the configuration of the cache pool, the cache pool does not contain the log structure.
[0008] In an embodiment of the present application, if the log information of the first log structure is different from the log information of all log structures in the cache pool, it indicates that the first log structure is a new log. Therefore, in order to facilitate subsequent log analysis, the electronic device can store the first log structure in the cache pool. In this way, the accuracy of the log analysis results can be improved and the occurrence of situations where the log results are affected by missing log files can be reduced.
[0009] In a possible implementation manner of the first aspect, the log information includes at least one of a log name, a process number / thread number, a log priority, a log tag, and log content.
[0010] In a possible implementation of the first aspect, the log information of the merged second log structure includes at least one of a log name, a process number / thread number, a log priority, a log tag, and log content, a log repetition count, and a timestamp linked list. The timestamp linked list includes a timestamp of the log structure that is the same as the log information corresponding to the second log structure.
[0011] In a possible implementation manner of the first aspect, the preset condition includes that a cache duration of the cache pool reaches a preset cache time; and / or a data volume of all log structures in the cache pool reaches a preset data volume.
[0012] In an embodiment of the present application, if the cache time of the cache pool reaches the preset cache time, it means that the log file is stored in the cache area for a long time. Therefore, writing multiple log structures in the cache pool to the socket buffer can avoid the situation where the log cannot be analyzed in time due to the long log storage time, thereby improving the timeliness of the log analysis; if the data volume of all log structures in the cache pool reaches the preset data volume, it indicates that there is no remaining memory space in the cache area. Therefore, writing multiple log structures in the cache pool to the socket buffer can avoid the loss of subsequent log files, save the storage resources of the electronic device to the greatest extent, and improve the storage space of the log.
[0013] In a possible implementation manner of the first aspect, the method further includes: when the cache time length of the cache pool does not reach the preset cache time, the electronic device can continue to receive the log structure sent by the log driver.
[0014] In an embodiment of the present application, if the cache duration of the cache pool does not reach the preset cache time, it indicates that the log files in the cache pool are stored in the cache pool for a short time. Therefore, the electronic device can continue to receive the log structure sent by the log driver to facilitate the subsequent merging of duplicate log structures to improve the aggregation degree of the log.
[0015] In a possible implementation manner of the first aspect, the method further includes: when the data volume of all log structures in the buffer pool does not reach a preset data volume, determining whether the log length in the buffer pool is greater than a preset log length.
[0016] In an embodiment of the present application, if the log cache capacity corresponding to the cache area does not exceed the preset cache capacity, it indicates that although there is a log file timeout in the cache area, there is still free memory space. Therefore, in order for the non-blocking socket buffer to store more log files, the electronic device can determine whether the log length in the cache pool is greater than the preset log length, so as to compress the log structure whose log length is less than the preset log length, thereby saving the storage resources of the socket buffer to the greatest extent.
[0017] In a possible implementation of the first aspect, the process of writing multiple log structures in the cache pool into the socket buffer may specifically include: if the log length of the third log structure is greater than or equal to the preset log length, writing the third log structure into the socket buffer, wherein the third log structure is any log structure among the multiple log structures that has not been written into the socket buffer.
[0018] In an embodiment of the present application, if the log length of the third log structure is greater than or equal to the preset log length, it means that the third log structure is a long log. Therefore, the third log structure can be directly written into the socket buffer. In this way, the sending efficiency of the log structure can be improved and the waste of resources caused by unnecessary log merging can be reduced.
[0019] In a possible implementation manner of the first aspect, the method further includes: if the log length of the third log structure is less than a preset log length, merging the third log structure with one or more fourth log structures until the merged log length is greater than or equal to the preset log length, and writing the merged log structure into a socket buffer, wherein the fourth log structure is a log structure located after the third log structure and not written into the socket buffer.
[0020] In the embodiment of the present application, if the log length of the third log structure is less than the preset log length, it means that the third log structure is a short log. Therefore, in order to improve the log storage efficiency of the cache area, the third log structure can be merged with one or more fourth log structures until the length of the merged log is greater than or equal to the preset log length, that is, until the merged log structure is a long log, the merged log structure is written to the socket buffer. In this way, multiple short log files can be merged into one long log file, which can not only save mobile phone storage resources while improving log aggregation and reducing the probability of log loss, but also reduce the consumption of IO resources due to sending log files to the socket buffer multiple times, thereby improving the calling frequency of IO resources.
[0021] In a possible implementation manner of the first aspect, the process of merging the log structures may specifically include: merging content in one or more fourth log structures that is different from the third log structure into the third log structure.
[0022] In an embodiment of the present application, if the log length of the third log structure is less than the preset log length, the content in the fourth log structure that is different from the third log structure is merged into the third log structure. In this way, while avoiding the merged log length being too long, the log storage efficiency of the socket buffer can be maximized, and the occurrence of log loss due to insufficient storage space of the electronic device can be reduced, providing more storage space for the subsequently issued log structure.
[0023] In a possible implementation of the first aspect, the process of merging the log structures may specifically include: if the log length of the third log structure is less than the preset log length, merging the third log structure with the next log structure after the third log structure to obtain a candidate log file; wherein the third log structure is a log file in the cache whose log length is less than the preset log length. Afterwards, when the log length corresponding to the candidate log file is less than the preset log length, the candidate log file is used as the third log structure, and the process returns to the step of "merging the third log structure with the next log structure after the third log structure to obtain a candidate log file" until the log length corresponding to the candidate log file is not less than the preset log length, and the merged log structure is written into the socket buffer.
[0024] In a possible implementation of the first aspect, the method further includes: determining an arrangement order of the log structures by sorting the storage time corresponding to each log structure in the buffer area according to a preset order. Then, determining a fourth log structure according to the arrangement order of the log structures.
[0025] In a possible implementation of the first aspect, after writing multiple log structures in the cache pool into the socket buffer, the method further includes: reconfiguring the cache pool according to preset cache information; wherein the preset cache information includes a preset cache time and / or a preset data volume.
[0026] In a possible implementation manner of the first aspect, the method further includes: when the preset cache information includes a preset cache time, reconfiguring a timer; wherein the timer is used to record the time when the log file is stored in the cache pool.
[0027] In the embodiment of the present application, after sending multiple log structures in the buffer pool, the mobile phone can reset the buffer area and the timer, providing a basis for subsequent storage of log files in the buffer area.
[0028] In a possible implementation of the first aspect, when a log structure sent by a log driver is received, if the first application is an application that sends a log file for the first time, the cache pool is initialized and configured according to preset cache information; wherein the preset cache information includes a preset cache time and / or a preset data volume.
[0029] In an embodiment of the present application, after obtaining the above-mentioned log structure, the electronic device can determine whether to initialize the cache area. If the electronic device has not initialized the cache area, it indicates that the current application process generates a log file for the first time. Therefore, the electronic device can initialize the cache area; if the electronic device has initialized the cache area, it indicates that the current application or process does not generate a log file for the first time. Therefore, the electronic device does not need to initialize the cache area to avoid unnecessary waste of resources.
[0030] In a possible implementation manner of the first aspect, the method further includes: when the preset cache information includes a preset cache time, initializing and configuring a timer; wherein the timer is used to record the time when the log file is stored in the cache pool.
[0031] In the embodiment of the present application, if the preset cache information includes the preset cache time, it indicates that the mobile phone needs to obtain the log cache time, so the mobile phone can configure a timer to facilitate determining the storage time of the log file, thereby providing a basis for the subsequent determination of the log cache time of the cache pool. In addition, since the electronic device may cause a delay between the log generation time and the log storage time due to reasons such as freezing, in order to accurately calculate the cache time of the log file, in this embodiment, the electronic device can directly obtain the storage time of the log file through a timer.
[0032] In a possible implementation of the first aspect, the method further includes: sending the log structure in the socket buffer to the log recording module. Afterwards, restoring the log structure received by the log recording module to obtain an initial log structure; wherein the initial log structure is a structure corresponding to a log file generated by the first application and not subjected to log merging.
[0033] In an embodiment of the present application, if the log structure is sent to the log recording module, the electronic device can parse the received log structure so that the merged log structure can be restored. This can facilitate subsequent analysis of the log file and improve the efficiency of log analysis.
[0034] In a possible implementation of the first aspect, the method further includes: based on the log flow corresponding to the log files in the cache area, preferentially compressing the log files with the largest log flow to obtain compressed log files. Thereafter, writing the structure corresponding to the compressed log files into the socket buffer.
[0035] In an embodiment of the present application, not only can duplicate log files and log files with less characters be merged, but log files with larger log traffic can also be compressed. In this way, the aggregation degree of log files can be maximized, the waste of storage resources can be reduced, and the storage efficiency of the socket buffer can be improved.
[0036] In a possible implementation of the first aspect, the method further includes: compressing log files with high log priorities according to the log priorities corresponding to the log files in the cache area to obtain compressed log files. Thereafter, writing the structure corresponding to the compressed log files into the socket buffer.
[0037] In an embodiment of the present application, not only can duplicate log files and log files with fewer characters be merged, but log files with higher log priorities can also be compressed. In this way, the aggregation degree of log files can be maximized, the waste of storage resources can be reduced, and the storage efficiency of the socket buffer can be improved.
[0038] In a second aspect, the present application provides an electronic device, comprising a memory and one or more processors; the memory and the processor are coupled; the memory is used to store computer program code, and the computer program code comprises computer instructions; when the processor executes the computer instructions, the electronic device executes the method as described above.
[0039] In a third aspect, the present application provides a computer-readable storage medium, comprising computer instructions, which, when executed on an electronic device, enables the electronic device to execute the method described above.
[0040] In a fourth aspect, the present application provides a computer program product, which, when executed on an electronic device, enables the electronic device to execute the method described above.
[0041] In a fifth aspect, a chip is provided, comprising: an input interface, an output interface, a processor and a memory, wherein the input interface, the output interface, the processor and the memory are connected via an internal connection path, and the processor is used to execute the code in the memory. When the code is executed, the processor is used to execute the method as described above.
[0042] Among them, the beneficial effects that can be achieved by the electronic device described in the second aspect, the computer-readable storage medium described in the third aspect, the computer program product described in the fourth aspect, and the chip described in the fifth aspect provided above can refer to the beneficial effects in the first aspect and any possible design method thereof, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 A schematic diagram of the structure of a log system provided in an embodiment of the present application;
[0044] Figure 2 A schematic diagram of an interface in which a user slides upwards on a news interface provided in an embodiment of the present application;
[0045] Figure 3 A schematic diagram of an interface for entering an initial interface of a video application provided in an embodiment of the present application;
[0046] Figure 4 A schematic diagram showing multiple duplicate logs provided in an embodiment of the present application;
[0047] Figure 5 A schematic diagram showing multiple short logs provided in an embodiment of the present application;
[0048] Figure 6 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application;
[0049] Figure 7 A schematic diagram of the software structure of an electronic device provided in an embodiment of the present application;
[0050] Figure 8 A schematic diagram of the structure of another log system provided in an embodiment of the present application;
[0051] Fig. 9 A flow chart of a log management method provided in an embodiment of the present application;
[0052] Fig.10 A structural diagram of a log structure table corresponding to a log file provided in an embodiment of the present application;
[0053] Fig.11 A schematic diagram of the structure of a log structure provided in an embodiment of the present application;
[0054] Fig.12 A flowchart of another log management method provided in an embodiment of the present application;
[0055] Fig.13 A schematic diagram of the structure of a timestamp chain in a log structure provided in an embodiment of the present application;
[0056] Fig.14 A schematic diagram of merging duplicate logs provided in an embodiment of the present application;
[0057] Fig.15 A structural diagram of a log structure table corresponding to a reorganized log file provided in an embodiment of the present application;
[0058] Fig.16 A schematic diagram of another method for merging duplicate logs provided in an embodiment of the present application;
[0059] Fig.17 A schematic diagram of adding duplicate logs to a cache area provided in an embodiment of the present application;
[0060] Fig.18 A schematic diagram of merging short logs in a cache area provided in an embodiment of the present application;
[0061] Fig.19 A schematic diagram of merging short logs in another buffer area provided in an embodiment of the present application. DETAILED DESCRIPTION
[0062] The technical scheme in the embodiment of the present application will be described below in conjunction with the accompanying drawings in the embodiment of the present application. Wherein, in the description of the present application, unless otherwise specified, the "and / or" in the present application is only a kind of association relationship describing the associated object, indicating that there can be three kinds of relationships, for example, A and / or B, which can be represented by: A exists alone, A and B exist at the same time, and B exists alone, wherein A, B can be singular or plural. And, in the description of the present application, unless otherwise specified, "multiple" refers to two or more than two. "At least one of the following (individuals)" or its similar expressions refers to any combination of these items, including any combination of single items (individuals) or plural items (individuals). For example, at least one of a, b, or c (individuals) can be represented by: a, b, c, ab, ac, bc, or abc, wherein a, b, c can be single or multiple. In addition, in order to facilitate the clear description of the technical scheme of the embodiment of the present application, in the embodiment of the present application, the words "first", "second" and the like are used to distinguish the same items or similar items with substantially the same functions and effects. Those skilled in the art will appreciate that words such as "first" and "second" do not limit the quantity and execution order, and words such as "first" and "second" do not necessarily limit the difference. At the same time, in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a concrete way for easy understanding.
[0063] In some embodiments, the electronic device can implement the distribution, storage and analysis of log files (or log data) through the log system. Figure 1As shown, the log system may include a system (system) / log (liblog) library, a socket (socket) buffer, and a log record (logd) module. Among them, the system / log library is used to send and receive log files, and the system / log library can be called by any process. The socket buffer is used to receive log files issued by the system / log library. The logd module is the core process of the log system, and the logd module is used to store and manage log files.
[0064] The above-mentioned system / log library includes a log sending driver (logger_write), a log sending interface (logd_writer), a log reading driver (logger_read) and a log reading interface (logd_reader). Among them, the log sending driver is used to control the log sending interface to send log files. The log sending interface is used to send log files. The log reading driver is used to establish a communication connection between the log reading interface and the xlogcat / logcatz module and the logcat module. The log sending interface is used to send log files and log reading requests.
[0065] The above socket buffer includes logdw, logdr and logd node files. Among them, the logdw node file is used to store the log files sent by the above log sending interface. The logdr node file is used to store the log files sent by the logd module. The logd node file is used to store the log reading request sent by the above log reading interface.
[0066] In this embodiment, the above-mentioned socket buffer is generally set to a non-blocking mode, which means that when the socket buffer has no memory space to store log files, the socket buffer can return the log files that cannot be stored in the socket buffer, that is, the socket buffer will refuse to write new log files. Therefore, if the frequency of sending log files is too high, it may cause the socket buffer to receive logs at a higher frequency than the frequency of sending logs, that is, the number of logs received by the socket buffer is greater than the number of logs sent by the socket buffer, which will cause the socket buffer to be full and unable to receive new log files, resulting in the loss of log files. It is understandable that if the log files are lost, it may not be possible to analyze the lost log files, and thus it may not be possible to solve the problem in a timely manner, which will ultimately affect the user experience.
[0067] The above-mentioned logd module includes a log listener, a log buffer, a log reader and a command listener. Among them, the log listener is a log collection client provided by the log service for quickly accessing the log service. The log reader is used to read the log file in the buffer. The command listener is used to monitor the log reading request in the logd node file. The log buffer may include a main buffer, a system buffer, a crash buffer and an event buffer, etc. The main buffer is used to store logs related to the application, the system buffer is used to store logs related to system calls and system frameworks, the crash buffer is used to store logs related to system failures such as system jams, that is, logs with higher priority, and the events buffer is used to store logs corresponding to the interfaces of the upper layer calling and system events. Exemplary, taking the display interface of a user sliding an electronic device as an example, the logd module can store the sliding event in the events buffer. It should be noted that different areas correspond to different interfaces, and the log files in the area can be parsed by calling the corresponding interfaces.
[0068] Specifically, the application program (or upper layer application) in the electronic device can call the log sending driver in the system / log library through Java or C or C++ to send the log file to the logdw node file in the non-blocking socket buffer through the log sending interface, wherein the log file is embodied in the form of a log structure. Afterwards, the log listener in the logd module listens to the log file in the logdw node file. Afterwards, when the log listener listens to the non-blocking socket buffer including the log file, the log file is sent to the log buffer.
[0069] In some embodiments, if the logcat module wishes to obtain the above-mentioned log file, the logcat module can call the log reading driver, and call the log reading interface to send the log reading request (or log reading command) to the logd node file in the non-blocking socket buffer. Afterwards, when the logd node file receives the log reading request, if the command listener in the logd module detects that the log reading request is included in the logd node file, the above-mentioned log buffer receives the log reading request in the logd node file. Afterwards, the log reader in the logd module parses the log file by calling the interface corresponding to the log file. Afterwards, the log reader can send the parsed log file to the logdr node file in the non-blocking socket buffer. Afterwards, when the logdr node file receives the log file, the log reading interface in the system / log library is used to send the log file to the log reading driver. Afterwards, the log reading driver can send the log file to the logcat module to achieve the acquisition of the log file.
[0070] It should be noted that Figure 1 The xlogcat / logcatz module in is a log disk service, which is used to store the log files in the above log buffer to prevent the log files in the log buffer from being cleared due to power failure, restart, etc. of the electronic device. In other words, the xlogcat / logcatz module can be used to back up the log files in the log buffer to prevent the loss of log files.
[0071] In some embodiments, when a user uses an electronic device (such as a mobile phone, etc.), the application process in the electronic device may send a large amount of log data (or log files) at a high frequency due to some reasons (such as the user's finger sliding the screen, etc.), that is, a large amount of log data will be generated in the above log system. Afterwards, the electronic device can perform log analysis based on the large amount of log data.
[0072] Take the mobile phone as an example, Figure 2 As shown, the mobile phone is displaying the news content corresponding to news 1 to news 5. The user can swipe up on the currently displayed news interface according to their own needs. After that, the mobile phone can display the page after the upward swipe operation according to the user's upward swipe operation, that is, display the news content corresponding to news 2 to news 6. It can be understood that when the user performs the upward swipe operation, the mobile phone will generate a large amount of log data according to the change of the touch position of the upward swipe operation.
[0073] Take the mobile phone as an example, Figure 3As shown, the mobile phone displays the main interface, which includes icons and names of multiple APPs. The user can click on any APP icon in the main interface according to his or her own needs, such as clicking on the icon 11 of the video application. In response to the user's click operation, the mobile phone can display the initial interface 12 of the video application, that is, display the cover images corresponding to multiple videos. It can be understood that if the mobile phone receives the user's click operation and fails to display the initial interface of the video application in time during the process of responding to the click operation, that is, the mobile phone has a page jam, therefore, the mobile phone will generate a large number of error logs due to the page jam, so that the mobile phone can analyze the problem according to the error log later.
[0074] It is understandable that if the amount of log data sent by the application process is too much, the log data will occupy too much storage space (such as local memory space, cloud storage space, etc.), which will not only cause excessive waste of storage resources, but also due to the large number of logs, it may cause key log data to be diluted, which is not conducive to subsequent problem analysis of the log data, and thus the problem cannot be solved in a timely manner.
[0075] In one example, if Figure 4 As shown, taking 4 log files among the large number of log files as an example, the log information corresponding to log file 1 is "06-14 14:50:02.410 2662 6377IPCUtils:IS_ASSIST_MODE is:false", the log information corresponding to log file 2 is "06-14 14:50:02.411 2662 6377IPCUtils:IS_ASSIST_MODE is:false", the log information corresponding to log file 3 is "06-14 14:50:02.411 26626377IPCUtils:IS_ASSIST_MODEis:false", and the log information corresponding to log file 4 is "06-14 14:50:02.411 2662 6377IPCUtils:IS_ASSIST_MODE is:false". It can be seen from these 4 log files that, except for the timestamp, the rest of the log information in the 4 log files is the same, that is, except for the timestamp corresponding to the log file, the rest of the log information in the duplicate log files is duplicated. Therefore, if the duplicate log files are stored in the socket buffer in sequence, not only a large amount of transmission resources will be consumed, but also storage resources will be wasted, which will lead to the inability to store subsequent useful log files, and thus log analysis cannot be performed based on the useful log files.
[0076] In another example, if Figure 5As shown in the figure, taking three log files among a large number of log files as an example, the log information corresponding to log file A includes "06-14 14:50:02.419 29536 29536I BaseActivity:onCreate", the log information corresponding to log file B includes "06-14 14:50:02.420 29536 29536I BaseActivity:onCreateCommon", and the log information corresponding to log file C includes "06-14 14:50:02.420 29536 29536IBaseActivity:addWindowFlags". It can be seen from these three log files that except for the timestamp and log content, the rest of the log information in the three log files is the same, that is, except for the timestamp and log content corresponding to the log file, the rest of the log information in the log file with a shorter string is repeated. Therefore, if each short log file is stored in the socket buffer as an independent log file, it will not only consume a lot of transmission resources, but also cause a waste of storage resources, which will lead to the inability to store subsequent useful log files, and thus the inability to perform log analysis based on the useful log files in time.
[0077] However, according to the above Figure 4 as well as Figure 5 It can be seen from the log files in that a large number of log files issued by the application process in the above-mentioned electronic device may have the characteristics of information redundancy and short character quantity, that is, the large number of log files may include some repeated log files and log files with shorter character strings, wherein the repeated log files are generated by calling log printing in the process of loop execution. Therefore, in order to solve the problem of the above-mentioned log file loss, the embodiment of the present application provides a log management method and an electronic device. In the method, the electronic device obtains a log file, wherein the log file is a file generated by the application process in the electronic device. Afterwards, when the log file meets the preset log condition, the electronic device performs log merging on the log file to obtain a target log file, wherein the log file meets the preset log condition means that there is a log file with the same log information as the log file in the buffer area (or buffer pool) and / or the log length corresponding to the log file is less than the preset log length. Afterwards, the electronic device sends the target log file to the socket buffer, wherein the socket buffer is used to send the target log file to the logd module, and the logd module is used to store and manage logs.
[0078] In an embodiment of the present application, the electronic device can process duplicate log files and log files with shorter log lengths respectively to obtain reconstructed log files. In this way, not only can duplicate log files be merged, but multiple short log files can also be merged into one long log file, thereby improving the aggregation degree of log files, reducing the waste of storage resources, and thus reducing the probability of losing useful log files, providing a basis for subsequent log file analysis.
[0079] Exemplarily, the electronic device may be any embedded electronic device capable of printing logs at a high frequency, such as a mobile phone, a tablet computer, a laptop computer, a desktop computer, a watch, a vehicle-mounted device, etc. The embodiments of the present application do not impose any restrictions on the specific type of the electronic device.
[0080] Figure 6 is a schematic diagram of the hardware structure of the electronic device 100 provided in the embodiment of the present application, such as Figure 6 As shown, the electronic device 100 may include a processor 110, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an external memory interface 120, an internal memory 121, and the like.
[0081] It is to be understood that the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or separate some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0082] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0083] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.
[0084] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0085] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, etc.
[0086] The I2S interface can be used for audio communication. The PCM interface can also be used for audio communication to sample, quantize and encode analog signals.
[0087] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.
[0088] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.
[0089] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the same device as at least some of the modules of the processor 110.
[0090] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as WIFI (wireless fidelity) network), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR) and the like applied to the electronic device 100. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and performs filtering, and sends the processed signal to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, modulate the frequency of the signal, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2. In some embodiments, at least some functional modules of the wireless communication module 160 can be set in the processor 110.
[0091] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present invention is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0092] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100 .
[0093] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), etc.
[0094] In some embodiments, the data storage area may also store log files generated by applications or processes during the use of the electronic device 100. Exemplarily, the data storage area may include a buffer pool, which is used to store short-term log structures, that is, log structures whose storage time is less than a preset storage time.
[0095] In addition, the internal memory 121 may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.
[0096] Exemplarily, the software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present invention takes the Android system of the layered architecture as an example to exemplify the software structure of the electronic device 100.
[0097] Figure 7 It is a software structure block diagram of the electronic device 100 according to an embodiment of the present application.
[0098] The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom, namely, the application layer (referred to as the application layer), the application framework layer (referred to as the framework layer), the Android runtime (Android runtime) and the system library, and the kernel layer (or driver layer). The application layer can include a series of application packages.
[0099] The application layer may include a series of application packages. The application layer may include multiple application packages. Figure 7 As shown, the application package may be a camera, calendar, map, WLAN, music, short message, gallery, call, navigation, Bluetooth, video and other applications.
[0100] The application framework layer provides application programming interface (API) and programming framework for the applications in the application layer. The application framework layer includes some predefined functions. Figure 7 As shown, the application framework layer may include a window manager, a content provider, a phone manager, a resource manager, a notification manager, a package manager, and the like.
[0101] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.
[0102] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0103] The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including connecting, hanging up, etc.).
[0104] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0105] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0106] The package manager is used to manage the information of applications installed by the system, and to query the information of each installation package and the information of applications with hidden icons.
[0107] Android runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.
[0108] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.
[0109] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0110] The system library may include multiple functional modules. For example: surface manager, media libraries, 3D graphics processing library (for example: OpenGL ES), log library, logd module, logcat module, etc. Among them, the log library is used to send and receive log files. The log library may include a log sending driver, a log sending interface, a log reading driver, a buffer area, a log reading interface, etc.
[0111] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.
[0112] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0113] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0114] The log sending driver is used to send the log file. Specifically, through the log sending driver, the log file can be sent to a non-blocking socket buffer.
[0115] The log sending interface is used to send log files. Specifically, calling the log sending interface can send the log file to the cache area.
[0116] The log reading driver is used to read the log file. Specifically, through the log reading driver, the log file can be sent to the logcat module to obtain the log file.
[0117] The log reading interface is used to send log files. Specifically, calling the log sending interface can send the log file in the non-blocking socket buffer to the logcat module.
[0118] The cache area is used to temporarily store log files. Specifically, when a log file sent by the log sending interface is received, the cache area can store the log file.
[0119] The logd module is used to manage and store log files. Specifically, when a log file is detected to be stored in the non-blocking socket buffer, the log file is stored.
[0120] The logcat module is used to obtain log files.
[0121] The kernel layer is a layer between hardware and software. The kernel layer at least includes display driver, camera driver, audio driver, non-blocking socket buffer, etc. Among them, the non-blocking socket buffer is used to store log files. Specifically, the non-blocking socket buffer is used to receive log files sent by the buffer area. The non-blocking socket buffer may include logdw, logdr and logd node files.
[0122] In some embodiments, the electronic device can compress and reorganize the log file through the buffer area in the system library to reduce the occurrence of log loss. Figure 8 As shown, the electronic device (or the application in the electronic device, the process in the electronic device) can call the log sending driver in the system / log library through Java or C or C++ to send the log file. Afterwards, the electronic device can send the log file to the cache area through the log sending interface. Afterwards, the electronic device can send the log file in the cache area to the non-blocking socket buffer when the cache time of the log file exceeds the preset cache time and / or the number of log files in the cache area exceeds the preset cache number. Afterwards, the log listener in the logd module can receive the log file sent by the non-blocking socket buffer when it monitors that the logdw node file in the non-blocking socket buffer stores the log file.
[0123] Afterwards, if the logcat module wants to obtain the above-mentioned log file, the logcat module can call the log reading interface through the log reading driver to send the log reading request to the logd node file in the non-blocking socket buffer. Afterwards, when the logd node file receives the log reading request, if the command listener in the logd module detects that the log reading request is included in the logd node file, the above-mentioned log buffer receives the log reading request in the logd node file. Afterwards, the log reader in the logd module parses the log file by calling the interface corresponding to the log file. Afterwards, the log reader can send the parsed log file to the logdr node file in the non-blocking socket buffer. Afterwards, when the logdr node file receives the log file, the log file is sent to the log reading driver through the log reading interface in the system / log library. Afterwards, the log reading driver can send the log file to the logcat module.
[0124] The log management method of the embodiment of the present application can be applied to scenarios where logs are printed frequently (such as logs recording the position of the user's finger sliding on the screen, and a large number of error logs printed due to system freezes, etc.). The following will take the electronic device as an example of a mobile phone to illustrate the method of the embodiment of the present application. Specifically, Fig. 9 As shown, the log management method may include S801 to S810.
[0125] S801, the mobile phone obtains a log file.
[0126] The log file is a file sent by the log driver. The log file (or log data) is used to record the operation status of the hardware, software and system in the mobile phone. In other words, the mobile phone can determine whether there are problems with the hardware, software and system in the mobile phone based on the log file. For example, if the mobile phone freezes or crashes, the mobile phone can determine the operation status of the mobile phone by analyzing the log file, and then determine the cause of the failure. For example, the user clicks on Figure 3 If the mobile phone cannot respond to the user's click operation in time, that is, the mobile phone needs to wait for a while before displaying the initial interface of the video application (such as Figure 3 The interface 12) shown in the figure indicates that the mobile phone has a page freeze. Therefore, the mobile phone can analyze the cause of the page freeze based on the obtained log file.
[0127] It should be noted that the above log file is generated by the application process (or referred to as the first application) in the mobile phone when the system is running. The process is an instance of the program running in the mobile phone.
[0128] Specifically, the log file may include at least one of a log name (logId), a process ID / thread ID (tid / pid), a timestamp (timespec), a log priority (priority), a log tag (tag), and a log content (msg). Figure 1 The name of the area corresponding to the buffer in the buffer. For example, if the log file is related to an application (such as a video APP), the log name corresponding to the log file is log_id_main. It should be noted that the log name corresponding to the log file defaults to log_id_main.
[0129] Wherein, the above-mentioned log priority can include verbose (verbose, V), debug (debug, D), information (info, I), warning (warn, W), error (error, E) and fatal (fatal, F). It can be understood that the log priority is used to characterize the importance of the log file, that is, the higher the priority of the log file, the more important the log file. Specifically, the importance of the log file corresponding to the priority V is lower than the log file corresponding to the priority D, the importance of the log file corresponding to the priority D is lower than the log file corresponding to the priority I, the importance of the log file corresponding to the priority I is lower than the log file corresponding to the priority W, the importance of the log file corresponding to the priority W is lower than the log file corresponding to the priority E, and the importance of the log file corresponding to the priority E is lower than the log file corresponding to the priority F. In other words, the log file corresponding to the priority F is the most important.
[0130] For example, the above Figure 4 Take log file 1 in the example as an example, and analyze the log file 1 to get the following Fig.10 The log structure table shown. Specifically, the process number / thread number corresponding to log file 1 is 2662 / 6377, the timestamp corresponding to log file 1 is 06-14 14:50:02.410, the log priority corresponding to log file 1 is 1, the log tag corresponding to log file 1 is PCUtils, and the log content corresponding to log file 1 is IS_ASSIST_MODE is:false. It can be understood that since the log name is not displayed in the log file 1, the mobile phone can assume that the log name corresponding to the log file 1 is log_id_main.
[0131] In this application, the storage unit of the log file is a structure array, that is, the log file is sent in the form of a log structure through a log driver and a log interface. The log structure (or first log structure) may include multiple sub-log structures (iovec), and each log structure sent encapsulates the starting address and log length of a memory block. For example, Fig.11 As shown, the log structure includes two member variables, namely a pointer variable (iov_base) and a length variable (iov_len). The pointer variable is used to point to the starting address of the log file. The length variable is used to indicate the log length of the log file.
[0132] In one example, Fig.10 The nr in the log file represents the total number of sub-log structures in the log file, for example, Fig.10The nr corresponding to log file 1 is 4. Among them, iovec[0] is the first sub-log structure (or called the head sub-structure), iovec[1] is the second sub-log structure, and iovec[nr-1] is the last sub-log structure, that is, the fourth sub-log structure. It should be noted that the head sub-structure corresponding to the log file in the native log system includes the log name, process number / thread number, and timestamp. After that, the other sub-structures corresponding to each log file correspond to a structure type (or member variable), that is, iovec[1] corresponds to the log priority of the log file, iovec[2] corresponds to the log tag of the log file, and iovec[3] corresponds to the log content of the log file. For example, taking the above-mentioned log file 1 as an example, iovec[0] corresponding to log file 1 includes "06-14 14:50:02.410 2662 / 6377", iovec[1] corresponding to log file 1 includes "I", iovec[2] corresponding to log file 1 includes "PCUtils", and iovec[3] corresponding to log file 1 includes "IS_ASSIST_MODEis:false".
[0133] In one implementation, the mobile phone can pre-configure cache information, wherein the cache information may include cache time and / or cache capacity. The cache time refers to the time that the log file can be stored in the cache area. The cache capacity refers to the total length of the log file that can be stored in the cache area (or cache pool). Afterwards, after obtaining the above-mentioned log file, the mobile phone can directly obtain the pre-configured cache information (or preset cache information), and judge the log information cached in the cache area based on the preset cache information, without initializing the configuration of the cache area.
[0134] In another implementation, if the log file is generated by a new process in the mobile phone, that is, the new process calls the log sending interface for the first time to send the log file, the mobile phone can initialize the cache area according to the preset cache information. It can be understood that during the initialization configuration of the cache pool, the cache pool does not contain log files, that is, the cache pool is empty.
[0135] Specifically, after obtaining the above log file, the mobile phone can determine whether to initialize the cache area. If the mobile phone has not initialized the cache area, it indicates that the current application process generates a log file for the first time. Therefore, the mobile phone can initialize the cache area. If the mobile phone has initialized the cache area, it indicates that the current application or process does not generate a log file for the first time. Therefore, the mobile phone does not need to initialize the cache area to avoid unnecessary waste of resources. Exemplarily, the process of determining the initialization of the cache area by the mobile phone may include the following: Fig.12 S10-S30 shown.
[0136] S10, the mobile phone determines whether the cache area has been initialized and configured.
[0137] Exemplarily, if the mobile phone has not initialized the cache area, the mobile phone can execute S20. If the mobile phone has initialized the cache area, the mobile phone can execute S802. The cache area is a memory area with preset space in the mobile phone, which is used to temporarily store log files generated by the same process.
[0138] In some embodiments, the mobile phone can determine whether the above-mentioned cache area is initialized by judging whether the process in the mobile phone calls the log sending interface for the first time. If the process calls the log sending interface for the first time, it indicates that the process has not sent a log file. Therefore, the mobile phone can determine that the cache area has not been initialized. If the process does not call the log sending interface for the first time, it indicates that the process has sent a log file. Therefore, the mobile phone can determine that the cache area has been initialized.
[0139] S20, the mobile phone initializes and configures the cache area according to preset cache information to obtain a configured cache area, wherein the preset cache information may include a preset cache time and / or a preset cache capacity.
[0140] In some embodiments, the preset cache information corresponding to each process in the mobile phone may be the same or different, and is not specifically limited. The preset cache information may include a preset cache time and / or a preset cache capacity (or preset data volume).
[0141] The above-mentioned preset cache time is the pre-set maximum time that the log file can be stored. It can be understood that since the log file is time-sensitive, that is, if the cache time of the log file exceeds the preset cache time, it means that the log file is stored in the cache area for a long time. Therefore, in order to avoid the inability to analyze the log in time due to the long storage time of the log file, the mobile phone can send all log files in the cache area after the cache time of the log file exceeds the preset cache time. For example, the mobile phone can send the log file to a non-blocking socket buffer.
[0142] The above-mentioned preset cache capacity is a pre-set maximum length that can store log files. It can be understood that since the above-mentioned cache area is a part of the memory area in the mobile phone, and the memory area corresponding to the cache area is pre-divided, that is to say, the total length (or data volume) of all log files in the cache area cannot exceed the memory area corresponding to the cache area (or called the preset cache capacity, preset data volume). Therefore, if the total length of all log files in the cache area is greater than the preset cache capacity, it means that the cache area has no remaining memory space. Therefore, in order to avoid the loss of subsequent log files, the mobile phone can send all log files in the cache area after the data volume of all log files in the cache area is greater than the preset cache capacity. For example, the mobile phone can send all log files in the cache area to a non-blocking socket buffer.
[0143] S30, the mobile phone configures a timer, wherein the timer is used to record the storage time of the above log file.
[0144] The storage time indicates the time when the log file is stored in the cache area.
[0145] In some embodiments, the mobile phone may need to configure a timer to facilitate determining the storage time of the log file, thereby providing a basis for subsequently determining the log cache time of the cache pool. Among them, the storage time of the log file is the time corresponding to when the log file is stored in the cache area. It should be understood that the timestamp in the log file is the timestamp of the log file generation. Under normal circumstances, the log generation time and the log storage time should be the same, but in fact, there may be a delay between the log generation time and the log storage time due to reasons such as jamming. Therefore, in order to accurately calculate the cache time of the log file, in this embodiment, the mobile phone can directly obtain the storage time of the log file through the timer.
[0146] In other embodiments, although there may be a delay between the log generation time and the log storage time, the delay may be small, that is, the delay can be ignored. Therefore, the mobile phone may not configure a timer, that is, does not obtain the storage time of the log file, and directly uses the timestamp in the log file as the storage time of the log file.
[0147] Specifically, after obtaining the preset cache information, if the preset cache information includes the preset cache time, it indicates that the mobile phone needs to obtain the log cache time. Therefore, the mobile phone can configure a timer to calculate the log cache time. That is to say, when the preset cache information is the preset cache capacity, the mobile phone can not configure a timer to reduce unnecessary resource waste. It can be understood that when the cache area receives a log file, the mobile phone can refresh the timer, that is, the timer starts counting from the current timestamp until the accumulated time of the timer reaches the preset cache time, and the mobile phone sends all log files in the cache area to the non-blocking socket buffer.
[0148] S802, the mobile phone determines whether there is a log file in the cache area with the same log information as that corresponding to the above log file.
[0149] The above-mentioned log information includes all contents in the log structure except the timestamp, that is, the log information includes at least one of the log name, process number / thread number, log priority, log tag and log content.
[0150] In some embodiments, after obtaining the above-mentioned log file, the mobile phone can determine whether there is a log file in the cache area with the same log information as that corresponding to the log file, that is, determine whether the log information corresponding to the log file is repeated with the log information corresponding to any log file in the cache area. If there is a log file in the cache area with the same log information as that corresponding to the log file, it indicates that the log file obtained by the mobile phone is a duplicate log, and the mobile phone can execute S803; if there is no log file in the cache area with the same log information as that corresponding to the log file, it indicates that the log file obtained by the mobile phone is not a duplicate log, that is, it is a new log file, then the mobile phone does not need to process the log file, that is, the mobile phone can execute S804 to continue to judge the log file.
[0151] It can be understood that since the time when the above-mentioned log file and the log file in the above-mentioned cache area were generated may be different, that is, the timestamps corresponding to the log file and the log file in the cache area are different. Therefore, when the mobile phone determines whether the log contents are the same, there is no need to judge the timestamp. In other words, the mobile phone only needs to determine whether the log name, process number / thread number, log priority, log tag and log content are all the same.
[0152] In an example, if the log structure corresponding to the above log file is "06-14 14:50:02.411 26626377IPCUtils:IS_ASSIST_MODE is:false", and the log structure corresponding to a log file in the above cache area is "06-14 14:50:02.410 2662 6377IPCUtils:IS_ASSIST_MODE is:false", it means that there is a log file in the cache area with the same log information as the log file corresponding to the log file, that is, the log file is a duplicate log.
[0153] In another example, if the log structure corresponding to the above log file is "06-14 14:50:02.41929536 29536IBaseActivity:onCreate", and the log structures corresponding to the log files in the above cache area are "06-1414:50:02.420 29536 29536I BaseActivity:onCreateCommon" and "06-14 14:50:02.420 2953629536I BaseActivity:addWindowFlags", then the log structure corresponding to the log file is different from the log structure corresponding to the log file in the cache area, that is, there is no log file in the cache area with the same log information corresponding to the log file, that is, the log file is not a duplicate log.
[0154] In some embodiments, after obtaining the above log file, the mobile phone can determine whether there is a log file with the same log content as the above log file among the preset number of log files located before the timestamp corresponding to the log file in the cache area. Figure 5Taking log file A, log file B and log file C in the cache as an example, if the preset number is 2, the mobile phone can compare the log file obtained by the mobile phone with the log information corresponding to log file B and log file C in the cache area. If the log information corresponding to the log file obtained by the mobile phone is "06-1414:50:02.420 29536 29536I BaseActivity:onCreateCommon", it means that the log file is the same as the log information corresponding to log file B in the cache area. Therefore, the mobile phone can determine that the log file is a duplicate log, that is, the mobile phone can reorganize the log file with the log file B in the cache area; if the log information corresponding to the log file obtained by the mobile phone is "06-14 14:50:02.420 29536 29536I BaseActivity:onCreate", it means that the log file is different from the log information corresponding to log file B and log file C in the cache area. Therefore, the mobile phone can determine that the log file is not a duplicate log.
[0155] S803, the mobile phone adds the timestamp and the log repetition count corresponding to the above log file to the first log file to obtain a new log file, wherein the log information corresponding to the first log file is the same as that of the log file.
[0156] Specifically, after determining that there is a log file in the cache area with the same log information as the above log file, the mobile phone can merge the log file and the log file in the cache area with the same log information as the log file (or called the first log file). In this way, the duplicate log files can be merged into one log file, which can save the storage resources of the mobile phone while improving the aggregation of log files, providing storage space for subsequently generated log files, reducing the occurrence of log loss due to insufficient storage space of the mobile phone, reducing the log loss rate, and improving the storage efficiency of log files. Among them, log merging refers to adding the number of log repetitions and the timestamp corresponding to the duplicate logs on the basis of the first log file.
[0157] The first log file being identical to the log information corresponding to the log file means that the log information of the log structure (or referred to as the second log structure) corresponding to the first log file is identical to the log information of the first log structure.
[0158] It is understandable that the cache area may include at least one log file, wherein the log file may be a log file directly obtained by the mobile phone, or a log file obtained by reorganizing the log file, that is, a new log file, which is not specifically limited.
[0159] In some embodiments, the new log file may include at least one of a log name, a process number / thread number, a log priority, a log tag, a log content, a log repetition count (repeat_count), and a timestamp list (timespec_list). For example, Fig.13 As shown, the timestamp linked list includes a current timestamp and a pointer to a next timestamp, and the length of the linked list corresponding to the timestamp linked list is determined by the number of log repetitions.
[0160] In one example, if Fig.14 As shown in the figure, taking 4 log files as an example, the log content corresponding to log file 1 is "06-14 14:50:02.410 2662 6377IPCUtils:IS_ASSIST_MODE is:false", the log information corresponding to log file 2 is "06-14 14:50:02.411 2662 6377IPCUtils:IS_ASSIST_MODE is:false", the log information corresponding to log file 3 is "06-14 14:50:02.411 2662 6377IPCUtils:IS_ASSIST_MODE is:false", and the log information corresponding to log file 4 is "06-14 14:50:02.411 2662 6377IPCUtils:IS_ASSIST_MODE is:false". It can be seen from these four log files that the log information of the four log files is the same except for the timestamp. Therefore, the mobile phone can merge the four log files to obtain log file 1234. Among them, the log information corresponding to the log file 1234 is "06-14 14:50:02.410 2662 6377IPCUtils:IS_ASSIST_MODE is:false[×4][14:50:02.411][14:50:02.411][14:50:02.411]". It can be understood that [×4] in log file 1234 is the number of log repetitions, and [14:50:02.411][14:50:02.411][14:50:02.411] in log file 1234 is the timestamp corresponding to the repeated log, that is, the timestamps corresponding to log files 2, 3 and 4.
[0161] Afterwards, the mobile phone can analyze the log file 1234 and obtain the following Fig.15The log structure table shown. Specifically, the process number / thread number corresponding to log file 1234 is 2662 / 6377, the log priority corresponding to log file 1234 is I, the log tag corresponding to log file 1234 is PCUtils, the log content corresponding to log file 1234 is IS_ASSIST_MODE is:false, the log repetition times corresponding to log file 1234 is [×4], and the timestamp linked list corresponding to log file 1234 includes [14:50:02.411][14:50:02.411][14:50:02.411]. It can be understood that since the log name is not displayed in the log file 1234, the mobile phone can assume that the log name corresponding to the log file 1 is log_id_main.
[0162] It can be understood that, since the above log file may include multiple sub-log structures, the log file obtained after log reorganization may also include multiple new sub-log structures (new_iovec). Fig.15 As shown, it can be seen from the above that nr represents the total number of sub-log structures in the log file, that is, the nr corresponding to the log file 1234 is 5. Among them, new_iovec[0] is the first new sub-log structure (or called the new head sub-structure), new_iovec[1] is the second new sub-log structure, and new_iovec[nr-1] is the last new sub-log structure, that is, the fifth new sub-log structure. Among them, the new head sub-structure includes the log name, the number of log repetitions and the timestamp linked list. Afterwards, the other new sub-structures corresponding to each reorganized log file correspond to a structure type respectively, that is, new_iovec[1] corresponds to the process number / thread number of the log file, new_iovec[2] corresponds to the log priority of the log file, new_iovec[3] corresponds to the log tag of the log file, and new_iovec[4] corresponds to the log content of the log file. For example, taking the above-mentioned log file 1234 as an example, the new_iovec[0] corresponding to the log file 1234 includes "[×4][14:50:02.411][14:50:02.411][14:50:02.411]", the new_iovec[1] corresponding to the log file 1234 includes "2662 / 6377", the new_iovec[2] corresponding to the log file 1234 includes "I", the new_iovec[3] corresponding to the log file 1234 includes "PCUtils", and the new_iovec[4] corresponding to the log file 1234 includes "IS_ASSIST_MODE is:false".
[0163] In another example, if Fig.16 As shown in the figure, taking 6 log files as an example, the log information corresponding to log file a is "06-2811:24:18.036 1746 1746E SurfaceFlinger:checkFrameMiss ADD 1.reason:!Composite", the log information corresponding to log file b is "06-28 11:24:18.227 1672 1672EHW_DISPLAY:get_cative_panel:index:0", the log information corresponding to log file c is "06-28 11:24:18.24517461746E SurfaceFlinger:checkFrameMiss ADD 1.reason:!Composite", and the log information corresponding to log file d is "06-28 11:24:18.436 1672 1672E HW_DISPLAY:get_cative_panel:index:0", the log information corresponding to log file e is "06-28 11:24:18.452 1746 1746E SurfaceFlinger:checkFrameMiss ADD 1.reason:! Composite", and the log information corresponding to log file f is "06-28 11:24:18.645 1672 1672EHW_DISPLAY:get_cative_panel:index:0". It can be seen from these 6 log files that the log information corresponding to log files a, log files c and log files e are the same except for the timestamp, and the log information corresponding to log files b, log files d and log files f are the same except for the timestamp. Therefore, the mobile phone can merge log files a, log files c and log files e to obtain log file ace. At the same time, the mobile phone can merge log files b, log files d and log files f to obtain log file bdf. Among them, the log information corresponding to the log file ace is "11:24:18.036 1746 1746E SurfaceFlinger:checkFrameMiss ADD 1.reason:!Composite[×3][11:24:18.245][11:24:18.452]", and the log information corresponding to the log file bdf is "06-28 11:24:18.227 1672 1672E HW_DISPLAY:get_cative_panel:index:0[×3][11:24:18.436][11:24:18.645]".
[0164] For example, Fig.17 As shown, if the cache area includes log file A, log file B and log file C, and the log information corresponding to log file D obtained by the mobile phone is "06-14 14:50:02.421 2953629536IBaseActivity:onCreateCommon", it means that the log information corresponding to the log file D and the log file B in the cache area are the same except for the timestamp. Therefore, the mobile phone can merge the log file D with the log file B in the cache area to obtain the log file BD, wherein the log information corresponding to the log file BD becomes "06-14 14:50:02.42029536 29536I BaseActivity:onCreateCommon[×2][14:50:02.421]". It should be noted that the log files in the cache area that have different log information from the log file keep the original log information, that is, the mobile phone will not Fig.17 The log information corresponding to log file A and log file C in the log file A and log file C are changed.
[0165] In some embodiments, after the above log file is reorganized with the first log file, the mobile phone can refresh the timer, that is, obtain the current time, and determine the current time as the storage time of the log file, that is, the time corresponding to when the log file is stored in the cache area. Afterwards, the mobile phone can encapsulate the log structure corresponding to the reorganized log file (or the new log file) to obtain the log cache entity corresponding to the new log file. For example, see Fig.15 , the mobile phone can encapsulate new_iovec[0], new_iovec[1], new_iovec[2], ..., new_iovec[nr-1] to obtain the log cache entity (logCache_iovec[0]) corresponding to the log file.
[0166] In one implementation, after determining that there is a log file with the same log content as the log file corresponding to the above log file in the cache area, the mobile phone can use the target memory algorithm to process the log files in the cache area to obtain the target cache area. The target memory algorithm is the least recently used (LRU) algorithm, which is to give priority to deleting log files with earlier storage time according to the storage time of the memory files when the memory space is insufficient.
[0167] Specifically, the mobile phone can obtain the storage time of each log file in the cache area. After that, the mobile phone can delete the log file with the earliest storage time and add the log file obtained by the mobile phone to the cache area to ensure that the log in the cache area is the most recently generated log file.
[0168] S804, the mobile phone adds the above log file to the above cache area.
[0169] Specifically, after determining that there is no log file with the same log content as the log file in the cache area, the mobile phone can directly add the log file to the cache area without reorganizing the log file with the log files in the cache area.
[0170] Exemplarily, the cache area includes the above Figure 5 Taking log file A and log file B in as an example, if the log content corresponding to the log file obtained by the mobile phone is "06-14 14:50:02.420 29536 29536I BaseActivity:addWindowFlags", it means that the log file is different from the log file in the cache area. Therefore, the mobile phone can add the log file to the cache area, that is, the log file is log file C in the cache area.
[0171] In some embodiments, after adding the above log file to the cache area, the mobile phone can refresh the timer, that is, obtain the current time, and determine the current time as the storage time of the log file. Afterwards, the mobile phone can encapsulate the log structure corresponding to the log file to obtain the log cache entity corresponding to the log file.
[0172] S805, the mobile phone determines whether there is a log file in the cache area whose log cache time exceeds the preset cache time.
[0173] In some embodiments, after obtaining the log file, the mobile phone can determine whether there is a log file in the above-mentioned cache area whose log cache time exceeds the preset cache time, wherein the log file whose log cache time exceeds the preset cache time refers to the cache time corresponding to the log file with the earliest storage time. If there is a log file in the cache area whose log cache time exceeds the preset cache time, it indicates that the log file is stored in the cache area for a long time. Therefore, in order to avoid the situation where the log cannot be analyzed in time due to the long log storage time, the mobile phone can execute S806 to further determine whether the log file needs to be compressed. If there is no log file in the cache area whose log cache time exceeds the preset cache time, it indicates that the log file in the cache area is stored in the cache area for a short time, and the mobile phone can return to execute S801 to continue waiting for the upper application process to send the log file.
[0174] In one implementation, since the timer starts counting when the cache area is configured and the first log file is received, the mobile phone can determine whether the log file needs to be further compressed according to whether the cache time of the cache pool reaches the preset cache time. The cache time refers to the time between the time when the cache pool is initialized and the current time. The initialized cache pool includes the first initialization and the initialization after each log structure in the cache pool is written to the socket buffer, that is, the reconfigured cache pool.
[0175] Specifically, if the cache time of the cache pool reaches the preset cache time, it indicates that the log file is stored in the cache area for a long time. Therefore, in order to avoid the situation where the log cannot be analyzed in time due to the long log storage time, the mobile phone can execute S806 to further determine whether the log file needs to be compressed. If the cache time of the cache pool does not reach the preset cache time, it indicates that the log file in the cache area is stored in the cache area for a short time. The mobile phone can return to execute S801 to continue waiting for the upper application process to send the log file.
[0176] S806, the mobile phone determines whether the log cache capacity corresponding to the above cache area exceeds the preset cache capacity.
[0177] In some embodiments, after determining that there are log files in the cache area whose log cache time exceeds the preset cache time, the mobile phone can further determine whether the log cache capacity corresponding to the cache area exceeds the preset cache capacity, wherein the log cache capacity corresponding to the cache area refers to the data volume of all log structures in the cache area. If the log cache capacity corresponding to the cache area exceeds the preset cache capacity, it indicates that there is no remaining memory space in the cache area. Therefore, in order to avoid the loss of subsequent log files, the mobile phone can execute S809. If the log cache capacity corresponding to the cache area does not exceed the preset cache capacity, it indicates that although there is a log file timeout in the cache area, there is still free memory space. Therefore, in order for the non-blocking socket buffer to be able to store more log files, the mobile phone can execute S807.
[0178] S807, the mobile phone determines whether there is a log file in the buffer area whose log length is less than the preset log length.
[0179] In some embodiments, after determining that the log cache capacity corresponding to the cache area does not exceed the preset cache capacity, the mobile phone can determine whether there is a log file with a log length less than the preset log length in the above-mentioned cache area. If there is a log file with a log length less than the preset log length in the cache area, it indicates that there is a short log in the cache area. Therefore, in order to improve the log storage efficiency of the socket buffer, the mobile phone can execute S808. If there is no log file with a log length less than the preset log length in the cache area, that is, the log lengths corresponding to all log files in the cache area are not less than the preset log length, it indicates that the log files in the cache area are all long logs. Therefore, the mobile phone does not need to merge the log files in the cache area, that is, the mobile phone can execute S809.
[0180] Specifically, the mobile phone can determine the log length of each log file in the cache area, starting from the log file with the earliest storage time, according to the storage time corresponding to each log file, and judge whether the log length of the log file is greater than the preset log length. The log length refers to the number of character strings corresponding to the log file.
[0181] In one implementation, the mobile phone can determine the arrangement order of the log files by sorting the storage time corresponding to each log file in the cache area according to a preset order. The preset order can be an arrangement order from large to small, or an arrangement order from small to large, and is not specifically limited. Afterwards, the mobile phone can determine the log length of the log file in turn according to the arrangement order of the log files. Exemplarily, if the preset order is an arrangement order from large to small, it means that the storage time corresponding to the log file located at the first position is the earliest, so the mobile phone can determine the log length corresponding to the log file located at the first position. If the preset order is an arrangement order from small to large, it means that the storage time corresponding to the log file located at the final position is the earliest, so the mobile phone can determine the log length corresponding to the log file located at the final position.
[0182] In some embodiments, the mobile phone may not execute the above S806, that is, the above preset cache information only includes the preset cache time, and the mobile phone only needs to determine whether there is a log file in the above cache area whose log cache time exceeds the preset cache time. If there is a log file in the cache area whose log cache time exceeds the preset cache time, the mobile phone can directly execute S807. If there is no log file in the cache area whose log cache time exceeds the preset cache time, the mobile phone can return to execute S801 to continue waiting for the upper-layer application or process to send the log file.
[0183] S808: The mobile phone merges the log file whose log length is less than the preset log length with the second log file to obtain a target log file.
[0184] The second log file is the next log file after the log file whose log length is less than the preset log length. It can be understood that if the first log file is the last log file in the cache area, the second log file is the log file acquired by the mobile phone next time; if the first log file is not the last log file in the cache area, the second log file is the next log file in the cache area after the first log file.
[0185] In some embodiments, after determining that there is a log file with a log length less than a preset log length in the above-mentioned cache area, the mobile phone can merge the log file with a log length less than the preset log length (or referred to as a third log file) with the second log file. Wherein, log merging refers to adding the log content in the second log file that is different from the third log file to the third log file, that is, integrating the log content in the second log file into the third log file to form a long log. In this way, multiple short log files can be merged into a long log file, which can not only improve the log aggregation while saving mobile phone storage resources, reduce the probability of log loss, but also reduce the situation where IO resources are consumed due to sending log files to the socket buffer multiple times, and improve the calling frequency of IO resources.
[0186] Specifically, the mobile phone can determine the first log file in the cache area whose log length is less than the preset log length as the third log file. Afterwards, the mobile phone can merge the third log file with the second log file to obtain a merged log file (or candidate log file). Afterwards, the mobile phone can continue to determine whether the log length corresponding to the merged log file is less than the preset log length. If the log length corresponding to the merged log file is not less than the preset log length, the mobile phone can directly determine the merged log file as the target log file. If the log length corresponding to the merged log file is still less than the preset log length, the mobile phone can determine the merged log file as the third log file, and return to the above-mentioned step of "merging the third log file with the second log file to obtain the merged log file" until the log length corresponding to the merged log file is not less than the preset log length, and the mobile phone can determine the merged log file as the target log file.
[0187] Afterwards, the mobile phone can continue to determine whether there are log files with a log length less than the preset log length in the cache area. If there are still log files with a log length less than the preset log length in the cache area, the mobile phone can continue to merge the log file with the corresponding second log file until the log lengths corresponding to the log files in the cache area are all less than the preset log length. The mobile phone can determine that all log files in the cache area are target log files. It can be understood that the log length corresponding to the target log file is not less than the preset log length.
[0188] In one example, the buffer area includes Fig.18 Taking the three log files in as an example, if log file A is the third log file, that is, log file A is a short log, and log file B is the second log file mentioned above, the mobile phone can merge log file A and log file B to obtain a merged log file (or candidate log file), that is, log file AB. Specifically, since the log content corresponding to log file A includes "06-14 14:50:02.4192953629536I BaseActivity:onCreate", and the log content corresponding to log file B includes "06-14 14:50:02.420 2953629536I BaseActivity:onCreateCommon", the mobile phone can determine that the log information in log file B is different from the log information in log file A, that is, the mobile phone can add the timestamp and log information in log file B to log file A to obtain log file AB, wherein the log content corresponding to log file AB includes "06-1414:50:02.419 29536 29536I BaseActivity:onCreate[14:50:02.420]onCreateCommon".
[0189] It can be understood that after log file A and log file B are merged, the cache area only includes log file AB and log file C. In other words, the mobile phone still needs to continue to determine whether the log length corresponding to log file AB is less than the preset log length. If the log length corresponding to log file AB is still less than the preset log length, it indicates that the merged log file is still a short log. Therefore, the mobile phone can continue to merge log file AB with the above-mentioned log file C to obtain log file ABC, wherein the log content corresponding to log file ABC includes "06-14 14:50:02.419 2953629536IBaseActivity:onCreate[14:50:02.420]onCreateCommon[14:50:02.420]addWindowFlags".
[0190] If the log length corresponding to the above-mentioned log file AB is not less than the preset log length, it indicates that the log file AB is a long log. Therefore, the mobile phone can continue to determine whether the log length corresponding to the above-mentioned log file C is less than the preset log length. If the log length corresponding to the log file C is less than the preset log length, it indicates that the log file C is a short log. Therefore, the mobile phone can merge the log file C with the next log file stored in the cache area; if the log length corresponding to the log file C is not less than the preset log length, the mobile phone can determine that the log file AB and the log file C are the target log files.
[0191] In another example, the buffer area includes Fig.19 Taking the three log files in as an example, if log file AD is the third log file, that is, log file AD is a short log, and log file B is the second log file mentioned above, the mobile phone can merge log file AD with log file B to obtain a merged log file (or candidate log file), that is, log file ADB. Specifically, since the log content corresponding to the log file AD includes "06-14 14:50:02.41929536 29536I BaseActivity:onCreate[×2][14:50:02.421]", and the log content corresponding to the log file B includes "06-14 14:50:02.420 29536 29536I BaseActivity:onCreateCommon", the mobile phone can determine that the log information in the log file B is different from the log information in the log file AD, that is, the mobile phone can add the timestamp and log information in the log file B to the log file AD to obtain the log file ADB, wherein the log content corresponding to the log file ADB includes "06-14 14:50:02.419 29536 29536IBaseActivity:onCreate[×2][14:50:02.421][14:50:02.420]onCreateCommon".
[0192] In some embodiments, if the log length of the third log structure is less than the preset log length, the mobile phone can merge the third log structure with one or more fourth log structures until the merged log length is greater than or equal to the preset log length, and the log structure greater than or equal to the preset log length is determined as the log structure corresponding to the target log file. Wherein, the third log structure is any log structure in the cache area that is not written to the socket buffer. The fourth log structure is a log structure located after the third log structure and / or not written to the socket buffer.
[0193] It should be noted that, in the present embodiment, the mobile phone only performs log merging for log files with different timestamps and / or log contents, but in other embodiments, the mobile phone can perform log merging for log files with different member variables in the log information except the process number / thread number, without specific limitation.
[0194] In one implementation, after determining that there is a log file in the cache area whose log cache time exceeds the preset cache time, the mobile phone may not execute the above-mentioned judgment process S806 to S808, that is, the mobile phone can directly execute S809 to send the log file in the cache area to the non-blocking socket buffer.
[0195] S809: The mobile phone determines the log file in the above buffer area as the target log file.
[0196] Specifically, after determining that there is no log file with a log length less than a preset log length in the cache area, the mobile phone can directly determine all log files in the cache area as target log files.
[0197] In certain embodiments, after determining that there is no log file whose log length is less than the preset log length in the above-mentioned buffer area, the mobile phone can also compress the log file with high log priority according to the log priority corresponding to the log file in the buffer area, and / or, the mobile phone can also compress the log file with maximum log flow according to the log flow corresponding to the log file in the buffer area, and obtain the target log file. That is to say, in this application, not only can the repeated log files and the log files with less character amount be compressed, but also the log files with higher log priority and the log files with larger log flow can be compressed, so that the aggregation degree of the log file can be improved to the greatest extent, the waste of storage resources can be reduced, and the storage efficiency of the socket buffer can be improved.
[0198] In some other embodiments, if the log length of the third log structure is greater than or equal to the preset log length, the mobile phone may determine the third log structure as the log structure corresponding to the target log file.
[0199] In one implementation, after updating the cache area, the mobile phone may not execute the judgment process of S805 to S809, that is, after determining whether the log file is a duplicate log, the mobile phone may directly execute S810 to send the log file to the non-blocking socket buffer; or the mobile phone may return to execute S801 to continue waiting for the upper-layer application or process to send the log file. Among them, updating the cache area refers to the process in which the mobile phone adds the above log file to the cache area and obtains a new log file.
[0200] In another implementation, the mobile phone may not execute the above S805, that is, the above preset cache information only includes the preset cache capacity, and the mobile phone only needs to determine whether the log cache capacity corresponding to the above cache area exceeds the preset cache capacity. If the log cache capacity corresponding to the cache area exceeds the preset cache capacity, the mobile phone may execute S809. If the log cache capacity corresponding to the cache area does not exceed the preset cache capacity, the mobile phone may execute S807.
[0201] S810, the mobile phone sends all target log files in the above buffer area to the socket buffer.
[0202] Specifically, after determining the target log file, the mobile phone can directly send all the target log files in the cache area to the socket buffer, wherein the socket buffer is a non-blocking socket buffer, and the socket buffer is used to store the log files. In this way, it can provide a basis for the subsequent log files obtained by the mobile phone to be stored in the cache area.
[0203] In some embodiments, after sending the target log file, the mobile phone can reset the buffer area and the timer, providing a basis for the subsequent buffer area to store log files. It is understandable that in the process of reconfiguring the buffer area, the buffer area does not contain log files, that is, the buffer area is empty.
[0204] In other embodiments, when the logd module in the mobile phone detects that the socket buffer includes the target log file, the log buffer in the logd module receives the log files in the socket buffer in sequence. Afterwards, the logd module can parse the received log file to restore the reconstructed log file to obtain an initial log structure, wherein the initial log structure is a log structure generated by the first application and without log merging, that is, the structure corresponding to the mobile phone when obtaining the log file, so that the subsequent analysis of the log file can be facilitated, thereby improving the efficiency of log analysis.
[0205] It is understandable that the process of resetting the cache area and the timer by the mobile phone and the process of receiving the target log file by the logd module can be performed simultaneously, one after another, or one of them can be selected, without specific limitation.
[0206] An embodiment of the present application also provides a computer-readable storage medium, which includes computer instructions. When the computer instructions are executed on the above-mentioned electronic device, the electronic device executes each function or step in the above-mentioned method embodiment.
[0207] The embodiment of the present application also provides a computer program product, including a computer program. When the computer program runs on an electronic device, the electronic device executes each function or step in the above method embodiment.
[0208] The embodiment of the present application provides a chip, the chip is used to execute instructions, when the chip is running, the technical solution in the above embodiment is executed. The implementation principle and technical effect are similar, and will not be repeated here.
[0209] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (eg, a floppy disk, a hard disk, a magnetic tape), an optical medium (eg, a high-density digital video disc (DVD)), or a semiconductor medium (eg, a solid state disk (SSD)).
[0210] It should be understood that the "embodiment" mentioned throughout the specification means that the specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, the various embodiments in the entire specification do not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in various embodiments of the present application, the size of the sequence number of the above-mentioned processes does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application.
[0211] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software 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.
[0212] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0213] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0214] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0215] 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.
[0216] 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 all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.
[0217] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application shall be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
Claims
1. A log management method, characterized in that: Applied to an electronic device, wherein a first application is installed in the electronic device, the method comprises: Receive a log structure sent by a log driver, where the log structure is a structure corresponding to a log file generated by the first application; If the log information of the first log structure is the same as the log information of the second log structure in the buffer pool, the timestamp of the first log structure is added to the second log structure to obtain a merged second log structure; wherein the first log structure is any log structure issued by the log driver, the second log structure is any log structure in the buffer pool, and the log information includes all contents in the log structure except the timestamp; If the log information of the first log structure is different from the log information of all log structures in the buffer pool, storing the first log structure in the buffer pool; wherein, during the configuration of the buffer pool, the buffer pool does not contain a log structure; When a preset condition is met, a plurality of log structures in the cache pool are written into a socket buffer, and the socket buffer is used for the electronic device to read and write log files to a log recording module.
2. The method according to claim 1, characterized in that The preset conditions include: The cache duration of the cache pool reaches a preset cache time; and / or, The data volume of all log structures in the cache pool reaches a preset data volume.
3. The method according to claim 1 or 2, characterized in that: The multiple log structures are stored in the cache pool according to a preset order; Writing the multiple log structures in the cache pool into the socket buffer includes: If the log length of the third log structure is greater than or equal to the preset log length, writing the third log structure into the socket buffer; If the log length of the third log structure is less than the preset log length, merge the third log structure with one or more fourth log structures until the merged log length is greater than or equal to the preset log length, and write the merged log structure into the socket buffer; The third log structure is any log structure among the multiple log structures that is not written into the socket buffer, and the fourth log structure is a log structure that is located after the third log structure and is not written into the socket buffer.
4. The method according to claim 3, characterized in that: The merging of the third log structure with one or more fourth log structures comprises: The content of the one or more fourth log structures that is different from the third log structure is merged into the third log structure.
5. The method according to any one of claims 1 to 4, characterized in that After writing the multiple log structures in the cache pool into the socket buffer, the method further includes: The cache pool is reconfigured according to preset cache information; wherein the preset cache information includes a preset cache time and / or a preset data volume.
6. The method according to claim 5, characterized in that The method further comprises: In the case where the preset cache information includes a preset cache time, the timer is reconfigured; wherein the timer is used to record the time when the log file is stored in the cache pool.
7. The method according to any one of claims 1 to 6, characterized in that After receiving the log structure sent by the log driver, the method further includes: In the case where the first application is an application that sends a log file for the first time, the cache pool is initialized and configured according to preset cache information; wherein the preset cache information includes a preset cache time and / or a preset data volume.
8. The method according to any one of claims 1 to 7, characterized in that The method further comprises: Send the log structure in the socket buffer to the log recording module; The log structure received by the log recording module is restored to obtain an initial log structure; wherein the initial log structure is a structure corresponding to a log file generated by the first application and not subjected to log merging.
9. An electronic device, characterized in that: The electronic device includes a memory and one or more processors; the memory and the processor are coupled; the memory is used to store computer program code, and the computer program code includes computer instructions; when the processor executes the computer instructions, the electronic device executes the method as described in any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that: The method comprises computer instructions, which, when executed on an electronic device, cause the electronic device to execute the method as claimed in any one of claims 1 to 8.
Citation Information
Patent Citations
Dialog management method and device
CN105049260A
Expression recommendation model training and expression recommendation methods and devices, apparatus, and medium
CN109034203A
Filtering method and device for eliminating repeated log records
CN110019064A
System log security detection method and device, electronic equipment and storage medium
CN116305290A
Parallelized redo-only logging and recovery for highly available main memory database systems
US20030061537A1