Log writing control method and device, equipment and storage medium
By calculating the storage pressure index (SPI) of the eMMC and selectively storing logs based on the level, the problems of crashes and reduced lifespan caused by small storage space are solved, achieving efficient log storage and life extension of electronic devices.
Patent Information
- Application Number
- CN202510755256.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-06
- Publication Date
- 2025-09-26
AI Technical Summary
In the prior art, the log storage method of electronic devices is prone to problems such as storage space collapse or reduced device life when the storage space is small.
By obtaining the health parameters and system load data of the eMMC, the target storage pressure index SPI is calculated. Based on the mapping relationship between the preset SPI range and the log level, logs of the target log level are selectively written to the eMMC. Combined with memory backup, selective data storage is achieved to extend the life of the eMMC.
It effectively reduces the loss of eMMC, extends its lifespan, avoids system crashes, and improves the flexibility and accuracy of log storage.
Smart Images

Figure CN120704596A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to embedded storage technology, and relate to, but are not limited to, a log writing control method and apparatus, device, and storage medium. Background Art
[0002] For electronic devices that need to store logs, such as smartphones and vehicle-mounted terminals, logs generated during the operation of the device usually need to be stored in the corresponding storage space.
[0003] In related technologies, the storage method used is usually fixed. For example, every time a log file is generated, the log file can be stored in a corresponding storage space.
[0004] However, this storage method is not suitable for electronic devices with small storage space, and may cause problems such as storage space collapse or reduced device life. Summary of the Invention
[0005] In view of this, the log writing control method, device, equipment, and storage medium provided in the embodiments of the present application can reduce the loss of storage space and increase the life of storage devices. The log writing control method, device, equipment, and storage medium provided in the embodiments of the present application are implemented as follows:
[0006] In one aspect of an embodiment of the present application, a log writing control method is provided, which is applied to an electronic device, wherein the electronic device includes an embedded multimedia card (eMMC). The method includes:
[0007] Obtaining target parameters, where the target parameters include health parameters of the eMMC and / or system load data, where the health parameters include at least one of the number of erase / write cycles, a bad block rate, and a current temperature, and the system load data includes at least one of a central processing unit (CPU) utilization and a direct memory access (DMA) queue depth;
[0008] Calculating a target storage pressure index SPI based on the target parameters;
[0009] According to the mapping relationship between the preset SPI range and the preset log level, the target log corresponding to the target log level is written to the eMMC. The target log level is the log level corresponding to the target SPI.
[0010] In another aspect of the embodiments of the present application, a log writing control device is provided, which is applied to an electronic device, wherein the electronic device includes an embedded multimedia card eMMC, and the device includes: a state perception module, a policy adjustment module, and a storage writing optimization module;
[0011] a state sensing module, configured to obtain target parameters, the target parameters including health parameters of the eMMC and / or system load data, the health parameters including at least one of the number of erase / write cycles, the bad block rate, and the current temperature, and the system load data including at least one of the central processing unit (CPU) utilization and the direct memory access (DMA) queue depth;
[0012] A policy adjustment module is used to calculate a target storage pressure index SPI based on target parameters;
[0013] The storage write optimization module is used to write a target log corresponding to a target log level to the eMMC according to a mapping relationship between a preset SPI range and a preset log level. The target log level is the log level corresponding to the target SPI.
[0014] The computer device provided in the embodiment of the present application includes a memory and a processor. The memory stores a computer program that can be run on the processor. When the processor executes the program, the method of the embodiment of the present application is implemented.
[0015] The computer-readable storage medium provided in the embodiment of the present application stores a computer program thereon, and when the computer program is executed by a processor, the method provided in the embodiment of the present application is implemented.
[0016] The computer program product provided in the embodiments of the present application includes a computer program, which implements the method provided in the embodiments of the present application when executed by a processor.
[0017] The log writing control method, device, equipment, and storage medium provided in the embodiments of the present application can obtain target parameters, the target parameters including health parameters and / or system load data of the eMMC, the health parameters including at least one of the number of erases and writes, the bad block rate, and the current temperature, and the system load data including at least one of the central processing unit CPU utilization and the direct memory access DMA queue depth; calculate the target storage pressure index SPI based on the target parameters; write the target log corresponding to the target log level to the eMMC according to the mapping relationship between the preset SPI range and the preset log level, and the target log level is the log level corresponding to the target SPI. Among them, it can be determined whether to write the target log to the storage space, that is, the above-mentioned eMMC, according to the level of the target log, and then selective data storage can be performed when the eMMC capacity is low, thereby reducing the loss of the eMMC, extending the life of the eMMC, and avoiding system crashes. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0019] Figure 1 A schematic diagram of an application scenario provided in an embodiment of the present application;
[0020] Figure 2 A flow chart of a log writing control method provided in an embodiment of the present application;
[0021] Figure 3 A schematic diagram of the process of calculating the target SPI provided in an embodiment of the present application;
[0022] Figure 4 A flow chart of log level screening provided in an embodiment of the present application;
[0023] Figure 5 A schematic diagram of one of the feasible storage methods provided in the embodiments of the present application;
[0024] Figure 6 A schematic diagram of another storage method provided in an embodiment of the present application;
[0025] Figure 7 A schematic diagram of the process of writing to a target log provided in an embodiment of the present application;
[0026] Figure 8 This is another flowchart of writing to a target log provided in an embodiment of the present application;
[0027] Figure 9 This is a schematic diagram of the structure of the log writing device provided in an embodiment of the present application;
[0028] Figure 10 This is a schematic diagram of the structure of the computer device provided in the embodiment of the present application. DETAILED DESCRIPTION
[0029] To make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the specific technical solutions of the present application will be further described in detail below in conjunction with the drawings in the embodiments of the present application. The following embodiments are used to illustrate the present application but are not intended to limit the scope of the present application.
[0030] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only and are not intended to limit this application.
[0031] In the following description, reference is made to “some embodiments”, which describes a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0032] It should be pointed out that the terms "first\second\third" involved in the embodiments of the present application are used to distinguish similar or different objects, and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.
[0033] In order to more accurately explain the log writing control method provided in this application, the actual application scenario of the method is explained below.
[0034] Figure 1 This is a schematic diagram of the application scenario provided in the embodiment of this application, please refer to Figure 1 In this scenario, an electronic device may be included, and an eMMC100 may be configured on the electronic device, wherein the eMMC (embedded MultiMediaCard) may be a storage device widely used in mobile devices and embedded systems, which is configured with corresponding storage space and can store specific data, such as log files, etc. In an embodiment of the present application, the eMMC may be a storage device for storing log files.
[0035] It should be noted that the electronic devices mentioned above may include, but are not limited to, mobile phones, wearable devices (such as smart watches, smart bracelets, smart glasses, etc.), tablet computers, laptop computers, vehicle-mounted terminals, PCs (Personal Computers), etc. The functions implemented by this method can be implemented by calling program code by a processor in the electronic device. Of course, the program code can also be stored in a computer storage medium. Therefore, the electronic device includes at least a processor and a storage medium.
[0036] Optionally, during operation, the electronic device may generate data that needs to be stored, such as a log. The log may be stored in the form of a file, and the electronic device may store the log through the eMMC.
[0037] In the related art, the technical means adopted is to store the log in the eMMC every time a log is generated.
[0038] However, since the storage space of the eMMC is limited, if all logs are stored in the storage space during the storage process, the life of the eMMC may be shortened. Moreover, if the storage space limit is exceeded, it may cause problems such as system crash. In view of this, a log writing control method is provided in an embodiment of the present application. The following explains one feasible implementation process of the method.
[0039] Figure 2 This is a flow chart of the log writing control method provided in the embodiment of the present application, please refer to Figure 2 , the method comprising:
[0040] S210: Obtain target parameters.
[0041] It should be noted that the execution subject of this method may be the above-mentioned electronic device.
[0042] The target parameters include health parameters of the eMMC and / or system load data.
[0043] Optionally, the health parameter includes at least one of the number of erase / write times, bad block rate and current temperature; and the system load data includes at least one of the central processing unit (CPU) utilization and direct memory access (DMA) queue depth.
[0044] Among them, the health parameter is used to indicate the usage status of the eMMC hardware. For example, the number of erase and write times can indicate the number of times the eMMC is written or cleared as a whole, or the number of times each storage block in the eMMC is written or cleared. There is no specific restriction here and it can be set according to actual needs.
[0045] The bad block rate refers to the ratio of damaged memory blocks to all memory blocks that are inevitably generated during the manufacturing process due to process, materials, and other reasons. For example, a bad block rate of 2% means that 2% of the memory blocks are damaged.
[0046] The current temperature refers to the current operating temperature of the eMMC. This temperature can be the temperature of the surrounding environment or the temperature of the device itself. If it is the temperature of the device itself, it can be the average temperature of the entire device or the temperature of a certain area in the device. There is no specific limitation here. One or more temperatures can be selected as the above current temperature according to actual needs.
[0047] System load data is used to indicate the usage status of the eMMC software, such as CPU utilization and DMA queue depth.
[0048] Central Processing Unit (CPU) utilization refers to the ratio of CPU usage time to total available time within a given time period. It's important to note that if a device's memory is insufficient, the CPU may frequently wait for data to be loaded from storage devices like hard drives while processing data, resulting in low CPU utilization.
[0049] DMA (Direct Memory Access) queue depth refers to the number of DMA requests or transfer tasks that a DMA controller or related device can handle at one time during a DMA operation.
[0050] It should be noted that, in the embodiments of the present application, one or more of the above-mentioned target parameters may be obtained, and different types of parameters may be obtained in different ways.
[0051] For example, health parameters can be obtained by reading the relevant hardware data of the eMMC; system load data can be obtained by reading the relevant data in the central processing unit or direct memory access queue. No specific restrictions are imposed here.
[0052] After obtaining at least one target parameter among the above-mentioned multiple target parameters, corresponding calculations can be performed based on the one or multiple target parameters.
[0053] S220: Calculating a target storage pressure index SPI based on the target parameters.
[0054] The Storage Pressure Index (SPI) is a parameter used to indicate the storage pressure of a storage space or storage device. This parameter can be a value in the range of 0-100%. A larger SPI value indicates a greater storage pressure on the storage space or storage device and a higher difficulty in storing data. Correspondingly, a smaller SPI value indicates a lower storage pressure on the storage space or storage device and a lower difficulty in storing data.
[0055] It should be noted that, as explained above, there are multiple target parameters, and the target storage pressure index SPI can be calculated based on at least one of the multiple target parameters.
[0056] In one embodiment, a corresponding calculation formula may be configured, and the SPI corresponding to the target parameter may be determined by using a calculation formula between one or more target parameters and the SPI.
[0057] It should be noted that since there are multiple target parameters, multiple different calculation formulas can be pre-configured. It can be the calculation formula of any one of the target parameters and the SPI, or it can be the calculation formula of multiple target parameters combined with the SPI. There is no specific restriction here, and corresponding settings can be made according to actual needs.
[0058] After obtaining the target SPI in the above manner, subsequent storage determination can be performed.
[0059] S230: Writing a target log corresponding to the target log level to the eMMC according to a mapping relationship between a preset SPI range and a preset log level.
[0060] It should be noted that the log level can be a level division of different logs according to actual needs, wherein the level division can be performed in a manner of log size, or in a manner of log category.
[0061] A mapping relationship between the SPI range and the log level can be configured. For example, multiple intervals can be set according to different SPI value ranges, and each interval corresponds to a log level. After the target SPI is determined in step S220 above, the corresponding log level can be found based on the SPI range to which the target SPI belongs, thereby determining the target log level. In other words, the target log level is the log level corresponding to the target SPI.
[0062] In one embodiment, the above-mentioned mapping relationship can be preset in advance. After obtaining the target SPI, matching can be performed through the mapping relationship to determine the target log level corresponding to the target SPI. During the log writing process, it can be determined whether the target log can be written to the eMMC based on the log level. If the log level of the target log is the target log level or higher than the target log level, the target log can be written to the eMMC. Correspondingly, if the log level of the target log is lower than the target log level, the target log cannot be written to the eMMC.
[0063] In the log writing control method provided in the embodiment of the present application, target parameters can be obtained, and the target parameters include health parameters and / or system load data of the eMMC, the health parameters include at least one of the number of erases and writes, the bad block rate and the current temperature, and the system load data includes at least one of the central processing unit CPU utilization and the direct memory access DMA queue depth; the target storage pressure index SPI is calculated based on the target parameters; according to the mapping relationship between the preset SPI range and the preset log level, the target log corresponding to the target log level is written to the eMMC, and the target log level is the log level corresponding to the target SPI. Among them, it can be determined whether the target log is written to the storage space, that is, the above-mentioned eMMC, according to the level of the target log, and then selective data storage can be performed when the eMMC capacity is low, so as to reduce the loss of the eMMC, extend the life of the eMMC, and avoid system crashes.
[0064] In order to more clearly illustrate the process of calculating the target SPI provided in the embodiments of the present application, the process of calculating the target SPI based on the target parameters is explained below through a specific embodiment.
[0065] Figure 3 For a flow chart of the calculation target SPI provided in the embodiment of this application, please refer to Figure 3 , calculate the target SPI based on the target parameters, including:
[0066] S310: Obtain a target weight corresponding to the target parameter.
[0067] Among them, different target parameters correspond to different weights.
[0068] It should be noted that before calculating the target SPI, the target parameters used in this calculation can be determined first. Different weights can be configured for different parameters. For example, the first weight can be set for health parameters and the second weight can be set for system load data.
[0069] Optionally, the first weight and the second weight may be fixed weights set according to actual needs, or may be variable weights obtained according to the type of health parameters involved in the calculation or the type of system load data, without specific limitation here.
[0070] If it is a fixed weight, it can be a preset fixed value, for example: the first weight is 0.3, and the second weight is 0.7; if it is a variable weight, it can be a weight set according to the type of target parameter involved in the calculation, for example: if the health parameters include the number of erases and writes, and the system load data includes the central processing unit CPU utilization and the direct memory access DMA queue depth, then the first weight can be set to a smaller value and the second weight can be set to a larger value; if the health parameters include the number of erases and writes, the bad block rate and the current temperature, and the system load data includes the central processing unit CPU utilization, then the first weight can be set to a larger value and the second weight can be set to a smaller value. There is no specific restriction here, and it can be set according to actual needs.
[0071] It should be noted that since there are multiple health parameters and system load data, the specific value of the target parameter can be calculated based on one or more of the data. For example, the specific value of the health parameter and the specific value of the system load data can be determined, and then the target weights corresponding to these two parameters can be obtained, and then the target SPI can be calculated.
[0072] S320: Perform a weighted sum operation on the target parameters according to the target weight to obtain a calculation result.
[0073] The calculation result is the target SPI.
[0074] It should be noted that the calculation formula is as follows:
[0075] SPI = a × L1 + b × L2;
[0076] Wherein, a is the target weight of the health parameter, b is the target weight of the system load data, a+b=1, L1 can be the specific value of the health parameter, and L2 can be the specific value of the system load data. The calculation result can be obtained in this way, and the settlement result represents the target SPI.
[0077] In the log writing control method provided in the embodiment of the present application, a target weight corresponding to the target parameter can be obtained. Different target parameters correspond to different weights. According to the target weight, a weighted sum operation is performed on the target parameter to obtain a calculation result. The calculation result is the target SPI. It should be noted that a more accurate and appropriate target SPI can be obtained by weighted calculation, so that it can be determined whether the target log can be stored according to the more accurate SPI, thereby improving the accuracy and rationality of log storage.
[0078] The following explains one feasible implementation process of log level screening provided in the embodiment of the present application.
[0079] Figure 4For a flow chart of log level screening provided in the embodiment of this application, please refer to Figure 4 , based on the preset mapping relationship between SPI range and log level, write the target log corresponding to the target log level to the eMMC, including:
[0080] S410: Determine a target SPI range corresponding to the target SPI.
[0081] It should be noted that the SPI range may be a plurality of pre-divided range intervals. As explained above, the SPI may be a percentage interval, for example, a numerical value of 0-100%. The SPI range may be divided within this range. For example, the SPI may be divided into ten different intervals according to 0-10%, 10%-20%, 20%-30%, 30%-40%, 40%-50%, 50%-60%, 60%-70%, 70%-80%, 80%-90%, and 90%-100%. These intervals may represent one of the SPI ranges, and the range into which the target SPI falls may be determined based on the value of the target SPI.
[0082] For example, if the target SPI is 51%, the corresponding target SPI range is 50%-60%.
[0083] In one embodiment, multiple SPI ranges may be determined according to any rule, and the target SPI range corresponding to the target SPI may be determined according to the value of the target SPI.
[0084] S420: Determine a target log level corresponding to the target SPI range from the mapping relationship.
[0085] It should be noted that a log level corresponding to each SPI range can be configured. After the target SPI range is determined, the target log level corresponding to the target SPI range can be determined based on the above mapping relationship.
[0086] In one embodiment, the preset log level includes at least one of emergency information EMERG, immediate alarm information ALERT, serious error information CRITICAL, general error information ERROR, warning information WARNING, attention information NOTICE, general information INFO, and debugging information DEBUG.
[0087] It should be noted that the above multiple log levels can be represented by setting corresponding log level labels in a manual marking manner, or can also be represented by log level labels automatically generated according to the type of log or the keywords of the log.
[0088] It should be noted that the above multiple log levels are in descending order, that is, the log level of emergency information EMERG is the highest, and the log level of debugging information DEBUG is the lowest.
[0089] In one embodiment, the log level corresponding to each SPI range may be one or more levels determined from the above-mentioned preset log levels, which is not specifically limited here.
[0090] S430: Writing the target log to the eMMC.
[0091] In one embodiment, after determining the target log level corresponding to the target SPI range, the target log may be written to the eMMC, wherein the target log includes logs at the target log level and logs above the target log level.
[0092] For example, if the target log level corresponding to the target SPI is ALERT, then during the log writing process, target logs with a log level greater than or equal to ALERT can be written, that is, logs with both the emergency information level and the immediate alarm information level can be written.
[0093] In the log writing control method provided in the embodiment of the present application, a target SPI range corresponding to a target SPI can be determined; a target log level corresponding to the target SPI range can be determined from a mapping relationship; and a target log can be written to the eMMC. Specifically, by determining the target SPI range corresponding to the target SPI, the target log level corresponding to the target SPI can be determined, thereby writing target logs at the target log level and above to the eMMC, thereby implementing the writing of logs for specific targets.
[0094] It should be noted that after storing specific logs in the above manner, some logs cannot be stored by the eMMC. In order to ensure that all logs can be stored normally, a feasible storage method is provided in the embodiment of the present application.
[0095] Figure 5 This is a schematic diagram of one of the possible storage methods provided in the embodiment of this application, please refer to Figure 5 In one embodiment, after writing the target log corresponding to the target log level to the eMMC, the method further includes: when the target SPI range is within the first threshold range, enabling the memory and storing the target log in the memory and the eMMC.
[0096] It should be noted that the first threshold range can be a threshold range defined according to actual needs, for example, it can be SPI ≥ 70%. In this case, the memory can be enabled, and during the process of storing the target log, it can be stored not only in the eMMC but also in the memory.
[0097] In one embodiment, if SPI is less than 30%, all types of logs can be stored; if 30% ≤ SPI < 70%, only warning information WARNING and logs above the WARNING level can be stored; if SPI ≥ 70%, only emergency information EMERG and immediate alarm information ALERT level logs can be stored. Accordingly, when SPI ≥ 70%, memory can also be enabled, and emergency information EMERG and immediate alarm information ALERT level logs are stored in the eMMC, and other logs that cannot be stored in the eMMC are stored in the memory.
[0098] In one embodiment, the fuse mechanism can also be set by enabling memory. For example, if SPI>85%, no logs will be written to the eMMC, and instead all corresponding logs will be written to the memory, thereby preventing damage to the eMMC.
[0099] Optionally, in addition to the SPI-based determination, the determination can also be made directly based on target parameters, such as bad block rate, current temperature, etc. When these target parameters are greater than a certain threshold, the above-mentioned fuse mechanism can also be triggered to prevent eMMC damage.
[0100] It should be noted that the memory can only be used as temporary storage and cannot be used for continuous storage like eMMC. Therefore, another storage method can be used.
[0101] Figure 6 For a schematic diagram of another storage method provided in the embodiment of this application, please refer to Figure 6 The method further includes: obtaining an updated target SPI; and writing the target log in the memory to the eMMC when the updated target SPI is within a second threshold range, and the minimum value of the first threshold range is greater than the maximum value of the second threshold range.
[0102] It should be noted that the second threshold range may be a threshold range defined according to actual needs, for example, SPI < 30%. In this case, the target log in the memory may be written to the eMMC.
[0103] In one embodiment, the Figure 5After the storage method shown, the updated target SPI is obtained at regular intervals, and the SPI range is determined for the updated target SPI. If it is within the second threshold range, the target log stored in the memory can be written to the eMMC.
[0104] In the log writing control method provided in the embodiment of the present application, when the target SPI range is within the first threshold range, the memory can be enabled, and the target log can be stored in the memory and the eMMC; the updated target SPI can be obtained; when the updated target SPI is within the second threshold range, the target log in the memory can be written to the eMMC, and the minimum value of the first threshold range is greater than the maximum value of the second threshold range. Among them, when the eMMC storage space resources are tight, the pressure of the eMMC can be shared by enabling the memory, and the log can be temporarily stored; when the eMMC storage space resources are loose, the log in the memory can be written to the eMMC, thereby realizing the normal storage of the log. The above method can make the storage of the log more flexible, improve the flexibility of log storage, and ensure that more logs can be stored normally by the eMMC.
[0105] The following explains one feasible implementation process of writing to the target log provided in the embodiment of the present application.
[0106] Figure 7 For a flow chart of writing target logs provided in the embodiment of this application, please refer to Figure 7 , write the target log corresponding to the target log level to the eMMC, including:
[0107] S710: Compress the target log to obtain a compressed target log.
[0108] It should be noted that before writing the target log to the eMMC, the target log can be compressed to reduce the space occupied by the log. For example, the log can be compressed using LZ4 lossless compression to obtain a compressed target log.
[0109] In one embodiment, all target logs may be compressed, or, depending on the level of the logs, only some of the logs may be compressed, for example, general information INFO and debugging information DEBUG logs may be compressed, while higher level logs may not be compressed. No specific limitation is imposed here.
[0110] It should be noted that in the actual implementation process, different compression methods can be used according to different log levels. For logs with lower levels, compression methods with higher compression ratios can be used for processing. For logs with higher levels, compression methods with lower compression ratios can be used for processing.
[0111] S720: Write the compressed target log to the eMMC.
[0112] It should be noted that after the target log is compressed using the above compression method, the compressed target log can be written into the eMMC.
[0113] During the write process, multi-plane alternating write technology can be used to distribute logs to different physical blocks, with reserved areas for storing critical logs. This technology can improve storage performance through parallel processing capabilities.
[0114] In the log writing control method provided in the embodiment of the present application, a target log can be compressed to obtain a compressed target log; the compressed target log is then written to the eMMC. Compression of the target log can conserve storage space resources occupied by the log. Furthermore, using different compression methods for logs of different levels can balance the storage space resources occupied by the log and the importance of the log, thereby ensuring that more logs are stored.
[0115] The following explains another feasible implementation process for log writing provided in the embodiments of the present application.
[0116] Figure 8 For another flow chart of writing target logs provided in the embodiment of the present application, please refer to Figure 8 , write the target log corresponding to the target log level to the eMMC, including:
[0117] S810: Obtain the target operating mode of the eMMC.
[0118] The working modes of the eMMC may include: HS400 working mode and HS200 working mode.
[0119] Optionally, different working modes may operate at different write rates. For example, in the HS400 working mode, the system may operate at a higher write rate, and in the HS200 working mode, the system may operate at a lower write rate.
[0120] In one embodiment, the target operating mode may be the current operating mode of the eMMC. For example, if the current operating mode is HS400, the target operating mode is HS400.
[0121] The working mode of eMMC can be set according to the actual operating environment or operating requirements, and is not specifically limited here.
[0122] S820: Determine a log writing rate according to a mapping relationship between a preset working mode and a preset writing rate and a target working mode.
[0123] It should be noted that different operating modes may correspond to different write rates. The mapping relationship may be pre-stored. After determining the target operating mode of the eMMC, the log write rate corresponding to the target operating mode may be determined based on the mapping relationship.
[0124] For example, when the target working mode is determined to be HS400, the log writing rate can be determined to be 400M / s.
[0125] S830: Write the target log to the eMMC according to the log writing rate.
[0126] It should be noted that after the log writing rate is determined based on the above mapping relationship, the target log can be written into the eMMC according to the corresponding log writing rate.
[0127] In the log writing control method provided in the embodiment of the present application, a target operating mode of the eMMC can be obtained; a log writing rate is determined based on the mapping relationship between the preset operating mode and the preset write rate and the target operating mode; and a target log is written to the eMMC at the log writing rate. The corresponding log writing rate is determined by the operating mode of the eMMC, and the target log can be written to the eMMC at a more appropriate log writing rate, thereby ensuring the efficiency of log storage.
[0128] In addition, the log writing control method provided in the embodiment of the present application does not require the provision of additional hardware products, and can also save the cost of log writing.
[0129] It should be understood that, although the steps in the above-mentioned flowcharts are shown in sequence according to the instructions of the arrows, these steps are not necessarily performed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be performed in other orders. Moreover, at least a portion of the steps in the above-mentioned flowcharts may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily performed at the same time, but can be performed at different times, and the execution order of these sub-steps or stages is not necessarily to be performed in sequence, but can be performed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
[0130] Based on the foregoing embodiments, an embodiment of the present application provides a log writing control device, which includes the modules included and the units included in each module, and can be implemented by a processor; of course, it can also be implemented by a specific logic circuit; in the implementation process, the processor can be a central processing unit (CPU), a microprocessor (MPU), a digital signal processor (DSP) or a field programmable gate array (FPGA), etc.
[0131] Figure 9 This is a structural diagram of the log writing device provided in the embodiment of the present application, please refer to Figure 9 , a log writing control device is applied to an electronic device, the electronic device includes an embedded multimedia card eMMC, and the device includes: a state perception module 910, a policy adjustment module 920 and a storage write optimization module 930;
[0132] A state sensing module 910 is configured to obtain target parameters, where the target parameters include health parameters of the eMMC and / or system load data, where the health parameters include at least one of the number of erase / write cycles, the bad block rate, and the current temperature, and the system load data includes at least one of the central processing unit (CPU) utilization and the direct memory access (DMA) queue depth.
[0133] A policy adjustment module 920 is configured to calculate a target storage pressure index SPI based on target parameters;
[0134] The storage write optimization module 930 is used to write a target log corresponding to a target log level to the eMMC according to a mapping relationship between a preset SPI range and a preset log level. The target log level is a log level corresponding to the target SPI.
[0135] In one embodiment, the policy adjustment module 920 is specifically configured to obtain a target weight corresponding to a target parameter, where different target parameters correspond to different weights; and perform a weighted sum operation on the target parameters according to the target weight to obtain a calculation result, which is the target SPI.
[0136] In one embodiment, the storage write optimization module 930 is specifically used to determine a target SPI range corresponding to the target SPI; determine a target log level corresponding to the target SPI range from a mapping relationship; and write a target log to the eMMC, where the target log includes logs at the target log level and above the target log level.
[0137] In one embodiment, the storage write optimization module 930 is further configured to enable the memory and store the target log in the memory and the eMMC when the target SPI range is within the first threshold range.
[0138] In one embodiment, the storage write optimization module 930 is further used to obtain an updated target SPI; when the updated target SPI is within a second threshold range, the target log in the memory is written to the eMMC, and the minimum value of the first threshold range is greater than the maximum value of the second threshold range.
[0139] In one embodiment, the storage write optimization module 930 is specifically configured to compress the target log to obtain a compressed target log; and write the compressed target log into the eMMC.
[0140] In one embodiment, the storage write optimization module 930 is specifically used to obtain a target operating mode of the eMMC; determine a log write rate based on a mapping relationship between a preset operating mode and a preset write rate and the target operating mode; and write a target log to the eMMC according to the log write rate.
[0141] In one embodiment, in the device, the preset log levels include at least one of emergency information EMERG, immediate alarm information ALERT, serious error information CRITICAL, general error information ERROR, warning information WARNING, attention information NOTICE, general information INFO and debugging information DEBUG, and the log levels decrease.
[0142] In the log writing control device provided in the embodiment of the present application, target parameters can be obtained, and the target parameters include health parameters and / or system load data of the eMMC, the health parameters include at least one of the number of erases and writes, the bad block rate and the current temperature, and the system load data includes at least one of the central processing unit CPU utilization and the direct memory access DMA queue depth; the target storage pressure index SPI is calculated based on the target parameters; according to the mapping relationship between the preset SPI range and the preset log level, the target log corresponding to the target log level is written to the eMMC, and the target log level is the log level corresponding to the target SPI. Among them, it can be determined whether the target log is written to the storage space, that is, the above-mentioned eMMC, according to the level of the target log, and then selective data storage can be performed when the eMMC capacity is low, thereby reducing the loss of the eMMC, extending the life of the eMMC, and avoiding system crashes.
[0143] The description of the above device embodiment is similar to the description of the above method embodiment and has similar beneficial effects as the method embodiment. For technical details not disclosed in the device embodiment of this application, please refer to the description of the method embodiment of this application for understanding.
[0144] It should be noted that in the embodiments of this application Figure 9The division of modules in the log writing control device shown is schematic and is only a logical functional division. In actual implementation, there may be other division methods. In addition, the functional units in the various embodiments of the present application can be integrated into a processing unit, or they can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units. It can also be implemented in the form of a combination of software and hardware.
[0145] It should be noted that, in the embodiment of the present application, if the above method is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling an electronic device to execute all or part of the method described in each embodiment of the present application. The aforementioned storage medium includes various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a magnetic disk or an optical disk. In this way, the embodiment of the present application is not limited to any specific combination of hardware and software.
[0146] Figure 10 For a schematic diagram of the structure of the computer device provided in the embodiment of this application, please refer to Figure 10 , the embodiment of the present application provides a computer device, which can be the above-mentioned electronic device, such as: a mobile phone, a watch, and a car terminal, etc., and its internal structure diagram can be as shown in Figure 10 As shown. The computer device includes a processor 1020, a memory, and a network interface 1040 connected via a system bus 1010. The processor 1020 of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium 1031 and an internal memory 1032. The non-volatile storage medium 1031 stores an operating system, a computer program, and a database. The internal memory 1032 provides an environment for the operation of the operating system and computer program in the non-volatile storage medium 1031. The database of the computer device is used to store data. The network interface 1040 of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor 1020, the above method is implemented.
[0147] An embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the method provided in the above embodiment are implemented.
[0148] An embodiment of the present application provides a computer program product containing instructions, which, when executed on a computer, enables the computer to execute the steps of the method provided in the above method embodiment.
[0149] Those skilled in the art will understand that Figure 10 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0150] In one embodiment, the log writing control device provided by the present application can be implemented in the form of a computer program. Figure 10 The computer device is operated on the computer device shown. The memory of the computer device can store various program modules that constitute the above-mentioned device. The computer program composed of each program module enables the processor to execute the steps of the method of each embodiment of the present application described in this specification.
[0151] It should be noted that the description of the above storage medium and device embodiments is similar to the description of the above method embodiments and has similar beneficial effects as the method embodiments. For technical details not disclosed in the storage medium, storage medium, and device embodiments of this application, please refer to the description of the method embodiments of this application for understanding.
[0152] It should be understood that "one embodiment" or "an embodiment" or "some embodiments" mentioned throughout the specification means that the specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in an embodiment" or "in some embodiments" appearing throughout the specification do not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in the various embodiments of the present application, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. The above-mentioned serial numbers of the embodiments of the present application are for description only and do not represent the advantages and disadvantages of the embodiments. The above description of the various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced to each other. For the sake of brevity, they will not be repeated here.
[0153] The term "and / or" in this article is only a description of the association relationship between associated objects, indicating that there can be three relationships. For example, object A and / or object B can mean: object A exists alone, object A and object B exist at the same time, and object B exists alone.
[0154] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or apparatus comprising the element.
[0155] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The embodiments described above are merely illustrative. For example, the division of the modules is merely a logical function division. In actual implementation, there may be other division methods, such as: multiple modules or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or modules can be electrical, mechanical or other forms.
[0156] The modules described above as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules; they may be located in one place or distributed across multiple network units; some or all of the modules may be selected according to actual needs to achieve the purpose of this embodiment.
[0157] In addition, all functional modules in the embodiments of the present application can be integrated into one processing unit, or each module can be a separate unit, or two or more modules can be integrated into one unit; the above-mentioned integrated modules can be implemented in the form of hardware or in the form of hardware plus software functional units.
[0158] Those skilled in the art will understand that all or part of the steps of implementing the above-mentioned method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above-mentioned method embodiment; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM), magnetic disks or optical disks, and other media that can store program codes.
[0159] Alternatively, if the above-mentioned integrated unit of the present application is implemented in the form of a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application, or the part that contributes to the relevant technology, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions for enabling an electronic device to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks or optical disks.
[0160] The methods disclosed in the several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.
[0161] The features disclosed in the several product embodiments provided in this application can be arbitrarily combined without conflict to obtain new product embodiments.
[0162] The features disclosed in the several method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments or device embodiments.
[0163] The above is merely an embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
Claims
1. A log writing control method, characterized in that: Applied to an electronic device, the electronic device includes an embedded multimedia card eMMC, and the method includes: Obtaining target parameters, where the target parameters include health parameters of the eMMC and / or system load data, where the health parameters include at least one of the number of erase / write cycles, a bad block rate, and a current temperature, and the system load data includes at least one of a central processing unit (CPU) utilization and a direct memory access (DMA) queue depth; Calculating a target storage pressure index SPI based on the target parameter; According to the mapping relationship between the preset SPI range and the preset log level, a target log corresponding to the target log level is written to the eMMC, where the target log level is the log level corresponding to the target SPI.
2. The log writing control method according to claim 1, characterized in that: The calculating the target SPI based on the target parameter includes: Obtaining a target weight corresponding to the target parameter, where different target parameters correspond to different weights; According to the target weight, a weighted sum operation is performed on the target parameters to obtain a calculation result, and the calculation result is the target SPI.
3. The log writing control method according to claim 1, characterized in that: Writing a target log corresponding to a target log level to the eMMC according to a preset mapping relationship between an SPI range and a log level includes: Determining a target SPI range corresponding to the target SPI; Determine the target log level corresponding to the target SPI range from the mapping relationship; The target log is written into the eMMC, where the target log includes logs at the target log level and logs above the target log level.
4. The log writing control method according to claim 3, characterized in that: After writing the target log corresponding to the target log level to the eMMC, the method further includes: When the target SPI range is within a first threshold range, a memory is enabled, and the target log is stored in the memory and the eMMC.
5. The log writing control method according to claim 4, characterized in that: The method further comprises: Get the updated target SPI; When the updated target SPI is within a second threshold range, the target log in the memory is written to the eMMC, and a minimum value of the first threshold range is greater than a maximum value of the second threshold range.
6. The log writing control method according to claim 1, characterized in that: Writing a target log corresponding to a target log level into the eMMC includes: Compressing the target log to obtain a compressed target log; The compressed target log is written into the eMMC.
7. The log writing control method according to claim 1 or 6, characterized in that: Writing a target log corresponding to a target log level into the eMMC includes: Obtain the target operating mode of the eMMC; Determining a log writing rate according to a mapping relationship between a preset working mode and a preset writing rate and the target working mode; The target log is written to the eMMC at the log writing rate.
8. The log writing control method according to claim 1, wherein: The preset log levels include at least one of emergency information EMERG, immediate alarm information ALERT, serious error information CRITICAL, general error information ERROR, warning information WARNING, attention information NOTICE, general information INFO and debugging information DEBUG, and the log levels decrease in descending order.
9. A log writing control device, characterized in that: Applicable to electronic devices, the electronic devices include embedded multimedia cards (eMMCs), the device includes: a state perception module, a policy adjustment module, and a storage write optimization module; The state sensing module is configured to obtain target parameters, wherein the target parameters include health parameters of the eMMC and / or system load data, wherein the health parameters include at least one of the number of erase / write cycles, the bad block rate, and the current temperature, and the system load data includes at least one of the central processing unit (CPU) utilization and the direct memory access (DMA) queue depth; The policy adjustment module is configured to calculate a target storage pressure index SPI based on the target parameter; The storage write optimization module is used to write a target log corresponding to a target log level to the eMMC according to a mapping relationship between a preset SPI range and a preset log level, where the target log level is a log level corresponding to the target SPI.
10. A computer device comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, wherein: When the processor executes the program, the steps of the method according to any one of claims 1 to 8 are implemented.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
12. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Cited By
Dynamic performance smooth regulation and control method and system for eMMC, medium and equipment
CN121455410A
A dynamic performance smoothing regulation method, system, medium and device for eMMC
CN121455410B