Log management method and device, electronic equipment and readable storage medium
By dynamically adjusting the log printing level based on CPU load and IO load in electronic devices, combining the number of log printing characters and the number of front-end applications, the problem of inflexible log management is solved, and the device performance and test accuracy are improved.
Patent Information
- Application Number
- CN202310611387.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-25
- Publication Date
- 2024-11-26
AI Technical Summary
The prior art log management is not flexible enough in electronic devices, and the log printing level cannot be dynamically adjusted according to different usage scenarios, resulting in limited performance improvement and the test results may be affected.
By determining different log printing levels based on CPU load and IO load, and combining the number of log printing characters and the number of front-end applications, dynamically adjusting the log printing level and scheduling level of the disk service to ensure that log management matches usage scenarios.
It realizes the flexibility and adaptability of log management, improves the performance of electronic devices, and avoids misjudgment of test results due to high printing levels during the testing process.
Smart Images

Figure CN119025368A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of terminals, and in particular to a log management method, device, electronic device and readable storage medium. Background Art
[0002] When working, electronic devices will generate event records, called logs, which record time information, users and descriptions of related operations, such as application logs, security logs or system logs. During the development and operation and maintenance process, different types of logs such as application logs, security logs or system logs need to be printed to help developers troubleshoot problems. Log levels are divided into V, D, I, W, E, F and S from low to high. In one implementation, a log printing level is set by default, for example, the default printing level is I, that is, the chip will print logs higher than or equal to level I, that is, it will not print logs of level V and D. The above implementation can reduce the printing of logs, that is, reduce the number of lines and characters printed in the log. By calculating that the printing of a line of logs takes about 0.0135ms, so reducing 10,000 lines of logs can reduce the time consumption by 135ms, so reducing the printing of logs can improve the performance of products using chips. However, this method of defaulting to a printing level is not flexible enough. Summary of the invention
[0003] The present application provides a log management method, device, electronic device and readable storage medium. The solution provided by the present application can adopt different log printing levels in different chip usage scenarios, which is more flexible.
[0004] In order to achieve the above objectives, this application adopts the following technical solutions:
[0005] In a first aspect, a log management method is provided, which is applied to an electronic device, including: determining whether to adopt a first printing level, the first printing level being determined based on a central processing unit (CPU) load and an input / output (IO) load; when it is determined that the first printing level is adopted, managing the printing of the log according to the first printing level; when it is determined that the first printing level is not adopted, managing the printing of the log according to a default printing level.
[0006] Based on the above scheme, the present application can determine and adopt different first printing levels based on different CPU loads and IO loads in different use scenarios of electronic devices, which is relatively flexible. In addition, in the test process of the compatibility test suite (CTS), camera imaging test suite (ITS), etc., if the first printing level determined based on the CPU load and IO load is high, it will cause more levels of logs not to be printed, thereby affecting the judgment of the test results. Therefore, in the test process of CTS, ITS, etc., it can be determined whether to adopt the first printing level first, so as to avoid the problem of affecting the test results when a higher first printing level is adopted.
[0007] In some possible implementations, the first printing level is also determined based on the current number of log print characters and / or the current number of foreground applications.
[0008] Based on the above solution, more parameters can be taken into consideration when determining the first printing level, so that the determined first printing level is more in line with the current usage scenario of the electronic device, thereby improving the user experience.
[0009] In some possible implementations, the first printing level is determined based on y in the following formula:
[0010]
[0011] Among them, L CPU Indicates CPU load, L IO Indicates IO load, N L Indicates the number of characters printed in the current log, N A Indicates the number of current foreground applications.
[0012] Based on the above solution, a specific weight coefficient is given according to the importance of each calculation parameter, so that the determined first printing level is more accurately adapted to the current use scenario of the electronic device.
[0013] In some possible implementations, when 0.2<y≤0.5, the first printing level is W, when 0.5<y≤0.7, the first printing level is E, and when 0.7<y≤1, the first printing level is S.
[0014] In some possible implementations, the method also includes: when determining to adopt the first printing level, determining the scheduling level of the log disk service corresponding to the first printing level based on the correspondence between the first printing level and the scheduling level of the log disk service; and controlling the log disk service according to the scheduling level.
[0015] Based on the above scheme, the scheduling level corresponding to the first printing level can also be determined to control the log disk service, so that the log disk service is more in line with the current usage scenario of the electronic device. It should be noted that the determination of the first printing level and the determination of the scheduling level can be simultaneous, or the determination of the first printing level can be first and the determination of the scheduling level can be later. This application does not impose any restrictions on this.
[0016] In some possible implementations, determining whether to adopt the first printing level includes: when a universal serial bus (USB) debugging switch is turned off, determining to adopt the first printing level.
[0017] Based on the above solution, during the chip testing process, the USB debugging switch is turned off, that is, the developer option is turned off. At this time, it can be determined to use the first printing level to manage the printing of the log.
[0018] In some possible implementations, determining whether to adopt the first printing level includes: when a USB debugging switch is turned on, determining not to adopt the first printing level.
[0019] Based on the above solution, during the chip testing process, the USB debugging switch is turned on, that is, the developer option is turned on. At this time, it can be determined not to use the first printing level, that is, to use the default printing level to manage the printing of logs, so as to avoid using a higher first printing level, resulting in more levels of logs not being printed, thereby affecting the judgment of the test results.
[0020] In some possible implementations, the method further includes: obtaining CPU load and IO load through a data acquisition module of the framework layer, or obtaining CPU load, IO load and at least one of the following: the number of characters printed in the current log, the number of current foreground applications.
[0021] Based on the above solution, the data collection module of the framework layer will trigger the log printing filter service (xlogfilter_service) to determine the printing level in various scenarios of user operation. The xlogfilter_service can obtain status parameters from the data collection module of the framework layer to determine the printing level.
[0022] In some possible implementations, the log includes a kernel log and an upper-layer log.
[0023] Based on the above scheme, the first printing level determined by the present application can be applied to the printing of kernel logs and upper-layer logs, such as logs of the application layer (Java layer) and the native layer.
[0024] In a second aspect, a log management device is provided, comprising a determination module and a control module, wherein the determination module is used to determine whether to adopt a first printing level, the first printing level being determined based on CPU load and IO load; when it is determined to adopt the first printing level, the control module is used to manage the printing of the log according to the first printing level; when it is determined not to adopt the first printing level, the control module is used to manage the printing of the log according to a default printing level.
[0025] In some possible implementations, the first printing level is also determined based on the current number of log print characters and / or the current number of foreground applications.
[0026] In some possible implementations, the first printing level is determined based on y in the following formula:
[0027]
[0028] Among them, L CPU Indicates CPU load, L IO Indicates IO load, N L Indicates the number of characters printed in the current log, N A Indicates the number of current foreground applications.
[0029] In some possible implementations, when 0.2<y≤0.5, the first printing level is W, when 0.5<y≤0.7, the first printing level is E, and when 0.7<y≤1, the first printing level is S.
[0030] In some possible implementations, the determination module is specifically used to: when determining to adopt the first printing level, determine the scheduling level of the log disk service corresponding to the first printing level based on the correspondence between the first printing level and the scheduling level of the log disk service; the control module is specifically used to: control the log disk service according to the scheduling level.
[0031] In some possible implementations, the determination module is specifically configured to: when a universal serial bus (USB) debugging switch is turned off, determine to use the first printing level.
[0032] In some possible implementations, the determination module is specifically configured to: when the USB debugging switch is turned on, determine not to use the first printing level.
[0033] In some possible implementations, the management device also includes an acquisition module, which is used to obtain the CPU load and IO load through the data acquisition module of the framework layer, or to obtain the CPU load, IO load and at least one of the following: the number of characters printed in the current log, the current number of foreground applications.
[0034] In some possible implementations, the log includes a kernel log and an upper-layer log.
[0035] In a third aspect, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the steps of processing in the first aspect or any one of the methods in the first aspect when executing the computer program.
[0036] In a fourth aspect, a chip is provided, characterized in that it includes: a processor for calling and running a computer program from a memory, so that a device equipped with the chip executes the steps of processing in the first aspect or any one of the methods in the first aspect.
[0037] In a fifth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor executes the steps of processing in the first aspect or any one of the methods in the first aspect.
[0038] In a sixth aspect, a computer program product is provided, the computer program product comprising: a computer program code, when the computer program code is executed by an electronic device, the electronic device executes the steps of processing in the first aspect or any one of the methods in the first aspect.
[0039] Among them, the beneficial effects of the second to sixth aspects can refer to the first aspect and will not be elaborated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 It is a hardware structure block diagram of an electronic device provided in an embodiment of the present application;
[0041] Figure 2 It is a flow chart of a log management method provided by an embodiment of the present application;
[0042] Figure 3 It is a flowchart of another log management method provided in an embodiment of the present application.
[0043] Figure 4 This is a schematic diagram of the USB debugging process provided by an embodiment of the present application;
[0044] Figure 5 This is an application scenario diagram of the log management method provided in the embodiment of the present application;
[0045] Figure 6 It is an application timing diagram of the log management method provided in the embodiment of the present application;
[0046] Figure 7 is a structural block diagram of a device provided in an embodiment of the present application;
[0047] Figure 8It is a schematic diagram of the structure of a chip provided in an embodiment of the present application. DETAILED DESCRIPTION
[0048] The technical solution in this application will be described below in conjunction with the accompanying drawings.
[0049] In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, unless otherwise specified, "multiple" means two or more than two.
[0050] In the following, the terms "first" and "second" are used only for descriptive purposes or for distinction, and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features.
[0051] The log management method provided in the embodiment of the present application can be applied to mobile phones, tablet computers, laptop computers, PDAs, mobile internet devices (MID), wearable devices, virtual reality (VR) devices, augmented reality (AR) devices, ultra-mobile personal computers (UMPC), netbooks, personal digital assistants (PDA), smart homes and other electronic devices that can generate logs. The embodiment of the present application does not impose any restrictions on the specific types of electronic devices.
[0052] The following is a schematic diagram of the hardware structure of the electronic device 100 for implementing the above method, for example, Figure 1 1 shows a hardware structure diagram of an electronic device 100. The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142 and a transceiver 150.
[0053] It is to be understood that the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or separate some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0054] For example, when the electronic device 100 is a mobile phone or a tablet computer, it may include all the components shown in the figure, or may include only some of the components shown in the figure.
[0055] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0056] The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of instruction fetching and execution.
[0057] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0058] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0059] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present invention is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0060] The charging management module 140 is used to receive charging input from a charger. The charger can be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 can receive charging input from the wired charger through the USB interface 130. In addition to charging, the USB interface can also be used to turn on the USB debugging switch, or to turn on the USB debugging mode. In some wireless charging embodiments, the charging management module 140 can receive wireless charging input through the wireless charging coil of the electronic device 100. While the charging management module 140 is charging the battery 142, it can also power the electronic device through the power management module 141.
[0061] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140 to power the processor 110, the internal memory 121, etc. In some other embodiments, the power management module 141 may also be disposed in the processor 110. In other embodiments, the power management module 141 and the charging management module 140 may also be disposed in the same device.
[0062] The transceiver 150 is used to send data or signaling to other devices outside the electronic device 100 , or to receive data or signaling from other devices outside the electronic device 100 .
[0063] The external memory interface 120 can be used to connect an external memory card, such as a secure digital memory card (SD), to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 via the external memory interface 120 to implement a data storage function.
[0064] The internal memory 121 can be used to store computer executable program codes, which include instructions. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, at least one application required for a function, etc. The data storage area may store data created during the use of the electronic device 100, such as logs. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc. The processor 110 executes various functional applications and data processing of the electronic device 100 by running instructions stored in the internal memory 121 and / or instructions stored in a memory provided in the processor.
[0065] In actual application scenarios, the operating system of the electronic device 100 may include, but is not limited to, Symbian, Android, Windows, MacOS, iOS, Blackberry, HarmonyOS, etc. This application does not impose any limitation on the operating system of the electronic device.
[0066] Before describing the solution provided in the embodiment of the present application, the log level and the printing level of the log are first introduced.
[0067] Log level: It is the attribute of the log, which is divided into V (VERBOSE), D (DEBUG), I (INFO), W (WARNING), E (ERROR), F (FATAL) and S (SILENT) from low to high. Among them, V represents the lowest level, which is used to open all log records; D represents debug log, which is used to print some operation logs during the development process; I represents information, which is used to print some interesting or important information, such as printing some key information of program operation; W represents warning, which means potential errors will occur; E represents error, although an error occurs, it does not affect the continued operation of the system; F represents fatal, that is, a serious error, which requires stopping the program; S represents silent, which is used to close all log records.
[0068] Log printing level: that is, the level of managing log printing. For example, if the log printing level is E, the chip will only print logs with a level higher than or equal to E. For another example, if the log printing level is W, the chip will only print logs with a level higher than or equal to W, and so on.
[0069] Figure 2 It is a flow chart of a log management method provided in an embodiment of the present application.
[0070] refer to Figure 2 The log management method 200 is applied to an electronic device, and the method 200 includes:
[0071] S201, determining a first printing level based on a central processing unit (CPU) load and an input / output (IO) load.
[0072] Different first printing levels can be determined in different scenarios of electronic device operation, such as electronic device startup, switching, sliding and unlocking, etc. Switching includes switching between applications, and sliding includes touch sliding on the screen of the electronic device.
[0073] In a possible implementation, the first printing level is determined based on y in formula (1):
[0074]
[0075] Among them, L CPU Indicates CPU load, L IO Represents IO load, n1+n2=1, for example, n1 is 0.6, n2 is 0.4, and this application does not limit the values of n1 and n2.
[0076] Optionally, the first printing level is also determined based on the current number of log printing characters and / or the current number of foreground applications.
[0077] Furthermore, more parameters are taken into consideration when determining the first printing level, so that the determined first printing level is more in line with the current usage scenario of the electronic device.
[0078] In a possible implementation, the first printing level is determined based on y in formula (2):
[0079]
[0080] Among them, N L Indicates the number of characters printed in the current log, N A Represents the current number of foreground applications, n1+n2+n3+n4=1, for example, n1 is 0.5, n2 is 0.2, n3 is 0.2, and n4 is 0.1. This application does not limit the values of n1, n2, n3, and n4. The current time can be understood as the moment of determining the first printing level, or the moment or time period of determining the first printing level.
[0081] Exemplarily, when 0.2<y≤0.5, the first printing level is W, when 0.5<y≤0.7, the first printing level is E, when 0.7<y≤1, the first printing level is S, and when y≤0.2, the first printing level is the default printing level.
[0082] It can be understood that when the CPU load and IO load are low, a lower printing level can be set, which is beneficial for having more print logs to develop and locate problems when problems occur during the operation of the electronic device. When the CPU load and IO load are high, a higher printing level can be set, which is beneficial for reducing the lag of the electronic device and improving performance.
[0083] S202: managing the printing of the log according to the first printing level.
[0084] Exemplarily, when the first printing level is W, managing the printing of logs according to the first printing level can be understood as: printing logs with a level higher than or equal to W, that is, printing logs with log levels of W, E, F, and S; when the first printing level is E, managing the printing of logs according to the first printing level can be understood as: printing logs with a level higher than or equal to E, that is, printing logs with log levels of E, F, and S, and so on. When the first printing level is the default printing level, the default printing level is, for example, I, managing the printing of logs according to the first printing level can be understood as: printing logs with a level higher than or equal to I, and this application does not limit the default printing level.
[0085] Optionally, the method 200 further includes:
[0086] According to the first printing level and the correspondence between the first printing level and the scheduling level of the log storage service, the scheduling level of the log storage service corresponding to the first printing level is determined, and the log storage service is controlled according to the scheduling level.
[0087] Exemplarily, when the first printing level is E, the scheduling level of the log disk service is medium; when the first printing level is S, the scheduling level of the log disk service is low; when the first printing level is W, the scheduling level of the log disk service is the default scheduling level. The scheduling level can determine whether the disk service is performed in real time. For example, when the current load is relatively high, the log disk service is placed in a low-level scheduling group to reduce the scheduling of the service and improve performance. In other words, controlling the log disk service according to the scheduling level corresponding to the first printing level can make the log disk service more in line with the current usage scenario of the electronic device.
[0088] Optionally, the method 200 further includes:
[0089] The CPU load and the IO load are obtained through the data acquisition module, or the CPU load, the IO load and at least one of the following items are obtained: the number of characters printed in the current log, and the number of current foreground applications.
[0090] Exemplarily, the data acquisition module of the framework layer will trigger the log printing filter service (xlogfilter_service) to determine the printing level in various scenarios of user operation. The xlogfilter_service can obtain the status parameters from the data acquisition module of the framework layer to determine the first printing level. The data adoption module can integrate the load and other data collected from the bottom layer (kernel layer) and the performance-related data into the status parameters. The data adoption module can be an application for scheduling the performance of system resources, which can identify the current user usage scenario. After identification, some resource allocation adjustments and scheduling strategy adjustments can be made. The data adoption module is, for example, an iware application or an iware platform. iware can integrate the load and other data collected from the bottom layer and the performance-related data into the status parameters. The status parameters can be used to determine L in formula (1) and formula (2). CPU , L IO 、N L and N A That is, the state parameter for determining the first printing level is obtained based on the real-time scenario of the user operation, so the printing of the management log according to the first printing level is more flexibly adapted to the current application scenario.
[0091] Based on method 200, the electronic device can determine and adopt different first printing levels based on different CPU loads and IO loads, or the electronic device can determine and adopt different first printing levels in different usage scenarios. Because the CPU load and IO load may be different in different usage scenarios, it is more flexible compared to the solution of defaulting to one printing level.
[0092] Figure 3 It is a flowchart of another log management method provided in an embodiment of the present application.
[0093] refer to Figure 3 The log management method 300 is applied to an electronic device, and the method 300 includes:
[0094] S301, determining whether to adopt the first printing level. The determination of the first printing level may refer to the corresponding content in method 200, which will not be described in detail.
[0095] In other words, S301 can also be described as: determining whether to adopt the default printing level, determining to adopt the default printing level means confirming not to adopt the first printing level, and determining not to adopt the default printing level means determining to adopt the first printing level.
[0096] In a possible implementation, when a universal serial bus (USB) debugging switch is turned off, it is determined to use the first printing level, that is, it is determined not to use the default printing level.
[0097] In a possible implementation, when the USB debugging switch is turned on, it is determined to adopt a default log printing level, that is, it is determined not to adopt the first printing level.
[0098] For example, Figure 4 As shown, a USB debugging switch is set at the application layer (application layer or application framework layer), and the xlogfilter_service service is triggered after the developer option is turned on. In the xlogfilter_service service process, it is determined whether to adopt the first printing level. When the USB debugging switch is turned off, it is determined to adopt the first printing level. When the USB debugging switch is turned on, it is determined not to adopt the first printing level, that is, it is determined to adopt the default log printing level. After determining the printing level, a persistent log level attribute (persist.log.tag) is set, and then the attribute triggers the write kernel node operation in the initialization (init) process, and the written kernel node manages the printing of the kernel log according to the determined printing level (e.g., the first printing level or the default printing level).
[0099] S302: When it is determined to adopt the first printing level, the printing of the log is managed according to the first printing level.
[0100] S302': when it is determined that the first printing level is not to be adopted, the printing of the log is managed according to the default printing level.
[0101] For the printing of the management log according to the first printing level and the default printing level, reference may be made to the relevant description in method 200, which will not be repeated here.
[0102] For example, during the testing process of the compatibility test suite (CTS) and the camera imaging test suite (ITS), logs are required to judge the test results. If the first printing level is determined based on method 200, when the determined first printing level is higher, for example, the first printing level is S, logs with a level lower than S will not be printed, and some problems may not be judged by the printed logs, thus affecting the test results. In this case, it is necessary to set the printing level to the default, for example, set the printing level to I by default, to avoid that logs of higher levels are not printed, thereby affecting the judgment of the test results. Therefore, during the CTS, ITS and other testing processes, the developer options are turned on, and when the USB debugging switch is turned on, it is determined that the first printing level is not used, and when the USB debugging switch is turned off, it is determined that the first printing level is used.
[0103] Optionally, when determining to adopt the first printing level, the method 300 further includes:
[0104] According to the first printing level and the correspondence between the first printing level and the scheduling level of the log disk storage service, the scheduling level of the log disk storage service corresponding to the first printing level is determined; and the log disk storage service is controlled according to the scheduling level.
[0105] For specific details, please refer to the relevant description in method 200, which will not be repeated here.
[0106] The logs involved in methods 200 and 300 may be kernel logs or upper-layer logs, such as logs of the Java layer (application layer) and the native layer.
[0107] Based on the solution provided by method 300, different first printing levels can be determined and adopted according to different CPU loads and IO loads, which is more flexible compared to the solution of adopting one printing level by default. In addition, during the CTS, ITS and other test processes, if the first printing level determined based on the CPU load and IO load is high, more levels of logs will not be printed, thereby affecting the judgment of the test results. Therefore, during the CTS, ITS and other test processes, it can be determined whether to adopt the first printing level first, thereby avoiding the problem of affecting the test results when adopting a higher first printing level.
[0108] Figure 5 This is an application scenario diagram of the log management method provided in the embodiment of the present application.
[0109] like Figure 5 As shown, the application of method 200 between local layer process call relations and kernel layer is illustrated. Different scenarios triggered by user operations (such as starting, switching, sliding and unlocking, etc.) will trigger corresponding services, and the first printing level can be determined in the corresponding services. The method for determining the first printing level can refer to method 200.
[0110] Step 1: After determining the first printing level, you can set properties in the log printing policy (policy) of the application layer (for example, application A) according to the determined first printing level, that is, set the persist.log.tag property. The application layer manages the printing of the upper-layer log according to the set policy. The log printing process calls the process (Logd) that allocates memory for log printing. Logd includes a process (Logreader) that reads logs, a buffer (buffer), and a process (Loglistener) that listens to log printing. Logd triggers the log disk service (Logcat). The Logcat process includes specific disk placement and strategies for controlling disk placement.
[0111] Step 2: After determining the first printing level, set / write a kernel node, which manages the printing of the kernel log through the determined first printing level.
[0112] Exemplarily, when the kernel log is printing, the log will be called to the kernel log printing external interface (printk), and then called to the kernel log printing internal interface (vprintk_store). Printk is the interface exposed by the kernel layer outside the kernel layer, and vprintk_store is the interface within the kernel layer. The kernel node debug / control (debug / control) policy enables the kernel layer to manage the printing of the kernel log according to the determined first print level. After printing, the kernel log can be cached in the ring memory (Log_buff), and the cached kernel log can be subsequently output to the console (console).
[0113] Step 3: After determining the first printing level, the scheduling level of the log disk service corresponding to the first printing level can be determined based on the determined first printing level and the correspondence between the first printing level and the scheduling level of the log disk service, and the determined scheduling level can be set in the disk strategy. The log disk service can be subsequently controlled according to the scheduling level.
[0114] It can be understood that step 1 can trigger step 2, or step 1 and step 2 can be performed simultaneously, or step 1 and step 3 can be performed simultaneously. This application does not limit the execution order of step 1, step 2, and step 3.
[0115] It can also be understood that after the first printing level is determined in method 300, the Figure 5 The process calling relationship between the local layer and the kernel layer of the example.
[0116] Figure 6 This is an application sequence diagram of the log management method provided in an embodiment of the present application.
[0117] For example, Figure 6 As shown, in terms of time sequence, the method 200 or 300 for managing the execution log of the functional module / process at the local layer includes the following steps:
[0118] S601, the initialization module (init) sets the user type (usertype) in the initialization process.
[0119] For example, during the boot process, initialization will be performed. The user type set in the initialization process can be understood as the mode used by the current user. The modes are divided into log version and nolog version. The default printing levels of the log version and the nolog version are different, that is, the subsequently set persistent log level attributes (persist.log.tag) and kernel nodes are different.
[0120] S602, the log printing filter service (xlogfilter_service) module sets persist.log.tag.
[0121] Exemplarily, after S601 is executed, the execution of the run command rc file (hilogcat.rc) is triggered, and the xlogfilter_service module is started to set persist.log.tag. hilogcat.rc defines the log storage service and the triggering conditions for starting the service.
[0122] S603, executing the run command rc file, and writing the kernel node in the kernel layer.
[0123] Exemplarily, after S602 is executed, an operation of writing a kernel node is triggered.
[0124] S604, the kernel node written in the kernel layer controls the printing of the kernel log according to the default printing level.
[0125] The above S601 to S604 are operations performed during the boot process, and the following steps are operations performed after the boot is completed.
[0126] S605, after the boot is complete, the launcher sets the boot_complete attribute to trigger subsequent operations.
[0127] S606, the xlogfilter_service module determines the first printing level and sets persist.log.tag.
[0128] Exemplarily, after S605 is executed, hilogcat.rc will be triggered to start the xlogfilter_service module to determine the first print level and set persist.log.tag. For the method of determining the first print level, please refer to the relevant description in method 200. It can be understood that the persist.log.tag set in S606 is different from the persist.log.tag set in S602. S602 is set according to the default print level, while S606 is set according to the calculated first print level. When the xlogfilter_service module determines the first print level, it needs to obtain behavior data and status parameters from the data acquisition module (such as iware). The behavior data is generated based on user behavior. For the status parameters, please refer to the relevant description in method 200, which will not be repeated here.
[0129] Optionally, if performing CTS, ITS and other tests, the xlogfilter_service module also needs to determine whether to use the first printing level. For specific determination, please refer to the relevant description in method 300. If it is determined to use the first printing level, execute steps S606 to S609. If it is determined to use the default printing level, execute steps S602 to S604.
[0130] S607, run the command rc file to write the kernel node in the kernel layer.
[0131] Exemplarily, after S606 is executed, hilogcat.rc is triggered to execute the operation of writing a kernel node.
[0132] S608: The kernel node written in the kernel layer controls the printing of the kernel log according to the first printing level.
[0133] S609, the printing and storage module manages the printing and storage of the upper-level log according to the determined printing level.
[0134] For example, during the log printing process, the log printing interface will be called, and the printing of the upper log will be managed according to the determined printing level. When the log is subsequently stored on disk, the storage of the printed log can be managed according to the determined storage level. The determined printing level here can be a default printing level or a determined first printing level.
[0135] It should be noted that this application does not limit the execution time of S609. For example, if the default printing level is determined during the boot process, S609 can be executed after S602, and the execution sequence of S609, S603, and S603 is not limited at this time; if the default printing level is determined during the CTS, ITS and other tests after the boot is completed, S609 can be executed after S606. At this time, although S606 determines the first printing level, it is determined not to use the first printing level. At this time, there is no restriction on the execution sequence of S609, S607, and S608; if the first printing level is determined after the boot is completed, and it is determined to use the first printing level, S609 can be executed after S606, and there is no restriction on the execution sequence of S609, S607, and S608.
[0136] It should be understood that the above examples are intended to help those skilled in the art understand the embodiments of the present application, rather than to limit the embodiments of the present application to the specific numerical values or specific scenarios illustrated. Those skilled in the art can obviously make various equivalent modifications or changes based on the above examples, and such modifications or changes also fall within the scope of the embodiments of the present application.
[0137] Figure 7 This is a structural block diagram of a device provided in an embodiment of the present application. For the sake of convenience of explanation, only the parts related to the embodiment of the present application are shown.
[0138] The device 700 is, for example, an electronic device, Figure 7 The device 700 includes: a determination module 701 and a control module 702.
[0139] Among them, the determination module 701 is used to determine whether to adopt the first printing level, and the first printing level is determined based on the CPU load and the IO load; when it is determined to adopt the first printing level, the control module 702 is used to manage the printing of the log according to the first printing level; when it is determined not to adopt the first printing level, the control module 702 is used to manage the printing of the log according to the default printing level.
[0140] In some possible implementations, the first printing level is also determined based on the current number of log print characters and / or the current number of foreground applications.
[0141] In some possible implementations, the first printing level is determined based on y in the following formula:
[0142]
[0143] Among them, L CPU Indicates CPU load, L IO Indicates IO load, N L Indicates the number of characters printed in the current log, N A Indicates the number of current foreground applications.
[0144] In some possible implementations, when 0.2<y≤0.5, the determination module 701 determines the first printing level as W; when 0.5<y≤0.7, the determination module 701 determines the first printing level as E; and when 0.7<y≤1, the determination module 701 determines the first printing level as S.
[0145] In some possible implementations, the determination module 701 is specifically used to: when determining to adopt the first printing level, determine the scheduling level of the log disk service corresponding to the first printing level based on the correspondence between the first printing level and the scheduling level of the log disk service; the control module 702 is specifically used to: control the log disk service according to the scheduling level.
[0146] In some possible implementations, the determination module 701 is specifically configured to: when a universal serial bus (USB) debugging switch is turned off, determine to use the first printing level.
[0147] In some possible implementations, the determination module 702 is specifically configured to: when the USB debugging switch is turned on, determine not to use the first printing level.
[0148] Optionally, the device 700 further includes an acquisition module 703, which is used to acquire CPU load and IO load through a data acquisition module of the framework layer, or to acquire CPU load, IO load and at least one of the following: the number of characters printed in the current log, and the current number of foreground applications.
[0149] In some possible implementations, the log includes a kernel log and an upper-layer log.
[0150] It should be noted that the information interaction, execution process and other contents between the above-mentioned modules are based on the same concept as the method embodiment of the present application. Their specific functions, execution steps, interpretation of terms, associations and technical effects brought about can be found in the method embodiment part and will not be repeated here.
[0151] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into a processing unit, or each unit 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. For example, a "module" can be a software program, a hardware circuit, or a combination of the two to implement the above-mentioned functions. The hardware circuit may include an application specific integrated circuit (ASIC), an electronic circuit, a processor (such as a shared processor, a proprietary processor, or a group processor, etc.) and a memory for executing one or more software or firmware programs, a merged logic circuit, and / or other suitable components that support the described functions.
[0152] Therefore, the modules of each example described in the embodiments of the present application can be implemented with electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present application.
[0153] In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other and are not used to limit the protection scope of this application. The specific working process of the units and modules in the above system can refer to the corresponding process in the above method embodiment, which will not be repeated here.
[0154] It should be understood that the hardware systems, devices and chips in the embodiments of the present application can execute the various methods of the aforementioned embodiments of the present application, that is, the specific working processes of the following various products can refer to the corresponding processes in the aforementioned method embodiments.
[0155] The embodiment of the present application also provides a computer-readable storage medium, in which computer instructions are stored; when the computer-readable storage medium is run on an electronic device, the electronic device executes the method shown above. The computer instructions can 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 can be transmitted from a website, computer, server or data center to another website, 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.) methods. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that contains one or more media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium, or a semiconductor medium (e.g., a solid state disk (SSD)), etc.
[0156] The embodiment of the present application also provides a computer program product including computer instructions, which, when executed on an electronic device, enables the electronic device to execute the technical solution shown above.
[0157] Figure 8 It is a schematic diagram of the structure of a chip provided in an embodiment of the present application. Figure 8 The chip shown can be a general-purpose processor or a dedicated processor. The chip includes a processor 801. The processor 801 is used to support the electronic device to execute the above-mentioned methods, such as method 200 and method 300.
[0158] Optionally, the chip further includes a transceiver 802, and the transceiver 802 is used to accept the control of the processor 801 and to support the electronic device to execute the technical solution shown above.
[0159] Optional, Figure 8 The chip shown may further include: a storage medium 803 .
[0160] It should be noted that Figure 8 The chip shown can be implemented using the following circuits or devices: one or more field programmable gate arrays (FPGAs), programmable logic devices (PLDs), controllers, state machines, gate logic, discrete hardware components, any other suitable circuits, or any combination of circuits that can perform the various functions described throughout this application.
[0161] The electronic devices, devices, computer storage media, computer program products, and chips provided in the above-mentioned embodiments of the present application are all used to execute the methods provided above. Therefore, the beneficial effects that can be achieved can refer to the corresponding beneficial effects of the methods provided above, and will not be repeated here.
[0162] It should be understood that the above is only to help those skilled in the art to better understand the embodiments of the present application, rather than to limit the scope of the embodiments of the present application. According to the above examples given, those skilled in the art can obviously make various equivalent modifications or changes. For example, some steps in each embodiment of the above detection method may be unnecessary, or some steps may be newly added. Or a combination of any two or any multiple embodiments of the above. Such modifications, changes or combined schemes also fall within the scope of the embodiments of the present application.
[0163] It should also be understood that the above description of the embodiments of the present application focuses on emphasizing the differences between the various embodiments. The same or similar points that are not mentioned can be referenced to each other. For the sake of brevity, they will not be repeated here.
[0164] It should also be understood that 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.
[0165] It should also be understood that in the embodiments of the present application, "pre-setting" and "pre-definition" can be achieved by pre-saving corresponding codes, tables or other methods that can be used to indicate relevant information in a device (for example, including an electronic device), and the present application does not limit its specific implementation method.
[0166] It should also be understood that the division of the methods, situations, categories and embodiments in the embodiments of the present application is only for the convenience of description and should not constitute a special limitation. The features of various methods, categories, situations and embodiments can be combined without contradiction.
[0167] It should also be understood that in the various embodiments of the present application, unless otherwise specified or there is a logical conflict, the terms and / or descriptions between different embodiments are consistent and can be referenced to each other, and the technical features in different embodiments can be combined to form new embodiments according to their internal logical relationships.
[0168] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A log management method, characterized in that: The method is applied to an electronic device, comprising: Determine whether to adopt a first printing level, wherein the first printing level is determined based on a CPU load and an I / O load; When it is determined to adopt the first printing level, managing the printing of the log according to the first printing level; When it is determined not to adopt the first printing level, the printing of the log is managed according to a default printing level.
2. The method according to claim 1, characterized in that The first printing level is also determined based on the current number of log printing characters and / or the current number of foreground applications.
3. The method according to claim 1 or 2, characterized in that: The first printing level is determined based on y in the following formula: Among them, L CPU Indicates the CPU load, L IO represents the IO load, N L Indicates the number of characters printed in the current log, N A Indicates the number of current foreground applications.
4. The method according to claim 3, characterized in that When 0.2<y≤0.5, the first printing level is W, when 0.5<y≤0.7, the first printing level is E, and when 0.7<y≤1, the first printing level is S.
5. The method according to any one of claims 1 to 4, characterized in that The method further comprises: When it is determined to adopt the first printing level, determining the scheduling level of the log storage service corresponding to the first printing level according to the first printing level and the correspondence between the first printing level and the scheduling level of the log storage service; The log storage service is controlled according to the scheduling level.
6. The method according to any one of claims 1 to 5, characterized in that The determining whether to adopt the first printing level includes: When the USB debugging switch is turned off, it is determined to adopt the first printing level.
7. The method according to any one of claims 1 to 5, characterized in that The determining whether to adopt the first printing level includes: When the USB debugging switch is turned on, it is determined that the first printing level is not adopted.
8. The method according to any one of claims 1 to 7, characterized in that The method further comprises: The CPU load and the IO load are obtained through a data acquisition module of the framework layer, or the CPU load, the IO load and at least one of the following items are obtained: the number of characters printed in the current log, and the number of current foreground applications.
9. The method according to any one of claims 1 to 8, characterized in that The logs include kernel logs and upper layer logs.
10. A log management device, characterized in that: Including determination module and control module: The determination module is used to determine whether to adopt a first printing level, wherein the first printing level is determined based on a CPU load and an IO load; When it is determined to adopt the first printing level, the control module is used to manage the printing of the log according to the first printing level; When it is determined not to adopt the first printing level, the control module is used to manage the printing of the log according to a default printing level.
11. An electronic device, characterized in that: The method comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method according to any one of claims 1 to 9 when executing the computer program.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor is caused to perform the method according to any one of claims 1 to 9.
13. A computer program product, characterized in that The computer program product comprises: a computer program code, and when the computer program code is executed by an electronic device, the electronic device executes the method according to any one of claims 1 to 9.
Citation Information
Cited By
Boot full-amount log writing method, computer device, and computer program product
CN122673068A
