Log storage method and device, electronic equipment and storage medium
By establishing the mapping relationship between the target memory buffer and the target disk space in the Android system, the problem of log loss in the Android system is solved, and the persistence and security of the log are achieved.
Patent Information
- Application Number
- CN202411380486.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-29
- Publication Date
- 2025-01-24
Smart Images

Figure CN119356601A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a log storage method and device, an electronic device, and a storage medium. Background Art
[0002] In software systems, logs play a vital role. Logs can record information related to the system's operating status and are important data for abnormal diagnosis and repair, system performance analysis, and security maintenance.
[0003] However, the native log framework logd of the Android system has the problem of log loss. Due to the limited memory space for log storage in the logd process, the communication failure between the log printing process and the logd process, or the log saving frequency is too frequent and is folded by the system, all logs may not be saved. Especially when key logs are lost, it may cause serious security risks.
[0004] In view of this, it is necessary to provide a log storage method to solve the problem of log loss in the Android system. Summary of the invention
[0005] The embodiments of the present application provide a log storage method and device, an electronic device, and a storage medium, which can solve the problem of log loss.
[0006] In a first aspect, an embodiment of the present application provides a log storage method, which is applied to a server process and is characterized in that it includes: receiving a log write request sent by a client process; determining a target memory buffer corresponding to the log; and writing the content of the log into the corresponding target memory buffer, wherein a mapping relationship exists between the target memory buffer and a target disk space, and the mapping relationship includes corresponding an address of the target memory buffer to an address in the target disk space.
[0007] In some implementations, the server process includes a specific memory space; and determining a target memory buffer corresponding to the log includes determining the target memory buffer in the specific memory space according to a target type of the log.
[0008] In some implementations, the target type includes: a network log, a Bluetooth log, a multimedia log, a battery status log, and at least one of a system log, wherein the system log includes: a kernel log, an application unresponsiveness log, a program crash log, and at least one of an event log.
[0009] In some implementations, the method further includes: when a preset write condition is met, writing the content in the target memory buffer into the target disk space.
[0010] In some implementations, the write condition includes at least one of the following: a preset time interval, insufficient device memory, and device shutdown, wherein the device includes a device running the server process.
[0011] In some implementations, when the device where the server process is located is started, the data in the target disk space is backed up.
[0012] In some implementations, the log is associated with system abnormality diagnosis and / or repair functions.
[0013] In some implementations, the method further includes: receiving a log reading request sent by the client process, the log reading request including at least a target type; determining the target disk space corresponding to the target type based on the log reading request; and determining that a target log file in the target disk space has undergone circular replication, copying the target log file to a target directory, or determining that a target log file in the target disk space has not undergone circular replication, copying the target log file and a copy of the target log file to the target directory.
[0014] In a second aspect, an embodiment of the present application provides a log storage device, characterized in that it is applied to an Android device, and the device includes:
[0015] An acquisition module, used for receiving a log writing request sent by the client process;
[0016] A determination module, used to determine a target memory buffer corresponding to the log;
[0017] A writing module is used to write the content of the log into the corresponding target memory buffer, wherein there is a mapping relationship between the target memory buffer and the target disk space, and the mapping relationship includes corresponding the address of the target memory buffer to the address in the target disk space.
[0018] In a third aspect, an embodiment of the present application provides an electronic device, characterized in that it includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, it implements the steps in the method described in the first aspect and the second aspect.
[0019] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the steps in the method described in the first aspect and the second aspect are implemented.
[0020] In summary, the embodiments of the present application disclose a log storage method and device, an electronic device, and a storage medium. The log storage method includes: receiving a log write request sent by a client process; determining a target memory buffer corresponding to the log; and writing the content of the log into the corresponding target memory buffer, wherein a mapping relationship exists between the target memory buffer and the target disk space, and the mapping relationship includes corresponding the address of the target memory buffer to the address in the target disk space. By establishing a mapping relationship between the target memory buffer and the target disk space, the log can be saved in the disk when needed, thereby solving the problem of easy loss of the log. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of this specification, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0022] Figure 1 A schematic diagram showing a log storage method executed by an electronic device provided in an embodiment of the present application is shown;
[0023] Figure 2 A flow chart of a log storage method provided by an embodiment of the present application is shown;
[0024] Figure 3 A schematic diagram of a log storage method according to another embodiment of the present invention is shown;
[0025] Figure 4 A schematic diagram of a log storage method according to another embodiment of the present invention is shown;
[0026] Figure 5 A schematic diagram of the structure of a log storage device provided by an embodiment of the present application is shown;
[0027] Figure 6 A schematic diagram showing the structure of an electronic device provided by an embodiment of the present application is shown; and
[0028] Figure 7 A schematic structural diagram of an electronic device provided in another embodiment of the present application is shown. DETAILED DESCRIPTION
[0029] The following will be combined with the drawings in this application to clearly and completely describe the technical solutions in this application. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. Based on the embodiments in the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0030] The embodiments of the present application provide a log storage method and device, an electronic device and a storage medium. Specifically, the embodiments of the present application provide log reading and writing suitable for electronic devices. The electronic device includes, but is not limited to, a mobile device, a network device, a medical device, an Internet of Things device, and the like. In some embodiments, the mobile device may be a personal computer, a smart phone, a tablet computer, a game console, and the like. In some embodiments, the network device may be a server, a router, a switch, a firewall, and other network infrastructure devices. In some embodiments, the medical device may be a monitor, an MRI scanner, a ventilator, and other detection or treatment instruments. In some embodiments, the Internet of Things device may include smart home devices, smart wearable devices, robots, smart assembly lines, and other devices in various fields of home, industry, city, and transportation.
[0031] In electronic devices, a log is a file or data structure that records system, application, or hardware activities and events. These records contain detailed information about the device's operation, such as operation time, executed commands, error messages, warnings, status changes, and various performance indicators. Regardless of the type of electronic device, the log system plays an important role in system or application status monitoring, network security monitoring, system performance, and abnormal risk detection.
[0032] The electronic device provided in the embodiment of the present application can be an electronic device based on the Android system. The native log system logd in the Android system stores the log in the memory during the log saving process. Since the memory space for storing logs in the logd process is limited, many old logs are discarded. The cross-process communication between the socket that sends the log from the printing log process to the logd process fails; or when the frequency of log saving is too frequent and exceeds the threshold, it may be folded by the system, resulting in the log being unable to be saved in the memory. In short, the native log storage system of the Android system may have log storage anomalies. If important logs are lost, the system's abnormal diagnosis and repair will face a situation where no logs are available. Therefore, the embodiment of the present application provides a log storage method that can solve the problem of log loss, especially the loss of key logs.
[0033] Figure 1The electronic device 100 includes a server process 101 , a client process 102 and a target disk space 103 .
[0034] The server process 101 and the client process 102 may be based on a CS (Client-Server) architecture. The client process 102 may send a request to the server process 101. The server process 101 may respond to the request of the client process 102 and provide corresponding services to the client process 102. For example, Figure 1 As shown in , the client process 102 sends a log writing request, and the server process 101 provides a log writing service to the client process 102. The server process 101 can open up memory space, such as Figure 1 As shown, the server process 101 may include a target memory buffer 1011. The target memory buffer 1011 may be used for writing logs.
[0035] Among them, the target disk space 103 can be a mechanical hard disk, a solid-state hard disk or other types of disks, and the specific type of the disk is not limited in this application. As mentioned above, the server process 101 includes a target memory buffer 1011. There is a mapping relationship between the target buffer 1011 and the target disk space 103, and the mapping relationship includes corresponding the address of the target memory buffer 1011 to the address in the target disk space 103. The electronic device 100 writes the log to the target memory buffer 1011 when executing the log storage method. Since there is a mapping relationship between the target memory buffer 1011 and the target disk space 103, the modification of the target memory buffer 1011 can be reflected in the target disk space 103 through the mapping relationship. Therefore, the electronic device 100 provided in this embodiment can operate the target memory buffer 1011 when writing logs, without the need to directly write files to the target disk space 103 frequently, avoiding the system overhead caused by a large number of I / O operations. In addition, even if the target memory buffer 1011 loses data due to power failure or data overflow, resulting in loss of log data in the memory, the target disk space 103 can save the log data in the target memory buffer 1011 based on the mapping relationship.
[0036] Specifically, Figure 1 As shown, the specific execution process of the server process 101 executing the log storage method is as follows: the server process 101 receives the log write request sent by the client process 102, determines the target memory buffer 1011 corresponding to the log according to the log write request, and writes the content of the log into the corresponding target memory buffer 1011, wherein there is a mapping relationship between the target memory buffer 1011 and the target disk space 103.
[0037] In summary, the electronic device 100 provided in the embodiment of the present application can save logs on the disk when needed based on the mapping relationship between the target memory buffer 1011 and the target disk space 103, thereby solving the log loss problem mentioned above.
[0038] In other embodiments, when the electronic device 100 is started, the data in the target disk space 103 can be backed up so that the previous log content can be used in system abnormality diagnosis, repair or other tasks. The electronic device 100 will continue to generate new log content during the operation process after one startup. If the log is cyclically copied, it means that the time between the current log and the log backed up at startup is very long or the difference is very large, and the backup log is not very meaningful for the current abnormality diagnosis and other tasks; on the contrary, if the log is not cyclically copied, it means that the time between the two versions of the log is not long and the difference is not very large, which has a certain reference significance for the current abnormality diagnosis and other tasks. Therefore, the electronic device 100 provided in this embodiment determines whether the target log file in the target disk space 103 is cyclically copied. If cyclically copied, the target log file is copied, otherwise, the target log file and the copy of the target log file are copied.
[0039] In addition, since the electronic device 100 in this embodiment can save the log to the target disk space 103, even if a system abnormality occurs and the electronic device 100 cannot be turned on, there is still a way to read the data in the target disk space 103. For example, a disk data reading tool is used to extract the original data in the disk to form an image file, and then the image file is decrypted into a readable file to obtain the specific content of the log.
[0040] In summary, the server process 101 of the electronic device 100 provided in the embodiment of the present application can read log files from the target disk space 103, and because the target disk space 103 stores backup files of the target log files, more versions of log information can be provided according to task requirements.
[0041] The log storage method is described in detail below. It should be noted that the description order of the following embodiments is not intended to limit the priority order of the embodiments.
[0042] Figure 2 A flow chart of a log storage method provided by an embodiment of the present application is shown. Although a logical order is shown in the flow chart, in some cases, the steps shown or described may be performed in an order different from that shown in the accompanying drawings. Specifically, the log storage method is applied to the server process 101, and the specific process of the log storage method is as follows:
[0043] S110 : Receive a log writing request sent by the client process 102 .
[0044] The client process 102 may be various processes in the electronic device 100. For example, the client process 102 may be processes of various applications, such as processes of video playback applications, processes of Bluetooth connection applications, etc. For example, the client process 102 may also be processes related to system performance monitoring, such as resource monitor processes, event viewer processes, etc.
[0045] The client process 102 and the server process 101 can communicate with each other through various methods, and the specific method of the inter-process communication is not limited in this application. The client process 102 can send a request to write a log to the server process 101, and in some embodiments, the request can be sent through a socket. After the server process 101 accepts the request of the client process 102, the server process 101 establishes a connection with the client process 102, and can receive the log data transmitted by the client process 102 through the socket.
[0046] In some applications, due to the limitation of system socket resource management, the client process 102 may fail to send a socket to the server process 101. In the log storage method provided in the embodiment of the present application, the success rate of socket sending can be improved by increasing the number of retries after the socket sending fails or delaying the sending and other retry strategies.
[0047] S120, determine the target memory buffer 1011 corresponding to the log.
[0048] The server process 101 may allocate a specific memory area for temporarily storing logs, and the memory area may include multiple memory buffers. The server process 101 may determine the target memory buffer 1011 corresponding to the log according to a preset rule.
[0049] S130 , writing the content of the log into the corresponding target memory buffer 1011 .
[0050] Among them, there is a mapping relationship between the target memory buffer 1011 and the target disk space 103, and the mapping relationship includes corresponding the address of the target memory buffer 1011 to the address in the target disk space 103. For example, the method can use MMAP (Memory-Mapped Files) technology to establish a mapping relationship between the target memory buffer 1011 and the target disk space 103. Other technologies for establishing a mapping relationship can also be used to establish a mapping relationship between the target memory buffer 1011 and the target disk space 103. This application does not limit the technology for establishing a mapping relationship. The establishment of the mapping relationship between the target memory buffer 1101 and the target disk 103 can occur at any time after the server process 101 opens up a specific memory area and before operation S130.
[0051] In the log storage method provided by the embodiment of the present application, the server process 101 can temporarily store the log in the target memory buffer 1011 when writing the log, without the need to directly write the file frequently to the target disk space 103, thereby avoiding the system overhead caused by a large number of I / O operations. In addition, even if the data in the target memory buffer 1011 is lost due to power failure or data overflow, etc., resulting in the loss of log data in the memory, the target disk space 103 can save the log data in the target memory buffer 1011 based on the mapping relationship. Therefore, the log storage method provided by the embodiment of the present application can effectively solve the problem of log loss while avoiding the decline of system performance.
[0052] In some embodiments, the server process 101 includes a specific memory space. As described above, the server process 101 can open up a specific memory space for temporarily storing logs. The specific memory space can be divided into different memory buffers to store logs of different types or sources. On the one hand, the size, read and write speed, and storage strategy of each memory buffer can be managed and optimized in a targeted manner, thereby reducing resource competition and improving overall processing efficiency. For example, high-priority logs can be given a larger memory buffer or a faster processing priority to ensure the immediate processing of critical information. On the one hand, as the complexity of the system increases, new log types may continue to appear. By designing a flexible multi-buffer architecture, it is not necessary to significantly modify the existing system when adding new log categories, thereby ensuring the scalability of the system. On the other hand, classifying and storing logs helps with future retrieval and analysis. For example, when it is necessary to troubleshoot a problem with a specific module or service, the relevant memory buffer can be directly queried without screening in a large number of mixed logs, thereby improving the efficiency of problem location.
[0053] In step S120 , determining a target memory buffer corresponding to the log may include: determining a target memory buffer 1011 in a specific memory space according to a target type of the log.
[0054] The target type of the log can be determined in a variety of ways. For example, when the client process 102 sends a log write request, the log type information can be included in the request to determine the target type of the log. For example, a label or identifier is attached to the log to distinguish the source or category of the log, thereby determining the target type of the log. For another example, the target type of the log can be determined based on the format or structure of the log.
[0055] Among them, the target type can be at least one of a network log, a Bluetooth log, a multimedia log, a battery status log, and a system log. The network log can record detailed information of the electronic device 100 during the network communication process, including but not limited to connection events, data transmission, network interface failures, network security events, etc. The Bluetooth log can record the behavior information of the electronic device 100 for wireless communication via Bluetooth, including but not limited to pairing and connection conditions, data transmission details, Bluetooth connection error logs, energy consumption information, etc. The multimedia log tracks the activity information of the electronic device 100 related to audio, video, recording and encoding and decoding, including but not limited to playback records, resource usage, encoding and decoding parameters, hardware interaction records, etc. The battery status log can record information related to the battery performance and status of the electronic device 100, including but not limited to power changes, charging events, battery health, power management, etc. The system log can record various activity information at the system level of the electronic device 100, including but not limited to at least one of the kernel log, application unresponsive log, program crash log, and event log.
[0056] As mentioned above, the specific memory space of the server process 101 may include multiple memory buffers corresponding to the types of logs, and the multiple memory buffers include the target memory buffer 1011. The correspondence between different target types and different memory buffers may be preset. The server process 101 determines the target memory buffer 1011 according to the correspondence between the log type and the memory buffer.
[0057] The log storage method provided in the embodiment of the present application can store logs generated during the operation of the electronic device 100, including but not limited to the important logs of the above-mentioned target types. These logs are associated with the system abnormality diagnosis and / or repair functions. The method stores key logs to avoid writing all logs to disk, which causes excessive storage pressure on the system. The method of saving key logs to disk strikes a balance between storage resources and system security performance.
[0058] Figure 3 A flow chart of a log storage method provided by another embodiment of the present application is shown. In some embodiments, the log storage method may also include:
[0059] S140 . When a preset writing condition is met, the content in the target memory buffer 1011 is written into the target disk space 103 .
[0060] As mentioned above, the log can be temporarily stored in the target memory buffer 1011, and the log is written to the target disk space 103 when the preset writing condition is met, thereby avoiding frequent real-time writing of the log to the target disk space 103 and reducing the overhead of system I / O operations.
[0061] Wherein, the writing condition may include at least one of the following: a preset time interval, insufficient device memory, and device shutdown, wherein the device includes an electronic device 100 running a server process 101. For example, when the memory of the electronic device 100 is insufficient, in order to ensure the normal operation of the electronic device 100, the system kernel needs to release part of the memory usage. The electronic device 100 can write the content of the target memory buffer 1011 to the target disk space 103 according to the instruction of the system kernel. For another example, when the electronic device 100 is shut down, the system kernel will check whether there is data in the memory that needs to be saved. Since there is a mapping relationship between the target memory buffer 1011 and the target disk space 103, when the electronic device 100 is shut down, the content of the target memory buffer 1011 can be written to the target disk space 103 according to the instruction of the system kernel.
[0062] In some embodiments, when the device where the server process 101 is located is started, the data in the target disk space 103 is backed up. After the device is turned on, the logs in the memory buffer are lost due to power failure, and the memory stores the newly generated logs after this startup. If the newly generated logs are written to the disk, the previously stored logs in the disk will be overwritten. When the electronic device 100 needs to use the logs before the power failure for abnormal diagnosis and repair, if the previous logs are not backed up, once the disk data is overwritten, the previous log data cannot be retrieved. Therefore, when the device 100 is started, the method backs up the data in the target disk space 103 so that the previous log content can be used in system abnormality diagnosis, repair or other tasks.
[0063] The backup files of the data in the target disk space 103 may be stored in other spaces in the disk outside the target disk space 103. For example, the electronic device 100 may include a specific disk space for storing the backup log files. The specific disk space may be divided into multiple parts corresponding to different types of log files.
[0064] In some embodiments, after the content in the target memory buffer 1011 is written into the target disk space 103 , the log may be read from the target disk space 103 . Figure 4A flow chart of a log storage method provided by another embodiment of the present application is shown. Although a logical order is shown in the flow chart, in some cases, the steps shown or described may be performed in an order different from that shown in the accompanying drawings. After operation S140, the log storage method may further include:
[0065] S210: Receive a log reading request sent by the client process 102, where the log reading request at least includes a target type.
[0066] Among them, the client process 102 and the server process 101 can perform inter-process communication in various ways, and the specific method of inter-process communication is not limited in this application. The client process 102 can send a request to read the log to the server process 101, and in some embodiments, the request can be sent through a socket. After the server process 101 accepts the request of the client process 102, the server process 101 establishes a connection with the client process 102, and can transmit the target log data to the client process 102 through the socket.
[0067] In some applications, due to the limitation of system socket resource management, the client process 102 may fail to send a socket to the server process 101. In the log storage method provided in the embodiment of the present application, the success rate of socket sending can be improved by increasing the number of retries after the socket sending fails or delaying the sending and other retry strategies.
[0068] The target type is the type of log that the client process 102 requests to read. The log reading request includes the target type. After receiving the log reading request, the server process 101 obtains the target type. In some embodiments, the target type can be at least one of a network log, a Bluetooth log, a multimedia log, a battery status log, and a system log.
[0069] S220 . Determine a target disk space 103 corresponding to the target type based on the log read request.
[0070] There is a mapping relationship between the target disk space 103 and the target memory buffer 1011 of the server process 101, and the target memory buffer 1011 is used to write the target log file. In some embodiments, when a preset writing condition is met, the target log file is written from the target memory buffer 1011 to the target disk space 103.
[0071] In some embodiments, different memory buffers are allocated for different types of logs. As mentioned above, storing different types of logs in multiple different memory buffers is of great significance for resource management, system scalability, and log retrieval and analysis. Different target types correspond to different target memory buffers 1011, and different target types correspond to different target disk spaces 103. The method can determine the target disk space 103 corresponding to the target class according to a preset corresponding rule.
[0072] S231, determine that the target log file in the target disk space 103 has been cyclically copied, and copy the target log file to the target directory. Or
[0073] S233: Determine that no circular duplication occurs to the target log file in the target disk space 103, and copy the target log file and the copy of the target log file to the target directory.
[0074] Among them, circular replication is a strategy for controlling the size of log files, which can be implemented in a variety of ways, and different implementations may correspond to different ways of judging whether circular replication occurs. For example, in some implementations, when the log reaches a preset length, the old log is cleared and the new log content is rewritten. For another example, in some implementations, the log file is managed in a first-in-first-out manner. When the log reaches a preset length, the old log content is continuously squeezed out and the new log content is added from the end.
[0075] The target directory may be a log storage directory specified when the client process 102 sends a log reading request.
[0076] The copy of the target file may be a file that backs up the log file in the target disk space 103 after the device is turned on.
[0077] In summary, the log storage method provided in the embodiment of the present application can read logs from the target disk space 103, and there is a mapping relationship between the target disk space 103 and the target memory buffer 1011. Therefore, in the case where the target memory buffer loses data due to power failure of the memory, the method can also read data from the target disk space 103. Furthermore, even if the electronic device 100 cannot be turned on normally, since the log files are stored in the target disk space 103, the disk data tool can be used to export the data to the disk.
[0078] Figure 5 The structure diagram of the log storage device provided by an embodiment of the present application is shown. The log storage device 200 is applied to an Android device, and can be specifically as follows:
[0079] The acquisition module 201 is used to receive a log writing request sent by the client process 102 .
[0080] The determination module 202 is used to determine the target memory buffer 1011 corresponding to the log.
[0081] The writing module 203 is used to write the log content into the corresponding target memory buffer 1011 , wherein the target memory buffer 1011 and the target disk space 103 have a mapping relationship, and the mapping relationship includes corresponding the address of the target memory buffer 1011 to the address in the target disk space 103 .
[0082] The log storage device 200 of this embodiment first receives a log write request by the acquisition module 201, then the determination module 202 determines the target memory buffer 1011 corresponding to the log, and finally the writing module 203 writes the log content into the corresponding target memory buffer 1011. The log storage device 200 provided by this embodiment can effectively solve the problem of log loss while avoiding the degradation of system performance.
[0083] In some embodiments, the determination module 202 determines a target memory buffer in a specific memory space of the server process according to a target type of the log.
[0084] In some embodiments, the writing module 203 writes the content in the target memory buffer 1011 to the target disk space 103 when a preset writing condition is met.
[0085] In some embodiments, the log storage device 200 further includes a backup module. When the electronic device 100 is started, the data in the target disk space 103 is backed up.
[0086] Figure 6 FIG. 1 is a schematic diagram showing the structure of an electronic device provided by an embodiment of the present application. Figure 6 As shown, the client process can call the write log interface in the HeraeyeAPI interface library to send a request to write a log to the server Heserver. The interface for writing a log request can be LOG361D() implemented in C++ language or Log361.d() implemented in Java language. The client process can send the log to be written to the server Heserver through a socket. The electronic device 100 can increase the probability of successful socket sending by increasing the number of socket failure retries.
[0087] like Figure 6As shown, the process of the server Heserver includes a memory buffer, and the memory buffer allocates separate buffer areas for different types of logs. The log types in the electronic device 100 include WiFilog, Medialog, BTlog, Perflog, and Audiolog. The memory buffer has a mapping relationship with part of area A in the kfault partition of the eMMC. This mapping relationship can be achieved through MMAP technology. The kfault partition of the eMMC can also include area B for backing up log files. When the electronic device 100 is turned on, the log files in area A can be copied to the backup area B.
[0088] Taking the log type requested to be written by the client process as Perflog (system performance log) as an example, after receiving the write Perflog log request from the client process, the server Heserver process determines the target memory buffer in the memory buffer corresponding to the Perflog type, and writes the log data into the memory buffer corresponding to Perflog. When the preset writing conditions are met, for example, the preset time interval is met, the electronic device 100 has insufficient memory, or the electronic device 100 is shut down, the Perflog data in the target memory buffer is written into the corresponding target disk space in area A, and the target log file Perflog.txt is obtained.
[0089] Continue to refer Figure 6 The client process can call the log reading interface in the HeraeyeAPI interface library to send a log reading request to the server Heserver. The log reading request interface can be READLOG361() implemented in C++ or readLog361() implemented in Java.
[0090] When the server-side Heserver process receives the Perflog log read request from the client process, it determines the target disk space corresponding to the Perflog type and determines whether the Perflog.txt file has been cyclically copied. If it is determined that a circular copy has occurred, the Perflog.txt file is copied to the target disk partition; otherwise, the Perflog.txt file and Copy_Perflog.txt are copied to the target disk partition.
[0091] The electronic device 100 stores the log in the kfault partition of the eMMC, so the log will not be lost when the power is off. Even if the system abnormality causes the electronic device 100 to fail to boot, a special tool can be used to extract the data in the kfault partition of the eMMC into an image file (such as a file in .img format), and the image file can be decrypted into a readable file to obtain the log content.
[0092] In addition, the present application also provides an electronic device, Figure 7 The structure diagram of the electronic device 100 provided in the embodiment of the present application is shown. Specifically:
[0093] The electronic device 100 may include one or more processors 601 of processing cores, one or more computer-readable storage media memories 602 and other components. Those skilled in the art will appreciate that Figure 7 The electronic device structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0094] The processor 601 is the control center of the electronic device 100. It uses various interfaces and lines to connect various parts of the entire electronic device 100. By running or executing software programs and / or modules stored in the memory 602, and calling data stored in the memory 602, it performs various functions of the electronic device and processes data, thereby monitoring the electronic device 100 as a whole. Optionally, the processor 601 may include one or more processing cores; preferably, the processor 601 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, etc., and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 601.
[0095] The memory 602 can be used to store software programs and modules. The processor 601 executes various functional applications and data processing by running the software programs and modules stored in the memory 602. The memory 602 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function, etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 602 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, or other volatile solid-state storage devices. Accordingly, the memory 602 may also include a memory controller to provide the processor 601 with access to the memory 602.
[0096] Specifically in this embodiment, the processor 601 in the electronic device will load the executable files corresponding to the processes of one or more applications into the memory 602 according to the following instructions, and the processor 601 will run the applications stored in the memory 602, thereby implementing the steps in any log storage method provided in the embodiments of the present application.
[0097] The specific process of the electronic device 100 executing the log storage method can be referred to Figure 1 The description in , this application will not be repeated here.
[0098] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0099] To this end, the present application provides a computer-readable storage medium, on which a computer program is stored. The computer program can be loaded by a processor to execute the steps in any log storage method provided in the present application.
[0100] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0101] The computer-readable storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0102] Since the instructions stored in the computer-readable storage medium can execute the steps in any log storage method provided in the present application, the beneficial effects that can be achieved by any log storage method provided in the present application can be achieved. Please refer to the previous embodiments for details, which will not be repeated here.
[0103] The above is a detailed introduction to a log storage method and device, an electronic device and a storage medium provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as limiting the present invention.
Claims
1. A log storage method, applied to a server process, characterized in that: include: Receive log writing requests sent by the client process; Determine a target memory buffer corresponding to the log according to the log writing request; as well as The content of the log is written into the corresponding target memory buffer, wherein there is a mapping relationship between the target memory buffer and the target disk space, and the mapping relationship includes corresponding the address of the target memory buffer to the address in the target disk space.
2. The method according to claim 1, characterized in that The server process includes a specific memory space; The determining the target memory buffer corresponding to the log includes: determining the target memory buffer in the specific memory space according to the target type of the log.
3. The method according to claim 1, characterized in that in, The target types include: At least one of a network log, a Bluetooth log, a multimedia log, a battery status log, and a system log, wherein: The system log includes at least one of a kernel log, an application unresponsiveness log, a program crash log, and an event log.
4. The method according to claim 1, characterized in that Also includes: When a preset writing condition is met, the content in the target memory buffer is written into the target disk space.
5. The method of claim 4, wherein: The write condition includes at least one of the following: A preset time interval, insufficient device memory, and device shutdown, wherein the device includes a device running the server process.
6. The method according to claim 4, characterized in that When the device where the server process is located is started, the data in the target disk space is backed up.
7. The method according to claim 1, wherein the log is associated with system abnormality diagnosis and / or repair functions.
8. The method according to claim 1, characterized in that The method further comprises: Receiving a log reading request sent by the client process, wherein the log reading request includes at least a target type; Based on the log read request, determining the target disk space corresponding to the target type; and Determine that the target log file in the target disk space has been cyclically copied, and copy the target log file to the target directory, or Determine that no circular duplication occurs to the target log file in the target disk space, and copy the target log file and the copy of the target log file to the target directory.
9. A log storage device, characterized in that: Applied to an Android device, the device comprises: An acquisition module, used for receiving a log writing request sent by the client process; A determination module, used to determine a target memory buffer corresponding to the log; A writing module is used to write the content of the log into the corresponding target memory buffer, wherein there is a mapping relationship between the target memory buffer and the target disk space, and the mapping relationship includes corresponding the address of the target memory buffer to the address in the target disk space.
10. An electronic device, characterized in that: The method comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps in the method according to any one of claims 1 to 8 when executing the computer program.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the method according to any one of claims 1 to 8 are implemented.