Log storage method, device, electronic device and storage medium for small system
By introducing log crawling services and log storage methods in electronic devices, the problem of log recording loss when electronic devices are turned on is solved, effective analysis of the causes of abnormalities is achieved, and the reliability of troubleshooting is improved.
Patent Information
- Application Number
- CN202310983455.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-04
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2043-08-04
AI Technical Summary
In the prior art, when abnormalities occur during the electronic device startup process, log records are difficult to save, resulting in difficulty in analyzing problems. Especially when the logo fails to load, there is a lack of an effective measurement mechanism.
Provide a log storage method for small systems. Through the log crawling service, the log interface is called after the small system is started, log data is obtained from the log partition, and stored in the preset storage area different from the log partition according to the preset log category, including Start logs, load logs and operation logs, and use index information and status flag bits to manage storage blocks to achieve circular coverage and dynamic memory storage.
When a small system runs abnormally, log data can be effectively saved for analysis of the causes of the exception, solving the problem of log record loss, and improving the reliability of troubleshooting.
Smart Images

Figure CN117687963B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data storage, and in particular to a log storage method, device, electronic device and storage medium for a small system. Background Art
[0002] When an electronic device has a logo loading exception or displays a red screen during the boot process, the abnormal problem may not be reproduced by restarting and capturing the serial port log, resulting in the loss of maintenance and testing information at the first scene and the inability to analyze the problem; in addition, during the process of loading the image file, if the loading fails, the image loading log record is difficult to save, making it impossible to determine the cause of the loading failure. It can be seen that there is currently a lack of maintenance and testing mechanism for abnormal problems, so a log storage method is urgently needed. Summary of the invention
[0003] The purpose of the embodiments of the present application is to provide a log storage method, device, electronic device and storage medium for a small system to achieve storage of log data. The specific technical solution is as follows:
[0004] In a first aspect, an embodiment of the present application provides a log storage method of a small system, which is applied to an electronic device, wherein the electronic device includes a small system and a log capture service, and the method includes:
[0005] After the mini-system is started, the log capture service calls the log interface of the mini-system to obtain log data from the log partition of the mini-system;
[0006] The log capture service stores the log data in a preset storage area according to a preset log category; wherein the preset storage area is a storage area applied for by the log capture service and is different from the log partition of the small system.
[0007] Optionally, the preset log category includes at least one of a device startup category, an image file loading category, and an operation category for the preset storage area.
[0008] The preset storage area includes at least one of a first log storage area, a second log storage area, and a third log storage area.
[0009] Optionally, the log data includes at least one of a startup log, a loading log, and an operation log, and storing the log data in a preset storage area according to a preset log category includes:
[0010] storing the startup log in the first log storage area, wherein the startup log is a log generated during a normal or abnormal startup process of the electronic device;
[0011] and / or
[0012] storing the loading log in the second log storage area, wherein the loading log is a log generated during the image file loading process;
[0013] and / or
[0014] The operation log is stored in the third log storage area, and the operation log is a log generated when an operation is performed on the preset storage area.
[0015] Optionally, storing the startup log in the first log storage area includes:
[0016] The first log storage area includes a first number of storage blocks;
[0017] Set index information and status flag information;
[0018] Determine the storage block pointed to by the index information, record a startup log in the storage block, and update the status flag information of the storage block to be in use; the initial information of the status flag information of the first number of storage blocks is that they are to be used;
[0019] When the storage block is full, the status flag information of the storage block is updated to be used;
[0020] The index information is pointed to the next storage block of the storage block. If the current storage block is the last storage block, the index information is pointed to the first storage block.
[0021] Optionally, storing the loading log in the second log storage area includes:
[0022] The second log storage area includes at least one storage block; the at least one storage block is divided into a plurality of sub-storage blocks of a preset size;
[0023] storing the loading log in a first sub-storage block among a plurality of sub-storage blocks;
[0024] When the first sub-storage block is full, writing the loading log to the next sub-storage block;
[0025] If the current sub-storage block is the last sub-storage block among the multiple sub-storage blocks, the loading log is written into the first sub-storage block among the multiple sub-storage blocks.
[0026] Optionally, storing the operation log in the third log storage area includes:
[0027] Storing the operation log in a pre-applied dynamic memory;
[0028] The data in the dynamic memory is acquired, and the data is stored in the third log storage area.
[0029] Optionally, storing the operation log in a pre-applied dynamic memory includes:
[0030] If the remaining space of the dynamic memory is not less than the storage space required for the operation log, storing the operation log at the offset position of the dynamic memory;
[0031] If the remaining space of the dynamic memory is smaller than the storage space required for the operation log, the operation log is stored at the starting position of the dynamic memory.
[0032] Optionally, the preset storage area further includes a switch information storage area; the switch information storage area is used to record the activation status of each log storage area;
[0033] When the enabling state of each log storage area is turned on, the step of storing the log data in the preset storage area according to the preset log category is performed.
[0034] Optionally, the preset storage area further includes a header information storage area, and the header information storage area includes header information of the first log storage area, header information of the second log storage area, and header information of the third log storage area.
[0035] In a second aspect, an embodiment of the present application provides a log storage device of a small system, which is applied to an electronic device, wherein the electronic device includes a small system and a log capture service, and the device includes:
[0036] A log data acquisition module, used to call the log interface of the small system and obtain log data from the log partition of the small system;
[0037] The log data storage module is used to store the log data in a preset storage area according to the preset log category; wherein the preset storage area is a storage area applied for by the log capture service and is different from the log partition of the small system.
[0038] Optionally, the preset log category includes at least one of a device startup category, an image file loading category, and an operation category for the preset storage area.
[0039] The preset storage area includes at least one of a first log storage area, a second log storage area, and a third log storage area.
[0040] Optionally, the log data includes at least one of a startup log, a loading log, and an operation log, and the log data storage module includes:
[0041] A first log data storage module, used for storing the startup log in the first log storage area, wherein the startup log is a log generated during a normal or abnormal startup process of the electronic device;
[0042] and / or
[0043] A second log data storage module, used to store the loading log in the second log storage area, where the loading log is a log generated during the image file loading process;
[0044] and / or
[0045] The third log data storage module is used to store the operation log in the third log storage area, where the operation log is a log generated when an operation is performed on the preset storage area.
[0046] Optionally, the first log storage area includes a first number of storage blocks; and the first log data storage module includes:
[0047] Setting module, used to set index information and status flag information;
[0048] a storage block determination module, configured to determine the storage block pointed to by the index information, record a startup log in the storage block, and update the status flag information of the storage block to be in use; the initial information of the status flag information of the first number of storage blocks is that they are to be used;
[0049] A status flag information updating module, used to update the status flag information of the storage block to be used when the storage block is full;
[0050] The index moving module is used to point the index information to the next storage block of the storage block, and if the current storage block is the last storage block, point the index information to the first storage block.
[0051] Optionally, the second log storage area includes at least one storage block; and the second log data storage module includes:
[0052] A storage block division module, used for dividing the at least one storage block into a plurality of sub-storage blocks of a preset size;
[0053] A sub-storage block storage module, used for storing the loading log in a first sub-storage block among a plurality of sub-storage blocks;
[0054] The sub-storage block moving module is used to write the loading log to the next sub-storage block when the first sub-storage block is full; if the current sub-storage block is the last sub-storage block among multiple sub-storage blocks, the loading log is written to the first sub-storage block among the multiple sub-storage blocks.
[0055] Optionally, the third log data storage module includes:
[0056] A dynamic memory storage module, used for storing the operation log in a pre-applied dynamic memory;
[0057] The third log data storage submodule is used to obtain the data in the dynamic memory and store the data in the third log storage area.
[0058] Optionally, the dynamic memory storage module is specifically used for:
[0059] If the remaining space of the dynamic memory is not less than the storage space required for the operation log, storing the operation log at the offset position of the dynamic memory;
[0060] If the remaining space of the dynamic memory is smaller than the storage space required for the operation log, the operation log is stored at the starting position of the dynamic memory.
[0061] Optionally, the preset storage area further includes a switch information storage area; the switch information storage area is used to record the activation status of each log storage area;
[0062] The judgment module is used to trigger the log data storage module when the enabling state of each log storage area is turned on.
[0063] Optionally, the preset storage area further includes a header information storage area, and the header information storage area includes header information of the first log storage area, header information of the second log storage area, and header information of the third log storage area.
[0064] In a third aspect, an embodiment of the present application provides an electronic device, including:
[0065] Memory, used to store computer programs;
[0066] The processor is used to implement the log storage method of any of the above-mentioned small systems when executing the program stored in the memory.
[0067] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the log storage method of any of the above-mentioned small systems is implemented.
[0068] Beneficial effects of the embodiments of the present application:
[0069] The log storage method of the small system provided in the embodiment of the present application is applied to an electronic device, wherein the electronic device includes a small system and a log capture service, and the method includes: after the small system is started, the log capture service calls the log interface of the small system to obtain log data from the log partition of the small system; the log capture service stores the log data in a preset storage area according to a preset log category; wherein the preset storage area is a storage area applied by the log capture service and is different from the log partition of the small system. The present application can save the log data corresponding to the small system when the small system is running, and analyze the cause of the abnormality through the saved log data when the small system runs abnormally. BRIEF DESCRIPTION OF THE DRAWINGS
[0070] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other embodiments can also be obtained based on these drawings.
[0071] Figure 1a A schematic diagram of a first structure of an electronic device provided in an embodiment of the present application;
[0072] Figure 1b A second structural diagram of an electronic device provided in an embodiment of the present application;
[0073] Figure 2 A schematic diagram of a software architecture provided for an embodiment of the present application;
[0074] Figure 3 A schematic diagram of a first flow chart of a log storage method for a small system provided in an embodiment of the present application;
[0075] Figure 4 A second flow chart of the log storage method for a small system provided in an embodiment of the present application;
[0076] Figure 5 A schematic diagram of a process flow for starting a log storage process provided in an embodiment of the present application;
[0077] Figure 6 A schematic diagram of the state information of a storage block provided in an embodiment of the present application;
[0078] Figure 7 A third flow chart of the log storage method for a small system provided in an embodiment of the present application;
[0079] Figure 8 A flow chart of a log storage process for loading provided in an embodiment of the present application;
[0080] Fig. 9 A schematic diagram of a process flow of an operation log storage process provided in an embodiment of the present application;
[0081] Fig.10 Another flowchart of the operation log storage process provided in the embodiment of the present application;
[0082] Fig.11 A schematic diagram of a log storage structure provided in an embodiment of the present application;
[0083] Fig.12 A structural schematic diagram of a log storage device of a small system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0084] In order to better understand the technical solution of the present application, the embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0085] It should be noted that, in this application, words such as "exemplarily" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplarily" or "for example" in this application should not be interpreted as being more optional or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplarily" or "for example" is intended to present related concepts in a specific way.
[0086] First, in a first aspect of an embodiment of the present application, an electronic device is provided, such as Figure 1a As shown, the electronic device includes:
[0087] Memory 101, used for storing computer programs;
[0088] The processor 102 is used to execute the program stored in the memory 101, and implements the following steps:
[0089] After the mini-system is started, the log interface of the mini-system is called to obtain log data from the log partition of the mini-system;
[0090] The log data is stored in a preset storage area according to a preset log category; wherein the preset storage area is a storage area applied for by the log capture service and is different from the log partition of the small system.
[0091] Furthermore, the electronic device may further include a communication bus and / or a communication interface, and the processor 102, the communication interface, and the memory 101 communicate with each other via the communication bus.
[0092] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0093] The communication interface is used for communication between the above electronic device and other devices.
[0094] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0095] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0096] For ease of explanation, a mobile phone is used as an example of an electronic device.
[0097] like Figure 1b As shown, in some embodiments, the electronic device 200 may include a processor 201 and a communication module 202, etc.
[0098] The processor 201 and Figure 1aThe processor 102 may be the same as the processor 101, and may include one or more processing units. For example, the processor 201 may include an application processor (AP), a modem processor, a graphics processor, an image signal processor (ISP), a controller, a memory, a video stream codec, a digital signal processor, a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or may be integrated in one or more processors 201.
[0099] The controller may be the nerve center and command center of the electronic device 200. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.
[0100] The processor 201 may also be provided with a memory for storing instructions and data.
[0101] In some embodiments, the memory in the processor 201 is a cache memory. The memory can store instructions or data that have just been used or cyclically used by the processor 201. If the processor 201 needs to use the instruction or data again, it can be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 201, and thus improves the efficiency of the system.
[0102] In some embodiments, the processor 201 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0103] The communication module 202 may include an antenna 1, an antenna 2, a mobile communication module, and / or a wireless communication module.
[0104] like Figure 1b As shown, in some embodiments, the electronic device 200 may further include an external memory interface 205, an internal memory 204, a USB interface 206, a charging management module 207, a power management module 208, a battery 209, and a sensor module 203, etc.
[0105] NPU is a neural network (NN) computing processor. By drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain, it can quickly process input information and can also continuously self-learn. Through NPU, applications such as intelligent cognition of the electronic device 200 can be realized, such as image recognition, face recognition, voice recognition, text understanding, etc.
[0106] The charging management module 207 is used to receive charging input from a charger, where the charger can be a wireless charger or a wired charger.
[0107] In some wired charging embodiments, the charging management module 207 may receive charging input from a wired charger through the USB interface 206 .
[0108] In some wireless charging embodiments, the charging management module 207 may receive wireless charging input via a wireless charging coil of the electronic device 200. While the charging management module 207 is charging the battery 209, it may also provide power to the electronic device 200 via the power management module 208.
[0109] The power management module 208 is used to connect the battery 209, the charging management module 207 and the processor 201. The power management module 208 receives input from the battery 209 and / or the charging management module 207, and supplies power to the processor 201, the internal memory 204, the external memory, and the communication module 202. The power management module 208 can also be used to monitor parameters such as battery capacity, battery cycle number, and battery health status (leakage, impedance).
[0110] In some other embodiments, the power management module 208 may also be disposed in the processor 201 .
[0111] In other embodiments, the power management module 208 and the charging management module 207 may also be disposed in the same device.
[0112] The external memory interface 205 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 200. The external memory card communicates with the processor 201 through the external memory interface 205 to implement a data storage function. For example, files such as music and video streams are stored in the external memory card.
[0113] The internal memory 204 can be used to store computer executable program codes, and the executable program codes include instructions. The processor 201 executes various functional applications and data processing of the electronic device 200 by running the instructions stored in the internal memory 204. The internal memory 204 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area can store data created during the use of the electronic device 200 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 204 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.
[0114] The sensor module 203 in the electronic device 200 may include image sensors, touch sensors, pressure sensors, gyroscope sensors, air pressure sensors, magnetic sensors, acceleration sensors, distance sensors, proximity light sensors, ambient light sensors, fingerprint sensors, temperature sensors, bone conduction sensors and other components to realize the sensing and / or acquisition functions of different signals.
[0115] Optionally, the electronic device 200 may further include peripheral devices, such as a mouse, buttons, indicator lights, a keyboard, a speaker, a microphone, etc.
[0116] The buttons include a power button, a volume button, etc. The buttons may be mechanical buttons or touch buttons. The electronic device 200 may receive button inputs and generate key signal inputs related to user settings and function controls of the electronic device 200.
[0117] The indicator may be a light indicator, which may be used to indicate the charging status and the change in the power level, and may also be used to indicate messages, missed calls, and notifications, etc.
[0118] It is understandable that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device 200 .
[0119] In other embodiments, the electronic device 200 may include more or fewer components than shown, or combine some components, or separate some components, or arrange the components differently. The components shown may be implemented in hardware, software, or a combination of software and hardware.
[0120] The partition table of the hard disk is the basis for reading and writing data. If there is a problem with the partition table of the device, it cannot be started normally. Since the device cannot be started normally, there is no corresponding log record for analyzing the reason for the failure to start. Similar scenarios also occur during the boot process. If the logo fails to load, or a red screen is displayed when the device is booted, the problem is often confirmed and analyzed by restarting and capturing the serial port log. However, during the process of restarting and capturing the serial port log, the abnormal problem may not reappear, so the log record of the first scene is lost and the problem cannot be analyzed. In the process of loading the image file, if the loading fails, the log at the time of the loading failure is not saved, so the reason for the loading failure cannot be analyzed.
[0121] See also Figure 2 , Figure 2 This is a schematic diagram of the software architecture in this application, including the application layer, framework layer, hardware abstraction layer, kernel layer (for example, Linux kernel layer), and boot loader layer. The application layer may include applications such as calendar, camera, and dialer; the framework layer includes modules such as content providers, managers, and view systems; the hardware abstraction layer includes resources such as audio, Bluetooth, camera, and sensors; the kernel layer includes modules such as audio, display, Bluetooth, camera, USB, WIFI, and test points; and the boot loader layer includes services such as startup mode, kernel startup parameters, quick startup, and block serial number. The log capture service in this application can be in the boot loader layer.
[0122] In order to solve at least one of the above problems, the present application provides a log storage method for a small system, see Figure 3 :
[0123] S301: After the mini-system is started, the log capture service calls the log interface of the mini-system to obtain log data from the log partition of the mini-system.
[0124] The solution of the present application is implemented through an electronic device, which includes a small system and a log capture service. Among them, the log capture service is a service different from the small system. Taking the electronic device as a mobile phone with an Android system installed as an example, the small system can be a boot program for guiding the startup operation of the mobile phone. During the startup process of the mobile phone, the small system will generate a system log for the mobile phone startup and automatically store the system log in the log partition of the small system; the small system can also be an image file loader for loading image files. The small system and the log capture service are two groups of processes in the electronic device. After the small system is started, the electronic device will start the log capture service to call the log interface of the small system and obtain log data from the log partition of the small system.
[0125] S302: The log capture service stores the log data in a preset storage area according to a preset log category.
[0126] The preset storage area is a storage area applied for by the log capture service, which is different from the log partition of the small system. The preset storage area is a raw partition in the electronic device. The raw partition is a special character device file that has not been formatted and is not read by Unix through the file system. The application is responsible for reading and writing it. It does not go through the buffering of the file system. It is a device that is not directly managed by the operating system. This type of device lacks the operating system layer, and the I / O efficiency is higher. Many databases can improve I / O efficiency by using raw devices as storage media.
[0127] The preset log categories include device startup category, image file loading category, and operation category for the preset storage area. For example, the log generated by the device during the startup process belongs to the device startup category log, the log generated when loading the image file belongs to the image file loading category log, and the log generated when writing to the preset storage area belongs to the operation category log.
[0128] After acquiring the log data, the log capture service stores the log data in a preset storage area according to the preset log category. The preset storage area includes at least one of a first log storage area, a second log storage area, and a third log storage area.
[0129] In one embodiment of the present application, storing the log data in a preset storage area according to a preset log category may include the following steps:
[0130] Step 1: storing the startup log in the first log storage area, wherein the startup log is a log generated during a normal or abnormal startup process of a device;
[0131] After the small system guides the electronic device to start up, it will automatically store the startup log generated during the startup process in the log partition of the small system. The log capture service can capture the startup log generated during the device startup process and store it in the first log storage area of the preset storage area. In one example, since the startup log includes both the log generated by the normal startup of the device and the log generated by the abnormal startup of the device, the first log storage area can be further divided into a normal log storage area and an abnormal log storage area, and the log generated during the normal startup of the device is stored in the normal log storage area, and the log generated during the abnormal startup of the device is stored in the abnormal log storage area.
[0132] and / or
[0133] Step 2: storing the loading log in the second log storage area, wherein the loading log is a log generated during the image file loading process;
[0134] When the small system loads the image file, a loading log will be generated accordingly to record the loading process of the image file. The log capture service can obtain the loading log in the log partition of the small system and store it in the second log storage area of the preset storage area. The second log storage area can be the same size as the first log storage area, or smaller than the first log storage area.
[0135] and / or
[0136] Step three: storing the operation log in the third log storage area, wherein the operation log is a log generated when an operation is performed on the preset storage area.
[0137] During the operation process on the preset storage area, such as performing a write operation on the preset storage area, an operation log will also be generated to record the operation performed on the preset storage area. The log capture service can store the operation log in the third log storage area.
[0138] In one example, the preset storage area may include a switch information storage area in addition to the first log storage area, the second log storage area, and the third log storage area. The switch information storage area is used to record the enabled state of each log storage area. For example, when the enabled state of the first log storage area is indicated as enabled, it indicates that the first log storage area supports data reading and writing operations. Optionally, the log capture service can store the startup log in the first log storage area when the first log storage area supports data reading and writing operations. When the enabled state of the second log storage area is indicated as enabled, it indicates that the second log storage area supports data reading and writing operations. Optionally, the log capture service can store the loading log in the second log storage area when the second log storage area supports data reading and writing operations. When the enabled state of the third log storage area is indicated as enabled, it indicates that the third log storage area supports data reading and writing operations. Optionally, the log capture service can store the operation log in the third log storage area when the third log storage area supports data reading and writing operations. The size of the switch information storage area can be set according to experience. In one case, the size of the switch information storage area is 4KB.
[0139] In one example, the preset storage area may also include a header information storage area, and the header information storage area includes header information of the first log storage area, header information of the second log storage area, and header information of the third log storage area. Optionally, the header information of each log storage area is stored in a space of 4KB. Of course, 4KB is a value set based on experience, and the embodiment of the present application does not limit the size of the storage space used to store the header information.
[0140] In one example, the preset storage area may also include a version information storage area for storing version information of the current preset storage area partition scheme. A 4KB space may be applied in the preset storage area to store the version information of the current partition scheme. Of course, 4KB is a value set based on experience, and the embodiment of the present application does not limit the size of the storage space used to store version information.
[0141] In one embodiment of the present application, step 1, storing the startup log in the first log storage area, can be refined into the following steps, see Figure 4 :
[0142] S401: Set index information and status flag information.
[0143] The first log storage area includes a first number of storage blocks; the first number can be set based on experience. Since the startup log is divided into a log generated during the normal startup of the electronic device and a log generated during the abnormal startup of the electronic device, 4 storage blocks can be set for the log generated by the normal startup, and 8 storage blocks can be set for the log generated by the abnormal startup. The index information acts as a pointer to point to a specific storage block, and the status flag information is used to characterize the usage status of each storage block, which is divided into three states: to be used, in use, and already used. The log capture service jointly determines the storage scheme of the startup log based on the index information and the status flag information.
[0144] S402: Determine the storage block pointed to by the index information, record a startup log in the storage block, and update the status flag information of the storage block to be in use.
[0145] The initial information of the status flag information of the first number of storage blocks are all to be used; after determining the storage block pointed to by the index information through the index information, a write operation can be performed on the storage block, specifically, the startup log is stored in the storage block.
[0146] S403: When the storage block is full, update the status flag information of the storage block to be used.
[0147] If the current storage block is full, the status flag information of the current storage block is updated to be used, indicating that the write operation will no longer be performed on the current storage block.
[0148] S404: Point the index information to the next storage block of the storage block. If the current storage block is the last storage block, point the index information to the first storage block.
[0149] The index information is pointed to the next storage block, and a write operation is performed on the storage block pointed to by the index information. However, if the current storage block is already the last storage block in the first log storage area, the index information needs to be pointed to the first storage block, so as to achieve cyclic coverage of log storage.
[0150] In one example, combining Figure 5 A detailed description of the stored procedure for starting the log. Figure 5 It reflects the storage process of the logs generated during the abnormal startup of the electronic device. The normal startup log is also stored in the same way. Please refer to the storage process of the abnormal startup log.
[0151] After the electronic device is turned on, the memory blocks are initialized. The initial information of the status flags of the eight memory blocks in the figure is that they are about to be used. For each memory block, its status flag information will switch between the three states of "about to be used", "in use" and "already used". Figure 6 . Determine the storage block pointed to by the index information, for example, if it is storage block 1, then the status flag information of storage block 1 will be updated to be in use, until storage block 1 is full, its status flag information will be updated to have been used, at this time, it is necessary to point the index information to the next storage block of storage block 1, that is, storage block 2, at this time, the status flag information of storage block 2 will be updated to be in use, until storage block 2 is full, its status flag information will be updated to have been used. If there is a need to continue storing the startup log after storage block 8 is full, the index information needs to be pointed to storage block 1 to achieve log circular overwrite storage.
[0152] Since the present application uses index information and status flag information to jointly determine the storage scheme of the boot log, the storage blocks can be well managed to ensure no waste. If the boot log is called multiple times during the same boot process, determining the storage block based on the index information can ensure that data is updated on the same storage block.
[0153] In one embodiment of the present application, step 2, storing the loading log in the second log storage area, can be refined into the following steps, see Figure 7 :
[0154] S501. The second log storage area includes at least one storage block; the at least one storage block is divided into a plurality of sub-storage blocks of a preset size.
[0155] The amount of log data generated during the image file loading process is much smaller than the amount of data in the startup log, so the second log storage area is set to be smaller than the first log storage area, and includes at least one storage block. The present application divides a storage block into multiple sub-storage blocks for use. The storage of the loading log adopts the ring_buff mechanism, that is, the log generated by each image file loading is limited to 4KB in size, and the loading log is written to the sub-storage block in the form of an offset. The preset size is determined based on the size of the log generated by each loading. When the log generated by each image file loading is limited to 4KB in size, the preset size is also set to 4KB.
[0156] S502: Store the loading log into a first sub-storage block among multiple sub-storage blocks.
[0157] When the loading log starts to be stored, the loading log is stored at the location where the storage block offset is 0, that is, the first sub-storage block.
[0158] S503: When the first sub-storage block is full, write the loading log to the next sub-storage block.
[0159] When the first sub-storage block is full, the offset of the storage block is determined, and the load log is written to the new sub-storage block according to the offset position of the storage block. If the current write operation is to the first sub-storage block, after the first sub-storage block is full, the storage position determined according to the offset is the storage position of the second sub-storage block.
[0160] S504: If the current sub-storage block is the last sub-storage block among the multiple sub-storage blocks, write the loading log into the first sub-storage block among the multiple sub-storage blocks.
[0161] If the sub-storage block used to store the loading log is the last sub-storage block in the second log storage area, the offset needs to be set to 0, the storage location pointed to by the offset is determined, that is, the first sub-storage block, and the loading log is written to the first sub-storage block, thereby realizing the circular overwrite mechanism of the loading log.
[0162] See also Figure 8 , which is a schematic diagram of the above-mentioned loading log storage process. Each sub-storage block (i.e., block in the figure) is used to store a loading log generated once. When the last sub-storage block is full, the loading log to be stored is written into the first sub-storage block.
[0163] In one embodiment of the present application, the above step three, storing the operation log in the third log storage area, can be refined into the following steps, see Fig. 9 :
[0164] S601: Store the operation log into a pre-applied dynamic memory.
[0165] When the electronic device is turned on, a dynamic memory is applied for to dynamically store operation logs. The operation logs are logs generated when operations are performed on the preset storage area.
[0166] If the remaining space of the dynamic memory is not less than the storage space required for the operation log, the operation log is stored at the offset position of the dynamic memory; it can be understood that the offset position refers to the starting position of the available storage space, which is determined by the storage result of the last operation log.
[0167] If the remaining space of the dynamic memory is smaller than the storage space required for the operation log, the operation log is stored at the starting position of the dynamic memory.
[0168] S602: Acquire data in the dynamic memory, and store the data in the third log storage area.
[0169] In one example, combining Fig.10 The storage process of operation logs is described in detail:
[0170] Call the log interface, obtain the operation log, and store the operation log in the pre-applied dynamic memory. Determine whether the dynamic memory can store the operation log based on the offset of the dynamic memory and the data size of the operation log. Specifically, the dynamic memory offset plus the data size of the operation log can be compared with the size of the dynamic memory. If the offset plus the current operation log size is larger than the size of the dynamic memory, the offset is set to 0, and the operation log is stored at the starting position of the dynamic memory according to the position of the offset 0; if the offset plus the current operation log size is not larger than the size of the dynamic memory, the operation log can be stored in the dynamic memory according to the current offset position. Write the data in the dynamic memory to the third log storage area of the preset storage area.
[0171] For an example, see Fig.11 , which is a schematic diagram of the log storage structure provided by this application:
[0172] 0 represents the version information storage area, which is used to store the version information of the current preset storage area partition scheme, with a size of 4KB;
[0173] 1 represents the switch information storage area, which is used to record the enabled status of each log storage area and has a size of 4KB;
[0174] 2 represents the header information of the normal log storage area, with a size of 4KB;
[0175] 3 represents the normal log storage area, which is the storage area corresponding to the logs generated by the normal startup process of the electronic device. The size is 2MB and is divided into 8 sub-areas;
[0176] 4 represents the header information of the abnormal log storage area, with a size of 4KB;
[0177] 5 represents the abnormal log storage area, which is the storage area corresponding to the log generated by the abnormal startup process of the electronic device, with a size of 4MB and divided into 16 sub-areas;
[0178] 6 represents the header information of the second log storage area, with a size of 4KB;
[0179] 7 represents the second log storage area, which is the area corresponding to the logs generated during the image file loading process, and its size is 2MB;
[0180] 8 represents the header information of the third log storage area, with a size of 4 KB;
[0181] 9 represents the third log storage area, which is an area corresponding to the logs generated when the preset storage area is operated, with a size of 128 KB and divided into 2 sub-areas;
[0182] 10 represents the header information of the customized information storage area, with a size of 4KB;
[0183] 11 represents a customized information storage area, for example, it can be used to store the header information of each partition, with a size of 40KB, which is divided into 10 sub-areas;
[0184] 12 represents the area to be expanded.
[0185] The embodiment of the present application also provides a log storage device of a small system, which is applied to an electronic device, wherein the electronic device includes a small system and a log capture service, see Fig.12 , the device comprises:
[0186] The log data acquisition module 701 is used to call the log interface of the small system and obtain log data from the log partition of the small system;
[0187] The log data storage module 702 is used to store the log data in a preset storage area according to a preset log category; wherein the preset storage area is a storage area applied for by the log capture service and is different from the log partition of the small system.
[0188] In one example, the preset log category includes at least one of a device startup category, an image file loading category, and an operation category for the preset storage area.
[0189] The preset storage area includes at least one of a first log storage area, a second log storage area, and a third log storage area.
[0190] In one example, the log data includes at least one of a startup log, a loading log, and an operation log, and the log data storage module includes:
[0191] A first log data storage module, used for storing the startup log in the first log storage area, wherein the startup log is a log generated during a normal or abnormal startup process of the electronic device;
[0192] and / or
[0193] A second log data storage module, used to store the loading log in the second log storage area, where the loading log is a log generated during the image file loading process;
[0194] and / or
[0195] The third log data storage module is used to store the operation log in the third log storage area, where the operation log is a log generated when an operation is performed on the preset storage area.
[0196] In one example, the first log storage area includes a first number of storage blocks; and the first log data storage module includes:
[0197] Setting module, used to set index information and status flag information;
[0198] a storage block determination module, configured to determine the storage block pointed to by the index information, record a startup log in the storage block, and update the status flag information of the storage block to be in use; the initial information of the status flag information of the first number of storage blocks is that they are to be used;
[0199] A status flag information updating module, used to update the status flag information of the storage block to be used when the storage block is full;
[0200] The index moving module is used to point the index information to the next storage block of the storage block, and if the current storage block is the last storage block, point the index information to the first storage block.
[0201] In one example, the second log storage area includes at least one storage block; the second log data storage module includes:
[0202] A storage block division module, used for dividing the at least one storage block into a plurality of sub-storage blocks of a preset size;
[0203] A sub-storage block storage module, used for storing the loading log in a first sub-storage block among a plurality of sub-storage blocks;
[0204] The sub-storage block moving module is used to write the loading log to the next sub-storage block when the first sub-storage block is full; if the current sub-storage block is the last sub-storage block among multiple sub-storage blocks, the loading log is written to the first sub-storage block among the multiple sub-storage blocks.
[0205] In one example, the third log data storage module includes:
[0206] A dynamic memory storage module, used for storing the operation log in a pre-applied dynamic memory;
[0207] The third log data storage submodule is used to obtain the data in the dynamic memory and store the data in the third log storage area.
[0208] In one example, the dynamic memory storage module is specifically used for:
[0209] If the remaining space of the dynamic memory is not less than the storage space required for the operation log, storing the operation log at the offset position of the dynamic memory;
[0210] If the remaining space of the dynamic memory is smaller than the storage space required for the operation log, the operation log is stored at the starting position of the dynamic memory.
[0211] In one example, the preset storage area further includes a switch information storage area; the switch information storage area is used to record the activation status of each log storage area;
[0212] The judgment module is used to trigger the log data storage module when the enabling state of each log storage area is turned on.
[0213] In one example, the preset storage area further includes a header information storage area, and the header information storage area includes header information of the first log storage area, header information of the second log storage area, and header information of the third log storage area.
[0214] In another embodiment provided in the present application, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of the log storage method of any of the above-mentioned small systems are implemented.
[0215] In another embodiment provided by the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any buffer allocation method in the above embodiments.
[0216] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive Solid State Disk (SSD)), etc.
[0217] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0218] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device and electronic device embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0219] The above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the protection scope of the present application.
Claims
1. A log storage method of a small system, applied to an electronic device, wherein the electronic device includes a small system and a log capture service, and the method includes: After the mini-system is started, the log capture service calls the log interface of the mini-system to obtain log data from the log partition of the mini-system, wherein the log data includes a startup log; The log capture service stores the log data in a preset storage area according to a preset log category; wherein the preset storage area is a storage area applied for by the log capture service and is different from the log partition of the small system; The preset storage area includes a first log storage area, and the first log storage area includes a first number of storage blocks; and storing the log data in the preset storage area according to the preset log category includes: Set index information and status flag information; determine the storage block pointed to by the index information, record the startup log in the storage block, and update the status flag information of the storage block to be in use; the initial information of the status flag information of the first number of storage blocks is to be used; when the storage block is full, update the status flag information of the storage block to be used; point the index information to the next storage block of the storage block, if the current storage block is the last storage block, point the index information to the first storage block, the startup log is a log generated during the normal or abnormal startup process of the electronic device.
2. The method according to claim 1, characterized in that The preset log category includes at least one of a device startup category, an image file loading category, and an operation category for the preset storage area. The preset storage area also includes at least one of a second log storage area and a third log storage area.
3. The method according to claim 2, characterized in that The log data further includes at least one of a loading log and an operation log, and the storing the log data in a preset storage area according to a preset log category further includes: storing the loading log in the second log storage area, wherein the loading log is a log generated during the image file loading process; and / or The operation log is stored in the third log storage area, and the operation log is a log generated when an operation is performed on the preset storage area.
4. The method according to claim 3, characterized in that The storing the loading log in the second log storage area comprises: The second log storage area includes at least one storage block; the at least one storage block is divided into a plurality of sub-storage blocks of a preset size; storing the loading log in a first sub-storage block among a plurality of sub-storage blocks; When the first sub-storage block is full, writing the loading log to the next sub-storage block; If the current sub-storage block is the last sub-storage block among the multiple sub-storage blocks, the loading log is written into the first sub-storage block among the multiple sub-storage blocks.
5. The method according to claim 3, characterized in that: The storing the operation log in the third log storage area includes: Storing the operation log in a pre-applied dynamic memory; The data in the dynamic memory is acquired, and the data is stored in the third log storage area.
6. The method according to claim 5, characterized in that The step of storing the operation log in a pre-applied dynamic memory includes: If the remaining space of the dynamic memory is not less than the storage space required for the operation log, storing the operation log at the offset position of the dynamic memory; If the remaining space of the dynamic memory is smaller than the storage space required for the operation log, the operation log is stored at the starting position of the dynamic memory.
7. The method according to claim 2, characterized in that The preset storage area also includes a switch information storage area; the switch information storage area is used to record the activation status of each log storage area; When the enabling state of each log storage area is turned on, the step of storing the log data in the preset storage area according to the preset log category is performed.
8. The method according to claim 1, characterized in that The preset storage area also includes a header information storage area, and the header information storage area includes header information of the first log storage area, header information of the second log storage area, and header information of the third log storage area.
9. A log storage device of a small system, applied to an electronic device, the electronic device comprising a small system and a log capture service, the device comprising: A log data acquisition module, used to call the log interface of the small system to obtain log data from the log partition of the small system, wherein the log data includes a startup log; A log data storage module, used to store the log data in a preset storage area according to a preset log category; wherein the preset storage area is a storage area applied for by the log capture service and is different from the log partition of the small system; the preset storage area includes a first log storage area, and the first log storage area includes a first number of storage blocks; The log data storage module includes: a first log data storage module, the first log data storage module includes: Setting module, used to set index information and status flag information; a storage block determination module, configured to determine the storage block pointed to by the index information, record a startup log in the storage block, and update the status flag information of the storage block to be in use; the initial information of the status flag information of the first number of storage blocks is that they are to be used; A status flag information updating module, used to update the status flag information of the storage block to be used when the storage block is full; The index moving module is used to point the index information to the next storage block of the storage block, and if the current storage block is the last storage block, point the index information to the first storage block.
10. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, for implementing any of the methods described in claims 1-8 when executing a program stored in a memory.
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 method according to any one of claims 1 to 8 is implemented.
