Log processing method and device

By determining the target buffer pool based on the remaining space of the log buffer pool in a small memory embedded device and writing to the log, the problem of slower program running speed and timing competition caused by log printing is solved, and the program function abnormality or crash is achieved Effective location and log security.

CN119046047APending Publication Date: 2024-11-29ZHEJIANG DAHUA TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411191719.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-27
Publication Date
2024-11-29

AI Technical Summary

Technical Problem

Small memory embedded devices have slower program running speed due to adding log printing, and there is less time-series competition, so they cannot reproduce program function abnormalities or crash problems caused by time-series competition.

Method used

When the target program is running, the target buffer pool is determined based on the remaining memory space and required memory space of the log buffer pool, and the logs are written to the buffer pool; when the program is abnormal, the logs in each log buffer pool are read and written to The object file to determine the cause of the exception.

Benefits of technology

By monitoring system signals, effectively locate program function abnormalities or crash problems, avoiding the slower program running speed and timing competition caused by log printing, ensuring the security and stability of system logs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119046047A_ABST
    Figure CN119046047A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a log processing method and device.The method comprises the steps that when a target program runs, a first log generated when the target program runs is received at the first moment, and the memory space occupied by the first log is the first memory space; under the condition that the log buffer pool operated at the first moment is the first buffer pool in the multiple log buffer pools, determining a target buffer pool in the multiple log buffer pools according to the remaining memory space of the first buffer pool and the first memory space; writing the first log into a target buffer pool; when it is monitored that the target program is abnormal at a second moment, logs stored in the log buffer pools are read from the log buffer pools, the read logs are written into the target file, the abnormal reason of the target program is determined through the logs in the target file, and the second moment is a moment after the first moment. The target file is stored in a fixed disk of the small-memory embedded device.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the computer field, and in particular, to a method and device for processing logs. Background Art

[0002] Small memory embedded devices refer to embedded devices with small memory capacity. Due to the characteristics of low power consumption, small size and low cost, such devices are usually used in some simple application scenarios or resource-limited environments, such as smart home devices, sensor nodes, IoT devices, embedded controllers and other applications that do not require high performance but need to run for a long time.

[0003] The systems of small memory embedded devices are usually tailored and may not support the generation of core files or debugging with the GNU debugger (gdb). You can only troubleshoot program crashes by adding log printing. However, after adding a large number of logs, IO operations are frequent, the program runs slower, timing competition is reduced, and the race condition cannot be met, making it impossible to reproduce program function anomalies or crashes caused by timing competition.

[0004] There is currently no effective solution to the above problems. Summary of the invention

[0005] The embodiments of the present invention provide a method and device for processing logs, so as to at least solve the problem in the related art that the program running speed of a small memory embedded device slows down due to the addition of log printing, there is less timing competition, and the program function abnormality or crash caused by timing competition cannot be reproduced.

[0006] According to one embodiment of the present invention, a method for processing logs is provided, which is applied to a small memory embedded device, comprising: when a target program is running, receiving a first log when the target program is running at a first moment, wherein the memory space occupied by the first log is the first memory space; when the log buffer pool operated at the first moment is the first buffer pool among multiple log buffer pools, determining a target buffer pool among the multiple log buffer pools according to the remaining memory space of the first buffer pool and the first memory space, wherein the log buffer pool is a temporary memory of the small memory embedded device; writing the first log to the target buffer pool; when an exception is detected in the target program at a second moment, reading the logs stored in each of the multiple log buffer pools, and writing the read logs to a target file, so as to determine the cause of the exception of the target program through the log in the target file, wherein the second moment is a moment after the first moment, and the target file is stored on a fixed disk of the small memory embedded device.

[0007] In an exemplary embodiment, when the log buffer pool operated at the first moment is the first buffer pool among multiple log buffer pools, a target buffer pool is determined among the multiple log buffer pools based on the remaining memory space of the first buffer pool and the first memory space, including: when the remaining memory space of the first buffer pool is greater than or equal to the first memory space, the first buffer pool is determined as the target buffer pool; when the remaining memory space of the first buffer pool is less than the first memory space, a second buffer pool among the multiple log buffer pools that is adjacent to the first buffer pool and is sorted after the first buffer pool is determined as the target buffer pool, wherein the multiple log buffer pools are arranged in order.

[0008] In an exemplary embodiment, writing the first log to the target buffer pool includes: when the target buffer pool is the first buffer pool, directly writing the first log to the first buffer pool; when the target buffer pool is the second buffer pool, after performing a zeroing operation on the second buffer pool, writing the first log to the second buffer pool.

[0009] In an exemplary embodiment, after receiving a first log when the target program is running at a first moment, the method further includes: determining a log buffer pool pointed to by a target pointer in the multiple log buffer pools at the first moment as the first buffer pool; when the remaining memory space of the first buffer pool is less than the first memory space, after determining a second buffer pool in the multiple log buffer pools that is adjacent to the first buffer pool and sorted after the first buffer pool as the target buffer pool, the method further includes: moving the target pointer to point the target pointer to the second buffer pool.

[0010] In an exemplary embodiment, when an exception is detected in the target program at the second moment, the logs stored in each of the multiple log buffer pools are read, and the read logs are written to the target file, so as to determine the cause of the exception of the target program through the logs in the target file, including: obtaining a moving sequence table of the target pointer, wherein the target pointer moves according to the arrangement order of the multiple log buffer pools, and each time the target pointer moves, the sequence number of the log buffer pool currently pointed to is recorded in the moving sequence table; and the logs stored in each of the multiple log buffer pools are read according to the moving sequence table.

[0011] In an exemplary embodiment, logs stored in each log buffer pool are read from the multiple log buffer pools according to the moving sequence table, including: when the moving sequence table is the sequence number of the log buffer pool according to the moving sequence of the target pointer from front to back, the sequence numbers of the log buffer pools are read from the moving sequence table in sequence from back to front, and logs are read from the log buffer pools corresponding to the sequence numbers of the log buffer pools in sequence.

[0012] In an exemplary embodiment, when an exception is detected in the target program at the second moment, logs stored in each log buffer pool are read from the multiple log buffer pools, including: determining the log buffer pool pointed to by the target pointer in the multiple log buffer pools at the second moment as the third buffer pool, and reading the logs in the third buffer pool and the buffer pool before the third buffer pool in the order in which the multiple log buffer pools are arranged.

[0013] According to another embodiment of the present invention, a device for processing logs is provided, comprising: a receiving module, for receiving, at a first moment when a target program is running, a first log of the target program when the target program is running, wherein the memory space occupied by the first log is the first memory space; a first determining module, for determining a target buffer pool among the multiple log buffer pools according to the remaining memory space of the first buffer pool and the first memory space when the log buffer pool operated at the first moment is the first buffer pool among multiple log buffer pools, wherein the log buffer pool is a temporary memory of the small memory embedded device; a writing module, for writing the first log to the target buffer pool; a second determining module, for reading the logs stored in each of the multiple log buffer pools when an exception is detected in the target program at a second moment, and writing the read logs to a target file, so as to determine the cause of the exception of the target program through the log in the target file, wherein the second moment is a moment after the first moment, and the target file is stored on a fixed disk of the small memory embedded device.

[0014] According to yet another embodiment of the present invention, a computer-readable storage medium is provided, wherein a computer program is stored in the computer-readable storage medium, wherein the computer program implements the steps of any of the above methods when executed by a processor.

[0015] According to yet another embodiment of the present invention, there is provided an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0016] According to yet another embodiment of the present invention, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the steps of any of the above methods are implemented.

[0017] Through the present invention, by monitoring the system signal, before the target program is abnormal, the target buffer pool is determined according to the first memory space occupied by the first log and the remaining space of the first buffer pool, and the first log received at the first moment is written into the target buffer pool; after the target program receives the abnormal signal, the first log is read, and the first file is written into the target file in time, so that the temporary log stored in the log buffer pool is saved as a permanent disk file, thereby determining the abnormal cause of the target program according to the target file, and ensuring the security of the system log. Therefore, the problem that the program running speed of the small memory embedded device in the related art is slowed down due to the addition of log printing, the timing competition is less, and the program function abnormality or crash problem caused by the timing competition cannot be reproduced can be solved, so as to achieve the effect of ensuring the effective positioning of the program function abnormality or crash problem. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 is a hardware structure block diagram of a mobile terminal according to a method for processing logs in an embodiment of the present invention;

[0019] Figure 2 is a flowchart of a method for processing logs according to an embodiment of the present invention;

[0020] Figure 3 is a schematic diagram of the memory structure of a log module according to an embodiment of the present invention;

[0021] Figure 4 is a flowchart of a program for adding a log model according to an embodiment of the present invention;

[0022] Figure 5 is a flow chart of writing logs into a log buffer pool according to an embodiment of the present invention;

[0023] Figure 6 is a flow chart of writing files into the log buffer pool memory according to an embodiment of the present invention;

[0024] Figure 7 4 is a structural block diagram of a device for reading logs according to an embodiment of the present invention. DETAILED DESCRIPTION

[0025] Hereinafter, embodiments of the present invention will be described in detail with reference to the accompanying drawings and in combination with the embodiments.

[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0027] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 FIG. 1 is a hardware structure block diagram of a mobile terminal of a method for processing logs according to an embodiment of the present invention. Figure 1 As shown, the mobile terminal may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the mobile terminal may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the mobile terminal. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.

[0028] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the method for processing logs in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the mobile terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0029] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0030] In this embodiment, a method for processing logs running on the mobile terminal is provided. Figure 2is a flow chart of a method for processing logs according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:

[0031] Step S202, when the target program is running, receiving a first log of the target program at a first moment, wherein the memory space occupied by the first log is a first memory space;

[0032] The target program can be a program running on a small memory embedded device, such as intelligent monitoring, face recognition, voice recognition, music playback, etc. The small memory embedded device can be a smart watch, smart home device, sensor, smart phone, etc.; the first moment can be any moment when the target program is running normally; the first log can be the running log of the target program. By analyzing the running log, it can help developers, system administrators, etc. to find problems in time, optimize performance, and improve stability and security. When the target program is running, the first log of the target program running is received at the first moment, wherein the memory space occupied by the first log is the first memory space.

[0033] Step S204, when the log buffer pool operated at the first moment is the first buffer pool among the multiple log buffer pools, determining a target buffer pool among the multiple log buffer pools according to the remaining memory space of the first buffer pool and the first memory space, wherein the log buffer pool is a temporary memory of the small memory embedded device;

[0034] The above-mentioned log buffer pool can be a log buffer pool of a small-memory embedded device. Since the memory of the embedded device is small, there are only a few log buffer pools (generally preferably two) in the small-memory embedded device, wherein the log buffer pool is mainly used to temporarily store the logs of the target program running, that is, once the program exits or the operating system is restarted, the logs stored in the log buffer pool will be lost; the above-mentioned first buffer pool can be the log buffer pool being operated at the first moment, and the target buffer pool is determined from multiple log buffer pools based on the remaining memory space of the first buffer pool and the first memory space required to be occupied by the first log, wherein the target buffer pool can be the first buffer pool, or it can be other log buffer pools except the first buffer pool among the multiple log buffer pools.

[0035] Specifically, when the remaining memory space of the first buffer pool is greater than or equal to the first memory space, the first buffer pool is determined as the target buffer pool; when the remaining memory space of the first buffer pool is less than the first memory space, a second buffer pool among the multiple log buffer pools that is adjacent to the first buffer pool and is sorted after the first buffer pool is determined as the target buffer pool, wherein the multiple log buffer pools are arranged in order.

[0036] Figure 3 is a schematic diagram of the memory structure of the log module according to an embodiment of the present invention, such as Figure 3 As shown, the log module can contain multiple log buffer pools, and the multiple log buffer pools are arranged in sequence. Take two log buffer pools as an example, where:

[0037] BufferA and bufferB are two log buffer pools of the same size, and the arrangement order from left to right is bufferA, bufferB, where the sizes of bufferA and bufferB are both bufferSize; the pointer variable pBufferA points to bufferA, through which the data in the bufferA log buffer pool can be accessed and operated, and lengthA represents the effective log length in bufferA; the pointer variable pBufferB points to bufferB, through which the data in the bufferB log buffer pool can be accessed and operated, and lengthA represents the effective log length in bufferA; currentBuf refers to the log buffer pool currently being operated, which may be BufferA or BufferB; bufferSize refers to the size of the current log buffer pool, that is, the size of the amount of data that can be accommodated in the current log buffer; logMutex is a thread lock used to control access to logs or log outputs in multi-threaded or concurrent programming. By using logMutex, it can be ensured that only one thread can write to the log at the same time, avoiding the problem of confusion or loss of log content caused by multiple threads writing at the same time, thereby ensuring the integrity and accuracy of log records.

[0038] If the log buffer pool currently (i.e., at the first moment) being operated is bufferA (i.e., the first buffer pool), and if the remaining memory space in bufferA is greater than or equal to the first memory space, bufferA is determined as the target buffer pool; if the remaining memory space in bufferA is less than the first memory space, bufferB is determined as the target buffer pool.

[0039] Step S206, writing the first log into the target buffer pool;

[0040] Specifically, when the target buffer pool is the first buffer pool, the first log is directly written into the first buffer pool; when the target buffer pool is the second buffer pool, the first log is written into the second buffer pool after a zeroing operation is performed on the second buffer pool.

[0041] Step S208, when an exception is detected in the target program at a second moment, the logs stored in each of the multiple log buffer pools are read, and the read logs are written into a target file, so as to determine the cause of the exception of the target program through the logs in the target file, wherein the second moment is a moment after the first moment, and the target file is stored on a fixed disk of the small memory embedded device.

[0042] The second moment is the moment when an exception occurs in the target program, which may be a program function abnormality or freeze, but not a crash, or a program crash; the occurrence of the target program exception can be determined by monitoring program crash signals such as segment error (SIGSEGV), abnormal termination (SIGABRT), floating point exception (SIGFPE), illegal instruction (SIGILL), bus error (SIGBUS), termination signal (SIGTERM), interrupt signal (SIGINT), etc.; the stored log may be a log stored when the target program runs normally; the target file may be a file used to record the target program running log, and the target file may be a disk that is permanently stored The file is stored in the fixed disk of the small memory embedded device; when the target program is running normally (i.e., the first moment), the running log of the target program is obtained, the running log is written into the log buffer pool memory, and the program crash signals such as SIGSEGV, SIGABRT, SIGFPE, SIGILL, SIGBUS, SIGTERM, SIGINT, etc. are monitored through the main thread, and the program crash signal is monitored at the second moment, and it is determined that the target program is abnormal. At this time, the running logs stored in each log buffer pool are read from multiple log buffer pools, and the read running logs are written into the target file, and the abnormal cause of the target program is determined according to the running log recorded in the target file.

[0043] Optionally, when an exception is detected in the target program at the second moment, after reading the logs stored in each log buffer pool in the multiple log buffer pools, the read logs are written to a file, which can be an error log file, used to record error information and abnormal conditions when the program crashes, so that developers can troubleshoot and fix problems. In the case of a functional abnormality or freezing of the program, but not a complete crash, the user terminates the program by pressing ctrl+c, the program will receive a SIGINT signal, and then write the logs stored in the log buffer pool to a file to save the log information during the program operation; in the case of a complete crash of the program, after receiving the abnormal signal, the logs stored in the log buffer pool are written to a file for subsequent troubleshooting, thereby ensuring that the log information when the program is abnormal can be saved, facilitating subsequent troubleshooting and analysis.

[0044] Optionally, the executor of the above steps may be a background processor, or other devices with similar processing capabilities, or a machine that integrates at least an image acquisition device and a data processing device, wherein the image acquisition device may include a graphics acquisition module such as a camera, and the data processing device may include a computer, a mobile phone or other terminal, but is not limited thereto.

[0045] Through the above steps, by monitoring the system signal, the log is first written into the memory buffer pool before the target program is abnormal; after the target program receives the abnormal signal, the previously stored log write error log file (target file) is read in sequence, so that the abnormal cause of the target program can be determined according to the target file, effectively avoiding the slow running speed of the program due to adding log printing, increasing IO operations, etc., less timing competition, and the inability to reproduce the program function abnormality or crash caused by timing competition, reducing the slow running speed of the program, less timing competition, and the inability to reproduce the program function abnormality or crash caused by timing competition, ensuring the number of timing competition, providing reliable data support for subsequent troubleshooting and analysis, and helping to timely discover system failures, performance problems or security vulnerabilities, and then timely repair and optimization. It solves the problem that the program running speed of small memory embedded devices in the related technology is slow, the timing competition is less, and the program function abnormality or crash caused by timing competition cannot be reproduced, achieving the effect of effectively locating the program function abnormality or crash problem, and improving the stability and reliability of the system.

[0046] As an optional implementation, after receiving the first log when the target program is running at the first moment, the method further includes: determining the log buffer pool pointed to by the target pointer in the multiple log buffer pools at the first moment as the first buffer pool; when the remaining memory space of the first buffer pool is less than the first memory space, after determining the second buffer pool in the multiple log buffer pools that is adjacent to the first buffer pool and sorted after the first buffer pool as the target buffer pool, the method further includes: moving the target pointer to point the target pointer to the second buffer pool.

[0047] As an optional implementation, when an exception is detected in the target program at the second moment, the logs stored in each log buffer pool are read from the multiple log buffer pools to determine the cause of the exception of the target program through the logs stored in each log buffer pool, including: obtaining a moving sequence table of the target pointer, wherein the target pointer moves according to the arrangement order of the multiple log buffer pools, and each time the target pointer moves, the sequence number of the log buffer pool currently pointed to is recorded in the moving sequence table; and the logs stored in each log buffer pool are read from the multiple log buffer pools according to the moving sequence table.

[0048] As an optional implementation, the logs stored in each log buffer pool are read from the multiple log buffer pools according to the moving sequence table, including: when the moving sequence table is the sequence number of the log buffer pool according to the moving sequence of the target pointer from front to back, the sequence numbers of the log buffer pools are read from the moving sequence table in sequence from back to front, and the logs are read from the log buffer pools corresponding to the sequence numbers of the log buffer pools in sequence.

[0049] As an optional implementation, when an exception is detected in the target program at the second moment, the logs stored in each log buffer pool are read from the multiple log buffer pools, including: determining the log buffer pool pointed to by the target pointer in the multiple log buffer pools at the second moment as the third buffer pool, and reading the logs in the third buffer pool and the buffer pool located before the third buffer pool in the order of arrangement of the multiple log buffer pools.

[0050] As an optional implementation, Figure 4 is a flowchart of a program for adding a log model according to an embodiment of the present invention, such as Figure 4 As shown, the specific process is as follows:

[0051] Step S401, initialize the log module, apply for log buffer pool memory according to the preset buffer pool size, wherein the default current memory block currentBuf is bufferA, and write the log length of bufferA and bufferB log buffer pool to zero.

[0052] Step S402: monitor program crash signals such as SIGSEGV, SIGABRT, SIGFPE, SIGILL, SIGBUS, SIGTERM, and SIGINT in the main thread.

[0053] Step S403, running the main program (target program), and writing the important log (first log) into the log buffer pool memory.

[0054] Step S404, after receiving the program crash signal, write the log (first log) in the log buffer pool memory to a file (target file).

[0055] As an optional implementation, Figure 5 is a flow chart of writing logs into a log buffer pool according to an embodiment of the present invention, such as Figure 5 As shown, the specific process is as follows:

[0056] Step S501, before the log (first log) is written into the buffer pool, first determine whether the length of the current written string (first memory space) plus the written length is greater than the preset size of the buffer pool bufferSize, that is, determine whether the first memory space is greater than the remaining memory space of the first buffer pool. If greater, execute step S502, otherwise execute step S503.

[0057] Step S502, clear the write log length of the log buffer pool (second buffer pool) not in the current operation, switch the buffer pool (first buffer pool) in the current operation to another one (target buffer pool), and execute step S503.

[0058] Step S503: write the log into the memory of the buffer pool (target buffer pool) of the current operation, and record the length of the write.

[0059] As an optional implementation, Figure 6 is a flow chart of writing a file into the log buffer pool memory according to an embodiment of the present invention, such as Figure 6 As shown, the specific process is as follows:

[0060] Step S601, determine whether the write length of the memory of the log buffer pool not currently operated (the log buffer pool before the third buffer pool) is greater than 0, if so, execute step S602, otherwise execute step S603.

[0061] Step S602, first write the logs in the memory of the non-current log buffer pool (the log buffer pool before the third buffer pool) into the target file, and then append the logs in the current log buffer pool (the third buffer pool) into the target file.

[0062] Step S603, write the log in the memory of the current log buffer pool (third buffer pool) into the target file.

[0063] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.

[0064] In this embodiment, a device for reading logs is also provided, which is used to implement the above embodiments and preferred implementations, and will not be repeated here. As used below, the term "module" can implement a combination of software and / or hardware for a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0065] Figure 7 is a structural block diagram of a device for reading logs according to an embodiment of the present invention, such as Figure 7 As shown, the device includes: a receiving module 702, which is used to receive a first log of the target program when the target program is running at a first moment, wherein the memory space occupied by the first log is the first memory space; a first determining module 704, which is used to determine a target buffer pool among the multiple log buffer pools according to the remaining memory space of the first buffer pool and the first memory space when the log buffer pool operated at the first moment is the first buffer pool among multiple log buffer pools, wherein the log buffer pool is a temporary memory of the small memory embedded device; a writing module 706, which is used to write the first log to the target buffer pool; a second determining module 708, which is used to read the logs stored in each log buffer pool among the multiple log buffer pools when an exception is detected in the target program at a second moment, and write the read logs to a target file, so as to determine the cause of the exception of the target program through the log in the target file, wherein the second moment is a moment after the first moment, and the target file is stored on a fixed disk of the small memory embedded device.

[0066] In an exemplary embodiment, the device is also used to determine the first buffer pool as the target buffer pool when the remaining memory space of the first buffer pool is greater than or equal to the first memory space; and to determine the second buffer pool among the multiple log buffer pools that is adjacent to the first buffer pool and sorted after the first buffer pool as the target buffer pool when the remaining memory space of the first buffer pool is less than the first memory space, wherein the multiple log buffer pools are arranged in order.

[0067] In an exemplary embodiment, the device is also used to directly write the first log into the first buffer pool when the target buffer pool is the first buffer pool; and to write the first log into the second buffer pool after performing a zeroing operation on the second buffer pool when the target buffer pool is the second buffer pool.

[0068] In an exemplary embodiment, the device is also used to determine the log buffer pool pointed to by the target pointer in the multiple log buffer pools at the first moment as the first buffer pool; when the remaining memory space of the first buffer pool is less than the first memory space, after determining the second buffer pool in the multiple log buffer pools that is adjacent to the first buffer pool and sorted after the first buffer pool as the target buffer pool, move the target pointer and point the target pointer to the second buffer pool.

[0069] In an exemplary embodiment, the device is also used to obtain a moving sequence table of the target pointer, wherein the target pointer moves according to the arrangement order of the multiple log buffer pools, and each time the target pointer moves, the sequence number of the log buffer pool currently pointed to is recorded in the moving sequence table; and the logs stored in each log buffer pool are read from the multiple log buffer pools according to the moving sequence table.

[0070] In an exemplary embodiment, the device is also used to read the sequence numbers of the log buffer pools from the moving sequence table in sequence from back to front, and read logs from the log buffer pools corresponding to the sequence numbers of the log buffer pools in sequence, when the moving sequence table is the sequence number of the log buffer pool according to the moving sequence of the target pointer from front to back.

[0071] In an exemplary embodiment, the device is also used to determine the log buffer pool pointed to by the target pointer in the multiple log buffer pools at the second moment as the third buffer pool, and read the logs in the third buffer pool and the buffer pool located before the third buffer pool according to the arrangement order of the multiple log buffer pools.

[0072] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.

[0073] An embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above methods are implemented.

[0074] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.

[0075] An embodiment of the present invention further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0076] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.

[0077] An embodiment of the present invention further provides a computer program product, including a computer program, which implements the steps of the method described in each embodiment of the present application when executed by a processor.

[0078] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.

[0079] Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order than here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.

[0080] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for processing logs, characterized in that: Applicable to small memory embedded devices, including: When a target program is running, receiving a first log when the target program is running at a first moment, wherein the memory space occupied by the first log is a first memory space; In a case where the log buffer pool operated at the first moment is a first buffer pool among multiple log buffer pools, determining a target buffer pool among the multiple log buffer pools according to the remaining memory space of the first buffer pool and the first memory space, wherein the log buffer pool is a temporary memory of the small memory embedded device; Writing the first log into the target buffer pool; When an exception is detected in the target program at a second moment, the logs stored in each of the multiple log buffer pools are read, and the read logs are written to a target file, so as to determine the cause of the exception of the target program through the logs in the target file, wherein the second moment is a moment after the first moment, and the target file is stored on a fixed disk of the small memory embedded device.

2. The method according to claim 1, characterized in that In a case where the log buffer pool operated at the first moment is a first buffer pool among multiple log buffer pools, determining a target buffer pool among the multiple log buffer pools according to the remaining memory space of the first buffer pool and the first memory space includes: In a case where the remaining memory space of the first buffer pool is greater than or equal to the first memory space, determining the first buffer pool as the target buffer pool; When the remaining memory space of the first buffer pool is smaller than the first memory space, a second buffer pool adjacent to the first buffer pool and sorted after the first buffer pool among the multiple log buffer pools is determined as the target buffer pool, wherein the multiple log buffer pools are arranged in order.

3. The method according to claim 2, characterized in that Writing the first log into the target buffer pool includes: When the target buffer pool is the first buffer pool, directly writing the first log into the first buffer pool; In the case where the target buffer pool is the second buffer pool, after performing a zeroing operation on the second buffer pool, the first log is written into the second buffer pool.

4. The method according to claim 2, characterized in that: After receiving a first log when the target program is running at a first moment, the method further includes: Determine the log buffer pool pointed to by the target pointer in the multiple log buffer pools at the first moment as the first buffer pool; In the case that the remaining memory space of the first buffer pool is smaller than the first memory space, after determining a second buffer pool among the multiple log buffer pools that is adjacent to the first buffer pool and is sorted after the first buffer pool as the target buffer pool, the method further includes: moving the target pointer to point the target pointer to the second buffer pool.

5. The method according to claim 4, characterized in that When an exception occurs in the target program at the second moment, the log stored in each log buffer pool is read from the multiple log buffer pools, and the read log is written into a target file, so as to determine the cause of the exception of the target program through the log in the target file, including: Obtaining a moving sequence table of the target pointer, wherein the target pointer moves according to the arrangement order of the multiple log buffer pools, and each time the target pointer moves, the sequence number of the log buffer pool currently pointed to is recorded in the moving sequence table; The logs stored in each log buffer pool are read from the plurality of log buffer pools according to the movement sequence table.

6. The method according to claim 5, characterized in that Reading logs stored in each log buffer pool in the plurality of log buffer pools according to the movement sequence table includes: In the case where the moving sequence table is the sequence number of the log buffer pool in the order of movement of the target pointer from front to back, the sequence numbers of the log buffer pool are read from the moving sequence table in sequence from back to front, and logs are read from the log buffer pool corresponding to the sequence numbers of the log buffer pool in sequence.

7. The method according to claim 4, characterized in that When an exception is detected in the target program at the second moment, the log stored in each log buffer pool is read from the multiple log buffer pools, including: The log buffer pool pointed to by the target pointer in the multiple log buffer pools at the second moment is determined as the third buffer pool, and the logs in the third buffer pool and the buffer pool before the third buffer pool are read according to the arrangement order of the multiple log buffer pools.

8. A device for processing logs, characterized in that: Applicable to small memory embedded devices, including: A receiving module, configured to receive, at a first moment when a target program is running, a first log when the target program is running, wherein the memory space occupied by the first log is a first memory space; A first determination module, configured to determine a target buffer pool among the multiple log buffer pools according to a remaining memory space of the first buffer pool and the first memory space when the log buffer pool operated at the first moment is a first buffer pool among the multiple log buffer pools, wherein the log buffer pool is a temporary memory of the small memory embedded device; A writing module, used for writing the first log into the target buffer pool; The second determination module is used to read the logs stored in each of the multiple log buffer pools when an exception is detected in the target program at a second moment, and write the read logs into a target file, so as to determine the cause of the exception of the target program through the logs in the target file, wherein the second moment is a moment after the first moment, and the target file is stored on a fixed disk of the small memory embedded device.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program implements the steps of the method described in any one of claims 1 to 7 when executed by a processor.

10. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to perform the method according to any one of claims 1 to 7.