Resource management method and related device
By allocating memory to the process of the electronic device and recording resource information according to process status changes, the problem in the existing technology that the log takes up a large amount of memory and the difficulty of locating the problem is solved, and more accurate resource information acquisition and more efficient problem locating are achieved. .
Patent Information
- Application Number
- CN202311691227.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-07
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2043-12-07
AI Technical Summary
During the operation of electronic devices, performance problems such as interface lag and high temperature may occur. The existing technology analyzes the location problems through log analysis, but the log occupies a large amount of memory, which increases the difficulty of developers' location problems.
By allocating memory to the process, recording the resource information of the process, and recording the resource information into different memory intervals according to the time when the process status changes, it is convenient for developers to obtain accurate resource information.
It reduces the difficulty for developers to locate problems and improves the efficiency of problem location by obtaining more accurate resource information.
Smart Images

Figure CN118467147B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of terminal technology, and in particular to a resource management method and related devices. Background Art
[0002] During operation, electronic devices may experience performance issues such as interface freezes and high temperatures. Developers can analyze and locate performance issues based on the logs printed by the electronic devices.
[0003] However, logs occupy a large amount of memory, which increases the difficulty for developers to locate problems. Summary of the Invention
[0004] The resource management method and related apparatus provided in the embodiments of the present application enable an electronic device to allocate memory to a process to store the process's resource information. This memory includes multiple memory intervals. When the running state of a process changes, the electronic device can record the process's resource information in different memory intervals based on the time of the process state change. This allows developers to obtain more accurate resource information from the corresponding memory interval based on the time of the change, thereby reducing the difficulty for developers to locate problems.
[0005] In a first aspect, the resource management method provided by the embodiments of the present application includes:
[0006] At a first moment, the first process runs in the foreground, the second process is awakened, and the resource information of the second process is saved to the first area of the first memory. The resource information includes information used to reflect the running status of the process. At a second moment, the second process switches to the foreground, and the resource information of the second process is saved to the second area of the first memory, and the resource information of the first process is saved to the third area of the second memory. The second area is the same as or different from the first area. At a third moment, the first process switches to the foreground, and the resource information of the second process is saved to the fourth area of the first memory. The resource information of the first process is saved to the fifth area of the second memory. The fourth area is the same as or different from the second area, and the fifth area is the same as or different from the third area. In this way, the electronic device can save the resource information of different processes in different memory areas, making it easier for developers to obtain the resource information corresponding to a certain process when locating problems.
[0007] In one possible implementation, the first memory has N1 memory areas, and the second memory has N2 memory areas, where N1 and N2 are both positive integers. The specific storage location of the first process's resource information in the N2 memory areas is related to the time when the first process's state changes; the specific storage location of the second process's resource information in the N1 memory areas is related to the time when the second process's state changes. In this way, by determining the storage location of a process's resource information in the memory areas based on the time when the process's state changes, resource information for a specific time period can be obtained more conveniently and accurately.
[0008] In one possible implementation, saving the resource information of the second process to the first area of the first memory includes: saving the resource information of the second process to the first area of the first memory based on the first time and a preset mapping rule, wherein the preset mapping rule includes a mapping rule between time and each memory area in the first memory. In this way, developers can more accurately obtain process information related to the fault problem, thereby facilitating the developer's fault location and analysis.
[0009] In one possible implementation, based on a first moment and a preset mapping rule, the resource information of the second process is stored in a first area of the first memory, including: right-shifting the first moment by L bits to obtain the ID of the first unit information, where L is a positive integer; dividing the ID of the first unit information by N to obtain a modulo value M1; and storing the resource information of the second process in the M1th memory area of the first memory based on the ID of the first unit information. Thus, by selecting reasonable values for L and N, the amount of process resource information stored in the memory can be kept within a reasonable range, reducing the probability of losing fault information. It can also be ensured that the amount of process resource information stored in the memory is not excessive, reducing the pressure placed on system memory by the stored information.
[0010] In one possible implementation, before saving the resource information of the second process to the first area of the first memory based on the ID of the first unit information, the method further includes: if the ID of the unit information of the existing data in the first area is different from the ID of the first unit information, clearing the existing data in the first area. In this way, the electronic device first clears the previously saved content before saving the new process resource information, thereby continuously recording the process resource information of the recent period.
[0011] In one possible implementation, a target queue exists in the electronic device. Before saving the resource information of the second process to the first area of the first memory, the method further includes: generating a task for the second process in the target queue and saving the process identifier (PID) of the second process; and saving the resource information of the second process to the first area of the first memory includes: instructing the kernel layer to save the resource information of the second process to the first area of the first memory based on the task of the second process. In this way, by collecting statistics on the resource information of the process and feeding the collected resource information back to the upper-layer application, developers can analyze and locate problems based on the resource information.
[0012] In one possible implementation, if the number of process tasks in the target queue is less than or equal to a preset value, before generating a task for the second process in the target queue, the process further includes: if the number of process tasks in the target queue is equal to the preset value, stopping one or more target processes in the target queue and clearing the resource information in the memory corresponding to the one or more target processes. In this way, timely clearing of process tasks tracked in the TaskQueue queue can provide more cache space for new tracked tasks, thereby reducing the risk of data loss and reducing the occurrence of lags during task processing.
[0013] In one possible implementation, the method further includes: obtaining resource information of the second process during the first time period from the first memory. In this way, when a malfunction such as ANR or freeze occurs in the electronic device, the resource information of the process can be obtained from the first memory, thereby facilitating problem location by the developer.
[0014] In one possible implementation, before obtaining resource information for the second process within the first time period from the first memory, the following steps may be performed: right-shifting the start time of the first time period by L bits to obtain the ID of the second unit information; dividing the ID of the second unit information by N and taking the modulus to obtain a second value, M2; right-shifting the end time of the first time period by L bits to obtain the ID of the third unit information; dividing the ID of the third unit information by N and taking the modulus to obtain a third value, M3; obtaining resource information for the second process within the first time period from the first memory, including: obtaining resource information for the second process from the M2th to M3th memory areas in the first memory; and merging resource information from the M2th to M3th memory areas. In this way, the electronic device will select and obtain resource information for the process from N buckets, thereby obtaining more accurate resource information with smaller granularity, making it easier for developers to locate problems.
[0015] In one possible implementation, the resource information includes one or more of the following: the PID of the process, the total time the process is in the Runnable state, the number of times the process is in the Runnable state, the start time of the longest time the process is in the Runnable state, the end time of the longest time the process is in the Runnable state, the total time the process is in the Sleep state, the number of times the process is in the Sleep state, the start time of the longest time the process is in the Sleep state, the end time of the longest time process 1 is in the Sleep state, the total time the process is in the D state, the number of times the process is in the D state, the start time of the longest time the process is in the D state, the end time of the longest time the process is in the D state, the total time the process is in the Running state, the time the process runs on each core of the CPU, or the time the process runs on each frequency band of each core of the CPU. In this way, recording the resource information of the process in the memory can understand various status data during the process operation, thereby facilitating developers to locate and solve problems and improve user experience.
[0016] In a possible implementation, merging resource information from the M2th memory area to the M3th memory area includes one or more of the following: summing the total time that the process in the M2th memory area to the M3th memory area is in the Runnable state, summing the total time that the process in the M2th memory area to the M3th memory area is in the Sleep state, summing the total time that the process in the M2th memory area to the M3th memory area is in the D state, summing the total time that the process in the M2th memory area to the M3th memory area is in the Running state, summing the number of times the process in the M2th memory area to the M3th memory area is in the Runnable state, summing the number of times the process in the M2th memory area to the M3th memory area is in the Sleep state, and summing the total time that the process in the M2th memory area to the M3th memory area is in the D state. The electronic device can also calculate the sum of the number of times a process in the M2th to M3th memory areas is in the D state, the sum of the number of times a process in the M2th to M3th memory areas is in the Running state, the maximum value of the longest time a process in the M2th to M3th memory areas is in the Runnable state, the maximum value of the longest time a process in the M2th to M3th memory areas is in the Sleep state, the maximum value of the longest time a process in the M2th to M3th memory areas is in the D state, the sum of the time a process in the M2th to M3th memory areas runs on each CPU core, or the sum of the time a process in the M2th to M3th memory areas runs on each frequency band of each CPU core. In this way, the electronic device can continuously record process resource information for the current period. Developers can more accurately obtain process information related to the fault problem, making it easier for developers to locate and analyze the fault problem.
[0017] In one possible implementation, obtaining resource information of the second process within the first time period from the first memory includes: obtaining resource information of the second process within the first time period from the first memory when the target queue includes the PID of the second process. In this way, if the second process is not being tracked, resource information of the second process within the first time period may not be obtained from the first memory, thereby reducing code execution logic, reducing computing power of the electronic device, and improving computing efficiency.
[0018] In one possible implementation, obtaining resource information of the second process within the first time period from the first memory includes obtaining resource information of the second process within the first time period from the first memory when the start time of the first time period is earlier than the time when the task generating the second process is generated. In this way, if the time intervals do not match, the resource information of the second process is not queried, thereby reducing code execution logic and computing power of the electronic device.
[0019] In one possible implementation, obtaining resource information of the second process within the first time period from the first memory includes: when an application no response (ANR) or a freeze event occurs, obtaining resource information of the second process within the first time period from the first memory. In this way, when an ANR or performance freeze problem occurs in an electronic device, the electronic device can detect the ANR or performance freeze event and obtain resource information of the second process within the first time period from the first memory, thereby facilitating the developer to locate and analyze the problem.
[0020] In a second aspect, an embodiment of the present application provides a resource management device, which may be an electronic device or a chip or chip system within an electronic device. The device may include a processing unit. The processing unit is used to implement any processing-related method performed by the electronic device in the first aspect or any possible implementation of the first aspect. When the device is an electronic device, the processing unit may be a processor. The device may also include a storage unit, which may be a memory. The storage unit is used to store instructions, and the processing unit executes the instructions stored in the storage unit to enable the electronic device to implement the method described in the first aspect or any possible implementation of the first aspect. When the device is a chip or chip system within an electronic device, the processing unit may be a processor. The processing unit executes the instructions stored in the storage unit to enable the electronic device to implement the method described in the first aspect or any possible implementation of the first aspect. The storage unit may be a storage unit within the chip (e.g., a register, a cache, etc.) or a storage unit within the electronic device located outside the chip (e.g., a read-only memory, a random access memory, etc.).
[0021] Exemplarily, the processing unit is configured to run a first process in the foreground, wake up a second process, and save resource information of the second process to a first area of a first memory. The processing unit is further configured to run the second process in the foreground, save resource information of the second process to a second area of the first memory, and save resource information of the first process to a third area of the second memory. Specifically, the processing unit is further configured to run the first process in the foreground, save resource information of the second process to a fourth area of the first memory, and save resource information of the first process to a fifth area of the second memory.
[0022] In one possible implementation, the specific storage location of the resource information of the first process in the N2 memory areas is related to the time when the state of the first process changes; the specific storage location of the resource information of the second process in the N1 memory areas is related to the time when the state of the second process changes.
[0023] In a possible implementation, the processing unit is configured to save the resource information of the second process to a first area of the first memory according to the first moment and a preset mapping rule.
[0024] In one possible implementation, the processing unit is used to right shift L bits at the first moment to obtain the ID of the first unit information, and is also used to divide the ID of the first unit information by N and obtain the modulus to obtain the first value M1, and is specifically used to save the resource information of the second process to the M1th memory area of the first memory based on the ID of the first unit information.
[0025] In a possible implementation, the processing unit is configured to clear existing data in the first area.
[0026] In one possible implementation, the processing unit is used to generate a task of the second process in the target queue and save the process identifier PID of the second process. It is also used to instruct the kernel layer to save the resource information of the second process to the first area of the first memory based on the task of the second process.
[0027] In a possible implementation, the processing unit is configured to stop one or more target processes in a target queue and clean up resource information in a memory corresponding to the one or more target processes.
[0028] In a possible implementation, the processing unit is configured to obtain resource information of the second process within a first time period from the first memory.
[0029] In one possible implementation, the processing unit is configured to right-shift the start time of the first time period by L bits to obtain an ID for the second unit information, and perform a modulo N division on the ID of the second unit information to obtain a second value M2. The processing unit is further configured to right-shift the end time of the first time period by L bits to obtain an ID for the third unit information, and perform a modulo N division on the ID of the third unit information to obtain a third value M3. The processing unit is further configured to obtain resource information of the second process from the M2th to M3th memory regions in the first memory; and merge the resource information from the M2th to M3th memory regions.
[0030] In one possible implementation, the resource information includes one or more of the following: the PID of the process, the total time the process is in the Runnable state, the number of times the process is in the Runnable state, the start time of the longest time the process is in the Runnable state, the end time of the longest time the process is in the Runnable state, the total time the process is in the Sleep state, the number of times the process is in the Sleep state, the start time of the longest time the process is in the Sleep state, the end time of the longest time process 1 is in the Sleep state, the total time the process is in the D state, the number of times the process is in the D state, the start time of the longest time the process is in the D state, the end time of the longest time the process is in the D state, the total time the process is in the Running state, the time the process runs on each core of the central processing unit CPU, or the time the process runs on each frequency band of each core of the CPU.
[0031] In one possible implementation, the processing unit is used to sum the total time that the process in the M2th memory area to the M3th memory area is in the Runnable state, sum the total time that the process in the M2th memory area to the M3th memory area is in the Sleep state, sum the total time that the process in the M2th memory area to the M3th memory area is in the D state, sum the total time that the process in the M2th memory area to the M3th memory area is in the Running state, sum the number of times the process in the M2th memory area to the M3th memory area is in the Runnable state, sum the number of times the process in the M2th memory area to the M3th memory area is in the Sleep state, and sum the total time that the process in the M2th memory area to the M3th memory area is in the D state. Sum the number of times the process is in the D state, sum the number of times the process is in the Running state from the M2th memory area to the M3th memory area, maximize the longest time the process is in the Runnable state from the M2th memory area to the M3th memory area, maximize the longest time the process is in the Sleep state from the M2th memory area to the M3th memory area, maximize the longest time the process is in the D state from the M2th memory area to the M3th memory area, sum the time that the processes in the M2th memory area to the M3th memory area are running on each core of the CPU, or sum the time that the processes in the M2th memory area to the M3th memory area are running in each frequency band of each core of the CPU.
[0032] In a possible implementation, the processing unit is configured to obtain resource information of the second process within a first time period from the first memory when the target queue includes the PID of the second process.
[0033] In a possible implementation, the processing unit is configured to obtain resource information of the second process in the first time period from the first memory when a start time of the first time period is earlier than a time of generating a task of the second process.
[0034] In one possible implementation, the processing unit is configured to obtain resource information of the second process within a first time period from the first memory when an application no response (ANR) or freeze event occurs.
[0035] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor and a memory, wherein the memory is used to store code instructions, and the processor is used to run the code instructions to execute the method described in the first aspect or any possible implementation of the first aspect.
[0036] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a computer program or instruction is stored. When the computer program or instruction is run on a computer, the computer executes the method described in the first aspect or any possible implementation of the first aspect.
[0037] In a fifth aspect, an embodiment of the present application provides a computer program product comprising a computer program, which, when the computer program runs on a computer, enables the computer to execute the method described in the first aspect or any possible implementation of the first aspect.
[0038] In a sixth aspect, the present application provides a chip or chip system, comprising at least one processor and a communication interface, wherein the communication interface and the at least one processor are interconnected via a line, and the at least one processor is configured to execute a computer program or instruction to perform the method described in the first aspect or any possible implementation of the first aspect. The communication interface in the chip may be an input / output interface, a pin, or a circuit.
[0039] In one possible implementation, the chip or chip system described above in this application further includes at least one memory, in which instructions are stored. The memory may be a storage unit within the chip, such as a register, a cache, etc., or a storage unit of the chip (e.g., a read-only memory, a random access memory, etc.).
[0040] It should be understood that the second to sixth aspects of the present application correspond to the technical solutions of the first aspect of the present application, and the beneficial effects achieved by each aspect and the corresponding feasible implementation methods are similar and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application;
[0042] Figure 2 A schematic diagram of the software structure of an electronic device provided in an embodiment of the present application;
[0043] Figure 3 A software module interaction diagram provided in an embodiment of the present application;
[0044] Figure 4 A schematic diagram of process switching and process wakeup provided in an embodiment of the present application;
[0045] Figure 5 A flowchart of an eBPF collection service maintenance process information provided in an embodiment of the present application;
[0046] Figure 6 A schematic diagram of obtaining process information based on time interval segments provided in an embodiment of the present application;
[0047] Figure 7 A flowchart of an eBPF collection service for obtaining resource scheduling information provided in an embodiment of the present application;
[0048] Figure 8 A schematic diagram of a resource management method provided in an embodiment of the present application;
[0049] Figure 9 A schematic diagram of the structure of a chip provided in an embodiment of the present application. DETAILED DESCRIPTION
[0050] To facilitate a clear description of the technical solutions of the embodiments of the present application, some of the terms and technologies involved in the embodiments of the present application are briefly introduced below:
[0051] 1. Process state: used to indicate some states during the process execution. For example, the process state can include Running state, Runnable state, Sleep state and D state.
[0052] Running state: The process is in the running state.
[0053] Runnable state: The process has the conditions to run and is waiting in the run queue. The Runnable state can also be called the Ready state.
[0054] Sleep state: The process is in sleep state. A process in sleep state can respond to system interrupts, thereby waking up the process. Sleep state is also called S state.
[0055] D state: The process is in an uninterruptible, blocked state. A process in D state does not respond to interrupts and cannot be awakened. A process can be awakened when certain conditions occur; otherwise, it remains in a waiting state. D state is also called deep sleep.
[0056] In the embodiments of the present application, a process may also include a thread TID within the process, or a thread may also have various states of the aforementioned process, and a process identifier (PID) may also be understood as a thread identifier (TID). For ease of description, the following descriptions will be made using processes and PIDs.
[0057] 2. eBPF: Extended Berkeley Packet Filter (eBPF). eBPF can be understood as a mechanism that allows a small program to run when various kernel events and application events occur. This makes the kernel programmable and allows developers to customize business-related plug-ins to solve corresponding problems.
[0058] 3. Central processing unit (CPU) core: The CPU core can include large cores, medium cores, and small cores. Among them, large cores can refer to higher-performance cores, which are the main computing power of electronic devices. Medium cores can also be higher-performance cores, but the frequency of medium cores is lower than that of large cores. In some scenarios, medium cores can also be called large cores. Small cores can refer to cores with lower power consumption for energy saving purposes. They are used for running electronic devices under low load. The frequency of small cores is lower than that of medium cores.
[0059] The frequency point can also be understood as the operating frequency of the core. In some implementations, the frequency point can be classified differently. For example, taking the frequency point of the large core as an example, the frequency point of the large core can include low frequency, medium-low frequency, medium frequency, medium-high frequency, and high frequency. Exemplarily, the low frequency of the large core can include 590MHz, 720MHz, 860MHz, or 990MHz, etc., the medium-low frequency of the large core can include 1130MHz, 1240MHz, 1360MHz, 1470MHz, etc., the medium frequency of the large core can include 1590MHz, 1700MHz, 1840MHz, 1970MHz, etc., the medium-high frequency of the large core can include 2090MHz, 2220MHz, 2340MHz, 2470MHz, etc., and the high frequency of the large core can include 2590MHz, 2720MHz, 2840MHz, 2950MHz, 3180MHz, etc. It is understandable that there can be other classification standards for the frequency point, and the specific classification of the frequency point type is not limited in the embodiment of this application.
[0060] 4. Terminology
[0061] In the embodiments of this application, terms such as "first" and "second" are used to distinguish between identical or similar items with substantially the same functions and effects. For example, the terms "first chip" and "second chip" are used solely to distinguish between different chips and do not define their order. Those skilled in the art will understand that terms such as "first" and "second" do not define the quantity or execution order, and do not necessarily define differences.
[0062] It should be noted that in the embodiments of this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described in this application as "exemplary" or "for example" should not be construed as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.
[0063] In the embodiments of the present application, "at least one" refers to one or more, and "more" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: the existence of A alone, the existence of A and B at the same time, and the existence of B alone, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, a--c, bc, or abc, where a, b, c can be single or multiple.
[0064] 5. Electronic devices
[0065] The electronic device of the embodiment of the present application may also be a terminal device in any form. For example, the electronic device may include: a mobile phone, a tablet computer, a PDA, a laptop computer, a mobile internet device (MID), a wearable device, a virtual reality (VR) device, an augmented reality (AR) device, a wireless terminal in industrial control, a wireless terminal in self-driving, a wireless terminal in remote medical surgery, a wireless terminal in a smart grid, a wireless terminal in transportation safety, a wireless terminal in a smart city, a wireless terminal in a smart home, a cellular phone, a cordless phone, a session initiation protocol (SIP) phone, a wireless local loop (WLL) station, a personal digital assistant (PDA), a handheld device with wireless communication function, a computing device or other processing device connected to a wireless modem, an in-vehicle device, a wearable device, an electronic device in a 5G network or a future evolved public land mobile communication network (PLMN) Mobile network, PLMN) and other electronic devices, and the embodiments of the present application are not limited to this.
[0066] As an example and not a limitation, in the embodiments of the present application, the electronic device may also be a wearable device. Wearable devices may also be referred to as wearable smart devices, which are a general term for wearable devices that are intelligently designed and developed using wearable technology for daily wear, such as glasses, gloves, watches, clothing, and shoes. A wearable device is a portable device that is worn directly on the body or integrated into the user's clothes or accessories. Wearable devices are not only hardware devices, but also achieve powerful functions through software support, data interaction, and cloud interaction. Broadly speaking, wearable smart devices include those that are fully functional, large in size, and can achieve complete or partial functions without relying on smartphones, such as smart watches or smart glasses, as well as those that only focus on a certain type of application function and need to be used in conjunction with other devices such as smartphones, such as various smart bracelets and smart jewelry for vital sign monitoring.
[0067] In addition, in the embodiment of the present application, the electronic device can also be an electronic device in the Internet of Things (IoT) system. IoT is an important part of the future development of information technology. Its main technical feature is to connect objects to the network through communication technology, thereby realizing an intelligent network of human-machine interconnection and object-to-object interconnection.
[0068] The electronic devices in the embodiments of the present application may also be referred to as: user equipment (UE), mobile station (MS), mobile terminal (MT), access terminal, user unit, user station, mobile station, mobile station, remote station, remote terminal, mobile device, user terminal, terminal, wireless communication equipment, user agent or user device, etc.
[0069] In the embodiments of the present application, the electronic device or each network device includes a hardware layer, an operating system layer running on the hardware layer, and an application layer running on the operating system layer. The hardware layer includes hardware such as a CPU, a memory management unit (MMU), and memory (also known as main memory). The operating system can be any one or more computer operating systems that implement business processing through processes, such as a Linux operating system, a Unix operating system, an Android operating system, an iOS operating system, or a Windows operating system. The application layer includes applications such as browsers, address books, word processing software, and instant messaging software.
[0070] For example, Figure 1 A schematic structural diagram of an electronic device is shown.
[0071] The electronic device 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, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0072] It is understood that the structures illustrated in the embodiments of the present invention do not constitute specific limitations on the electronic device. In other embodiments of the present application, the electronic device may include more or fewer components than shown, or may combine or separate certain components, or arrange the components differently. The components shown in the diagram may be implemented in hardware, software, or a combination of software and hardware.
[0073] 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 processing unit (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). The different processing units may be independent devices or integrated into one or more processors. The controller may generate operation control signals based on instruction opcodes and timing signals to control instruction fetching and execution.
[0074] Processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in processor 110 is a cache memory. This memory can store instructions or data that have just been used or are being recycled by processor 110. If processor 110 needs to use the same instruction or data again, it can directly access the memory. This avoids duplicate accesses, reduces processor 110 latency, and thus improves system efficiency.
[0075] It is understood that the interface connection relationship between the modules illustrated in the embodiments of the present invention is only for illustrative purposes and does not constitute a structural limitation on the electronic device. In other embodiments of the present application, the electronic device may also adopt different interface connection methods from the above embodiments, or a combination of multiple interface connection methods.
[0076] The internal memory 121 can be used to store computer executable program code, and the executable program code includes instructions. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system, at least one application required for a function, etc. The data storage area can store data created during the use of the electronic device, etc. 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 by running instructions stored in the internal memory 121 and / or instructions stored in a memory provided in the processor.
[0077] Figure 2 This is a block diagram of the software structure of the electronic device in an embodiment of the present application. The layered architecture divides the software into several layers, each with a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into five layers: the application layer, the application framework layer, the Android runtime and system library, the hardware abstraction layer (HAL), and the kernel layer.
[0078] The application layer can also be called the application layer, which can include a series of application packages. Figure 2 As shown, the application package can include applications such as phone, music, calendar, camera, game, memo, video, etc. Applications can include system applications and third-party applications.
[0079] The application framework layer, also known as the Framework layer, provides an application programming interface (API) and programming framework for applications in the application layer. The Framework layer may include some predefined functions.
[0080] like Figure 2 As shown, the Framework layer may include the activity manager ActivityManger, eBPF collection service, notification manager, content provider, and view system.
[0081] ActivityManager can be used to manage the application process. For example, ActivityManager can allocate memory and resources to the process, manage the life cycle of the process, and kill unnecessary processes to release resources.
[0082] The eBPF collection service can be used to collect process resource information during the application's operation, making it easier for developers to analyze and locate problems based on the process's resource information. For a detailed description of the eBPF collection service, please refer to Figure 3 The description of the interaction between software modules in the corresponding embodiments will not be repeated here.
[0083] The Android runtime includes the core library and the virtual machine. The Android runtime is responsible for controlling and managing the Android system.
[0084] The core library consists of two parts: one is the function that needs to be called by the Java language, and the other is the Android core library.
[0085] The application layer and framework layer run in a virtual machine. The virtual machine executes the Java files in the application and framework layers as binary files. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection. For example, in the embodiments of the present application, the virtual machine can be used to perform functions such as waking up processes, switching between processes, and collecting process resource information.
[0086] The system library can also be called the Native layer. The Native layer can include multiple functional modules, such as the media library, function library, and graphics processing library.
[0087] The Hardware Abstraction Layer (HAL) is an abstract structure between the kernel layer and the Android runtime. It encapsulates hardware drivers and provides a unified interface for upper-layer applications to call.
[0088] The kernel layer is the layer between hardware and software. The kernel layer may include display driver, camera driver, audio driver, battery driver, Bluetooth driver, and CPU driver.
[0089] It should be noted that the embodiments of the present application are only illustrated using the Android system as an example. In other operating systems (such as Windows system, IOS system, etc.), as long as the functions implemented by each functional module are similar to those in the embodiments of the present application, the solutions of the present application can also be implemented.
[0090] During operation, electronic devices may experience performance issues such as interface freezes and high temperatures. Developers can analyze and locate performance issues based on the logs printed by the electronic devices.
[0091] In some implementations, the electronic device can collect logs using the performance analysis tool Systrace. The logs collected by the Systrace tool may include system resource usage information and information about functions called during application process execution. The system resource usage information may include CPU resource usage and memory usage.
[0092] However, logs generated by Systrace tools consume a large amount of memory. For example, a 10-second log collected by Systrace requires over 100 megabytes (MB) of space, increasing the load on electronic devices and impacting their performance and power consumption. Furthermore, the logs collected by Systrace are streamed, making it impossible to obtain resource statistics and analysis results, making it more difficult for developers to locate issues.
[0093] In other implementations, electronic devices can use system resource pressure information (PSI) monitoring to obtain information about their resource pressure status. For example, this information may include CPU usage and memory usage. However, PSI only measures the load of the electronic device and cannot capture information about the functions called during runtime by application processes, making it more difficult for developers to identify issues.
[0094] In view of this, the resource management method provided in the embodiments of the present application allows an electronic device to allocate memory to a process to store the process's resource information. This memory includes multiple memory intervals. When the running state of a process changes, the electronic device can record the process's resource information in different memory intervals based on the time of the process state change. This allows developers to obtain more accurate resource information from the corresponding memory interval based on the time of the change, thereby reducing the difficulty for developers to locate problems.
[0095] Figure 3A software module interaction diagram of the resource management method provided in an embodiment of the present application is shown.
[0096] In a possible implementation, the electronic device may include (1) a log statistics module and (2) a log collection service.
[0097] The log statistics module collects statistics on system resources and runtime application resource information when key events occur. The log collection service can feed this statistical resource information back to upper-layer applications, allowing developers to analyze and locate issues based on this resource information.
[0098] (1) Log statistics module.
[0099] The log statistics module may include an eBPF plug-in, which can also be understood as an eBPF program. The eBPF plug-in may include a process switching plug-in sched_switch, a process wakeup plug-in sched_wakeup, and a CPU frequency statistics plug-in power_cpu_freq.
[0100] The sched_switch plug-in can be used to record resource information of each process when switching between processes. The sched_switch plug-in can include functions such as get_time to get time, save_state to save state, and save_info to save information.
[0101] The sched_wakeup plugin can be used to record process resource information when the process is woken up. The sched_wakeup plugin can include functions such as get_time to get the time, save_state to save the state, and save_info to save the information.
[0102] The power_cpu_freq plugin records resource information when the frequency of each CPU core changes. The power_cpu_freq plugin includes functions such as get_cpu to obtain CPU resources, get_cluster to obtain CPU cluster information, and save_req to save frequencies.
[0103] For example, Figure 4 A schematic diagram showing inter-process switching and process awakening.
[0104] (1) Phase 1:
[0105] Before process 1 switches to process 2, process 1 can be in the Running state. After process 2 is awakened, process 2 can be in the Runnable state.
[0106] In the first stage, the electronic device can obtain the time when process 2 is awakened through the get_time function in the sched_wakeup plug-in, and can also save the Runnable state of process 2 through the save_state function.
[0107] (2) Phase 2:
[0108] When process 1 switches to process 2, process 1 can be in the Runnable state, the S state, or the D state. Process 2 can be in the Running state. That is, in one possible implementation, process 1 can remain in the Runnable state from the time process 1 switches to process 2 until process 2 switches to process 1. In another possible implementation, process 1 can be in the S state or the D state when switching to process 2. After process 1 is awakened, it can remain in the Runnable state before process 2 switches to process 1.
[0109] In the second stage, the electronic device can obtain the time when process 1 switches to process 2 through the get_time function in the sched_switch plug-in, and can also save the Runnable state, S state or D state of process 1 and the Running state of process 2 through the save_state function.
[0110] If process 1 is awakened, the electronic device can obtain the time when process 1 is awakened through the get_time function in the sched_wakeup plug-in, and can also save the Runnable state of process 1 through the save_state function.
[0111] In addition, the electronic device can obtain information such as the duration of the process in each state and the core ID of the CPU running the process. For example, the core ID of the CPU can be identified as cpu_id, and this information can also be saved through the save_info function.
[0112] (2) Phase 3:
[0113] When process 2 switches process 1, process 1 can be in the Running state, and process 2 can be in the Runnable state, the S state, or the D state.
[0114] In stage three, the electronic device can obtain the time when process 2 switches to process 1 through the get_time function in the sched_switch plug-in, and can also save the Running state of process 1 and the Runnable state, S state or D state of process 2 through the save_state function.
[0115] In addition, during the operation of the electronic device, the electronic device can also record resource information when the frequency of each CPU core changes through the power_cpu_freq plug-in.
[0116] For example, a CPU including 4 small cores, 3 medium cores, and 1 large core is used for description. For example, cpu_id=0, cpu_id=1, cpu_id=2, or cpu_id=3 are the IDs of the small cores, cpu_id=4, cpu_id=5, or cpu_id=6 are the IDs of the medium cores, and cpu_id=7 is the ID of the large core.
[0117] It is understandable that when the frequency of the small core with cpu_id=0 changes, the frequency of the small cores with cpu_id=1, cpu_id=2, and cpu_id=3 will also change accordingly. For example, when the frequency of the small core with cpu_id=0 increases from 0.8 GHz to 1 GHz, the frequency of the small cores with cpu_id=1, cpu_id=2, and cpu_id=3 will also increase from 0.8 GHz to 1 GHz. The electronic device can obtain the frequency information of the small core with cpu_id=0 through the get_cpu function in the power_cpu_freq plug-in, and can also obtain the frequency information of the small cores with cpu_id=1, cpu_id=2, and cpu_id=3 through the get_cluster function, and save the frequency information through the save_req function.
[0118] The code files of the eBPF plugin described above can be stored in the map collection res_maps. After compilation, a binary file can be generated. For example, the binary file may include resource.o, and the storage path may include / system / etc / bpf / . It is understood that the specific naming and file storage path of the binary file are not limited in this embodiment of the application. The electronic device can load the binary file of the eBPF plugin into the BPF instruction set BPF_Code in the kernel through the BPF loader BpfLoader.
[0119] The kernel of an electronic device may include the eBPF plugin's Verifier, the eBPF plugin's Just-in-time Compiler (JIT), and the kernel's native code, NativeCode. The Verifier can be used to verify the security of the eBPF plugin code, ensuring that the eBPF plugin does not crash or damage the kernel. The JIT can be used to compile the eBPF bytecode (BPF_Code) into machine instructions that the electronic device can execute, allowing for more efficient execution within the kernel.
[0120] (2) Log collection service.
[0121] The log collection service can also be called the eBPF collection service. The eBPF collection service can include a business management module, a task management module, a Java native interface (JNI), a Native tool library, and the like.
[0122] The service management module includes the ProcessObserver, the TaskQueue, and the getFgCpuResInfo function for retrieving CPU resource information. The ProcessObserver registers an observer with the ActivityManager. The TaskQueue stores process tasks traced by the eBPF collection service. The TaskQueue is also called the tracing queue.
[0123] It is understandable that a preset number of process tasks can be tracked in the TaskQueue queue. The specific number of process tasks that can be tracked in the TaskQueue queue is not limited in the embodiment of the present application.
[0124] For example, taking the example of 5 process tasks that can be tracked in the TaskQueue queue, when there are 5 process tasks tracked in the TaskQueue queue, if the eBPF collection service needs to track the 6th process task, one or more process tasks that have been tracked in the TaskQueue queue can be removed first. For example, the first process task that starts tracking in the TaskQueue queue can be removed first, and then the 6th process task can be tracked in the TaskQueue queue.
[0125] It is understandable that if the tracked process tasks are not cleared in time, the TaskQueue queue may be overcache, resulting in the inability to add the relevant data of the sixth process task to the TaskQueue queue, thereby creating the risk of data loss. Therefore, clearing the tracked process tasks in time can provide more cache space for tracking the sixth process task, which can reduce the risk of data loss and reduce the lag during task processing.
[0126] The task management module can include functions such as startTracking to start tracing, stopTracking to stop tracing, and getPeriodStateInfo to retrieve status information. For example, when the eBPF collection service begins tracing the sixth process task, it can call the startTracking function. When the eBPF collection service removes a process task from the TaskQueue queue, it can call the stopTracking function. When the eBPF collection service needs to obtain resource information for a process task, it can call the getPeriodStateInfo function.
[0127] The JNI interface can include the RegisterNativeMethods interface for registering local functions and the GetTrackedPidStateInfo interface for obtaining process status information. The eBPF collection service can use the JNI interface to associate Java code with C code, allowing the application layer to call some functions in the kernel.
[0128] The Native tool library includes interfaces such as the OperateProg interface for operating programs, the Getinfo interface for obtaining information, and the ReleaseInfo interface for releasing information. The eBPF collection service can use the interfaces provided in the Native tool library to call functions in libbpf. The OperateProg interface can be used to call the attach and detach functions in libbpf and write relevant information such as the process PID to the eBPF collection BPFMaps. The Getinfo interface can be used to obtain system resource scheduling information over a period of time. The ReleaseInfo interface can be used to periodically release process resource information recorded in BPFMaps.
[0129] Furthermore, the electronic device may include a BPF loader, libbpf. The eBPF collection service can use libbpf to retrieve resource information from the BPFMaps collection. libbpf includes functions such as attach and detach, and the bpf_obj_get function for retrieving BPF objects.
[0130] The attach function can be used to associate the eBPF plugin with the perf_event function. The detach function can be used to disassociate the eBPF plugin from the perf_event function. The bpf_obj_get function can be used to obtain the object information of the collection BPFMaps.
[0131] The following will combine the scenario where process 1 is running in the system to analyze the above Figure 4The execution process of each module is described.
[0132] When the electronic device is turned on, the process observer ProcessObserver of the eBPF collection service can register the observer with the activity manager ActivityManager of the system service system_server. For example, the registration function can be registerProcessObserver.
[0133] If Process 1 is running in the foreground, the observer can obtain information such as Process 1's PID through the ActivityManager. The observer can also call the startTracking function to start a tracking task for Process 1 and place it in the TaskQueue. The observer can also call the bpf_obj_get function in the Native tool library to obtain a BPFMaps object and write information such as Process 1's PID to the kernel's BPFMaps object.
[0134] It is understandable that when the electronic device is turned on, the eBPF collection service can also instruct to start the log statistics module and load the eBPF plug-in.
[0135] When the kernel function kernel_functions is executed in the kernel layer, the performance event perf_event function can be called. The perf_event function can be associated with the eBPF plug-in, so that the code logic in the eBPF plug-in can be executed in the kernel layer, and resource information such as switching and wake-up of process 1 can be recorded in the kernel's collection BPFMaps.
[0136] It is understandable that the eBPF plug-in can determine whether process 1 is a process that needs to be tracked through the is_tracked_pid function. If process 1 is a process that needs to be tracked, the resource information of process 1 can be counted in the kernel layer; if process 1 is not a process that needs to be tracked, the resource information of process 1 is not counted in the kernel layer. Among them, the processes that need to be tracked can include processes running in the foreground of the system, and can also include some more important processes in the system preset by the developer. The specific processes that need to be tracked are not limited in the embodiments of this application. For the sake of convenience of description, the following explanation will be given by taking tracking the foreground process as an example.
[0137] When an electronic device experiences a malfunction such as freezing, the eBPF collection service can query the TaskQueue for a task corresponding to Process 1. If there is no task corresponding to Process 1 in the TaskQueue, the eBPF collection service does not query the BPFMaps collection for resource information about Process 1. If there is a task corresponding to Process 1 in the TaskQueue, the eBPF collection service can obtain resource information about Process 1 from the kernel's BPFMaps collection by calling the getFgCpuResInfo function, the getPeriodStateInfo function, or the Getinfo interface.
[0138] It is understandable that when the eBPF collection service obtains the resource information of process 1, it can pass information such as the PID of process 1, the fault start time startTime, and the fault end time endTime to the kernel. Then, the eBPF collection service can obtain the resource information of process 1 from the set BPFMaps.
[0139] Figure 5 The flowchart of eBPF collecting service maintenance process information and passing it to the kernel is shown.
[0140] S501: trigger an activity switching event.
[0141] In the embodiment of the present application, the triggering activity switching event may include a switching event between processes. For example, taking process 1 switching to process 2 as an example, when process 1 switches to process 2, the eBPF collection service can obtain information such as the PID of process 2 and execute step S502.
[0142] S502: Determine whether the process is a system foreground process.
[0143] The eBPF collection service can determine whether process 2 is running in the system foreground. If process 2 is not running in the system foreground, it means that process 2 does not need to be traced, and the eBPF collection service will not add a tracing task for process 2 to the TaskQueue queue. If process 2 is running in the system foreground, it means that process 2 needs to be traced, and the eBPF collection service can add a tracing task for process 2 to the TaskQueue queue.
[0144] In a possible implementation, the eBPF collection service can use the isForeground function to determine whether process 2 is the process running in the system foreground, or any other possible method can be used to determine the process in the system foreground, which is not limited in the embodiment of the present application.
[0145] S503: Get the process PID.
[0146] If the TaskQueue is full and cannot add a task to track Process 2, the eBPF collection service can obtain the oldest tracked process task in the TaskQueue. For example, if the oldest tracked process is Process 3, the eBPF collection service can obtain the PID of Process 3 from the TaskQueue and execute step S504.
[0147] S504: Notify the kernel to stop tracking and clean up historical tasks.
[0148] To track the tasks of Process 2 in the TaskQueue, the eBPF collection service can call the stopTracking function to stop tracking the tasks of Process 3 and clean up the tasks of Process 3. This can provide more cache space for task tracking of Process 2 and reduce the risk of losing resource information of Process 2.
[0149] S505: Generate a tracking task.
[0150] S506: Notify the kernel to start tracing.
[0151] S507. The task is added to the queue.
[0152] The eBPF collection service can call the startTracking function to generate a tracing task for process 2 in the TaskQueue queue, and notify the kernel to track the task of process 2 by calling the interface provided by the JNI interface and the Native tool library, and record the resource information of process 2 in the collection BPFMaps.
[0153] It's understandable that electronic devices can record resource information for each process during runtime in the kernel's collection of BPFMaps. This resource information is extensive, making it more difficult for developers to locate issues. To more accurately obtain resource information for processes related to the fault, the eBPF collection service can potentially obtain resource information for processes during the fault period based on time interval segments.
[0154] Figure 6 A schematic diagram showing how to obtain process information based on time interval segments is shown.
[0155] The electronic device can cyclically use N preset memory segments to store process information within a period of time. The memory segments can also be called buckets, and each bucket can store process information for a preset time interval T. For ease of understanding, the embodiments of the present application are first described in decimal format and then in binary format.
[0156] (1) Describe the process of collecting resource information of the process in decimal form.
[0157] For example, the above Figure 4 For example, when process 2 switches process 1, process 1 can switch from the Runnable state to the Running state, which means the end of the Runnable state. At this time, the electronic device can record the resource information of the Runnable state and the end time T1 of the Runnable state.
[0158] For example, if an electronic device cycles through 10 buckets, with each bucket having a time interval of 1 second, the electronic device can perform a modulo-10 calculation on T1 and record the resource information of the Runnable state in the T1%10th bucket. For example, if T1 is 70 seconds (s), 70%10 equals 0, and the resource information of the Runnable state can be recorded in the 0th bucket; if T1 is 71 seconds (s), 71%10 equals 1, and the resource information of the Runnable state can be recorded in the 1st bucket; if T1 is 74 seconds (s), 74%10 equals 4, and the resource information of the Runnable state can be recorded in the 4th bucket; if T1 is 74.5 seconds (s), 74.5%10 equals 4, and the resource information of the Runnable state can also be recorded in the 4th bucket; if T1 is 75 seconds (s), 75%10 equals 5, and the resource information of the Runnable state can be recorded in the 5th bucket, and so on.
[0159] It is understood that each bucket may have a corresponding bucket ID. For example, the bucket ID of the 0th bucket may be 0, the bucket ID of the 1st bucket may be 1, and the bucket ID of the 5th bucket may be 5.
[0160] Each bucket may also have a corresponding unit information segment. Each segment may include one or more of the following: segment ID, scheduling delay information, sleep state information, D state information, or running state information.
[0161] The segment ID can also be called an interval ID or unit ID. The segment ID can be the start time, end time, or a time in between of the bucket, and this embodiment of the application is not limited to this. For example, the bucket ID of the 0th bucket can be 70, the bucket ID of the 1st bucket can be 71, and the bucket ID of the 5th bucket can be 75.
[0162] The scheduling delay information may include one or more of the following: the total time that process 1 is in the Runnable state runnable_total, the number of times process 1 is in the Runnable state runnable_count, the start time of the longest time that process 1 is in the Runnable state runnable_max_start, or the end time of the longest time that process 1 is in the Runnable state runnable_max_end, etc.
[0163] Sleep state information may include one or more of the following: the total time process 1 is in the Sleep state sleep_total, the number of times process 1 is in the Sleep state sleep_count, the start time sleep_max_start of the longest time process 1 is in the Sleep state, or the end time sleep_max_end of the longest time process 1 is in the Sleep state, etc.
[0164] The D state information may include one or more of the following: the total time that process 1 is in the D state d_state_total, the number of times process 1 is in the D state d_state_count, the start time of the longest time that process 1 is in the D state d_state_max_start, the end time of the longest time that process 1 is in the D state d_state_max_end, etc.
[0165] The running status information may include one or more of the following: the total time that process 1 is in the Running state, the time that process 1 runs on the small core, little_cluster_total_time, the time that process 1 runs at each frequency point of the small core, little_cluster, the time that process 1 runs at each frequency point of the medium core, medium_cluster, or the time that process 1 runs at each frequency point of the large core, big_cluster, etc.
[0166] For example, when the eBPF collection service needs to obtain information from 74s to 79s, the electronic device can determine that it needs information from the 4th to 9th buckets by taking the modulus of the time. The electronic device can then merge the information from the 4th to 9th buckets and return it to the eBPF collection service.
[0167] Taking the above-mentioned scheduling delay information as an example, when merging the information of the 4th to 9th buckets, the electronic device can sum the runnable_total of the 4th to 9th buckets, sum the runnable_count, find the maximum value of runnable_max_start, and find the maximum value of runnable_max_end. The electronic device can also find the maximum or larger value or values of runnable_max_start of the 4th to 9th buckets. The electronic device can also merge the resources of the resource information of the 4th to 9th buckets by subtraction, multiplication, exponentiation, etc. according to business needs. The specific merging method is not limited in the embodiments of this application.
[0168] It is understandable that when the eBPF collection service needs to obtain information from 81s to 89s, the electronic device can determine that it needs information from buckets 1 to 9 by taking the modulus of the time. At this time, the electronic device can also determine the segment ID of each bucket to determine whether the information stored in the bucket corresponds to the requested time period. For example, if the segment ID of the first bucket is 71, and the requested fault start time is 81s, indicating that 81 is not recorded in the first bucket, the request is invalid, and the electronic device does not return the resource information in the first bucket to the eBPF collection service.
[0169] After T1, when the state of process 1 changes again, the electronic device can record the state change time T2 of process 1, and record the resource information of the state change in the T2%10th bucket. For example, if T2 is 84s, 84%10 equals 4, then the state information of process 2 should be recorded in the 4th bucket. It is understandable that if the 4th bucket already contains the last recorded information, the electronic device can first clear the contents of the 4th bucket, and then save the process information corresponding to time T2. In this way, the electronic device can continuously record the current process state information of the last 10s. In this way, developers can more accurately obtain process information related to the fault problem, which facilitates developers to locate and analyze the fault problem.
[0170] It should be noted that the number N of buckets circulated by the above-mentioned electronic device can also be set to other values, the time interval T of each bucket can also be set to other values, and the value of the time interval T of each bucket can also be different. The specific values of N and T can be set by the electronic device according to business needs, and are not limited in the embodiments of this application.
[0171] (2) The process of collecting resource information of the process in binary form.
[0172] Electronic devices execute programs in binary format. Therefore, the number N of buckets that can be recycled by the electronic device can be set to a power of 2, which improves the execution efficiency of the electronic device. For example, N can be set to 64, 128, or 256, etc. The specific value of N is not limited in this embodiment of the application.
[0173] It is understandable that through laboratory testing and analysis, it is known that when N is 128, on the one hand, the information stored in the 128 buckets will not be too little, which can reduce the probability of losing fault information; on the other hand, the information stored in the 128 buckets will not be too much, which can reduce the pressure of storing information on system memory.
[0174] In addition, the time used in the program of the electronic device can be nanosecond time. Through laboratory testing and analysis, it is known that: if the binary format of the nanosecond time is shifted right by 26 bits, the corresponding time is about 67ms; if the binary format of the nanosecond time is shifted right by 27 bits, the corresponding time is about 134ms; if the binary format of the nanosecond time is shifted right by 28 bits, the corresponding time is about 268ms.
[0175] Therefore, the electronic device can also set the time interval T for each bucket. For example, T can be set to 67ms, 134ms, or 268ms, etc. The specific value of N is not limited in the embodiment of this application.
[0176] It is understandable that if T is set to 67ms, the total duration of resource information recorded by the 128 buckets is about 8s. If T is set to 134ms, the total duration of resource information recorded by the 128 buckets is about 17s. If T is set to 268ms, the total duration of resource information recorded by the 128 buckets is about 34s.
[0177] Since the failure time period is most likely within 17 seconds, obtaining process information within 17 seconds can not only meet the time requirements for locating the problem, but also reduce the difficulty for developers to locate the problem because the process information within 17 seconds is not too much. Therefore, in this embodiment of the application, the time interval T of each bucket can be set to 134ms. Of course, the time interval T of each bucket can also be set to other values based on business needs, and this embodiment of the application is not limited to this.
[0178] For ease of description, the following explanation is given using 128 buckets, where the time interval of each bucket is 134 ms.
[0179] For example, the above Figure 4Taking the corresponding embodiment as an example, in an electronic device, the end time T1 of process 1 obtained can be a time in nanoseconds. For example, when T1 is 74000000000 nanoseconds (ns), the corresponding binary number is 1000100111010101111100110010000000000. The electronic device can then right-shift the binary number by 27 bits to obtain 1000100111, which corresponds to a decimal number of 551. The electronic device can also perform a modulo 128 on 1000100111, which corresponds to a decimal number of 551%128, thereby obtaining 100111, which corresponds to a decimal number of 39. This indicates that the electronic device can record the resource information of process 1 in the 39th bucket.
[0180] The bucket ID calculated above is 100111, which corresponds to the decimal number 39; the segment ID is 1000100111, which corresponds to the decimal number 551. It is understood that the above calculation process is performed in binary in electronic devices, and the corresponding decimal description is for ease of understanding.
[0181] When T1 is 79000000000ns, the corresponding binary number is 1001001100100110001000101011000000000. The electronic device can right-shift this binary number by 27 bits to obtain 1001001100, which corresponds to the decimal number 588. The electronic device can also perform a modulo-128 operation on 1001001100, which corresponds to 588%128 in decimal, resulting in 1001100, which corresponds to 76 in decimal. This means that the electronic device can record the resource information of process 1 in the 76th bucket. The bucket ID is 1001100, which corresponds to the decimal number 76; the segment ID is 1001001100, which corresponds to the decimal number 588.
[0182] The same goes for the rest. I won’t go into details.
[0183] In this way, the electronic device can continuously record the resource information of the current process in the last 17 seconds. Developers can more accurately obtain process information related to the fault problem, making it easier for developers to locate and analyze the fault problem.
[0184] For example, when the eBPF collection service needs to obtain resource information from 74306175231ns to 76306540283ns, the electronic device can right-shift the binary number 74306175231 by 27 bits to obtain 1000100111, which corresponds to a decimal number of 553. The electronic device can also perform a modulo 128 on 1000100111, which corresponds to a decimal number of 553%128, thereby obtaining 101001, which corresponds to a decimal number of 41.
[0185] The electronic device can also right-shift the binary number 76306540283 by 27 bits to obtain 1000100111, which corresponds to the decimal number 568. The electronic device can also perform a modulo 128 on 1000100111, which corresponds to 568%128 in decimal, thereby obtaining 111000, which corresponds to the decimal number 56.
[0186] After calculation, it can be known that the electronic device can obtain the resource information of the process from the 41st bucket to the 56th bucket, and then the electronic device can merge the resource information of the 41st bucket to the 56th bucket and return it to the eBPF collection service.
[0187] It is understandable that the electronic device divides the information of about 17 seconds into 128 buckets for storage, which can obtain more accurate resource information with smaller granularity, making it easier for developers to locate problems.
[0188] Figure 7 It shows a flowchart of the eBPF collection service obtaining resource scheduling information.
[0189] S701, ANR, or performance issues.
[0190] When an electronic device experiences an application not responding (ANR) or performance lag problem, the electronic device may detect the ANR or performance lag event and execute step S702.
[0191] S702: Obtain resource information.
[0192] The electronic device can transmit information such as the PID, fault start time, and fault end time of the system foreground process to the eBPF collection service, and obtain resource information related to the process from the eBPF collection service. For ease of description, the following explanation uses foreground process 1 as an example.
[0193] S703: Check whether the queue has a corresponding ID.
[0194] The eBPF collection service can determine whether there is a PID of process 1 in the TaskQueue queue.
[0195] If there is no PID of process 1 in the TaskQueue queue, it means that the eBPF collection service does not perform task tracking on process 1, and step S709 can be executed.
[0196] If the PID of process 1 is in the TaskQueue queue, it means that the eBPF collection service has performed task tracking on process 1, and step S704 can be executed.
[0197] S704: Check whether the time intervals match.
[0198] The eBPF collection service can determine whether the fault start time and the start tracing time of process 1 match.
[0199] If the fault start time is not within the start tracing time of process 1, indicating that the time interval does not match, the eBPF collection service does not query the resource information of process 1 and step S709 can be executed.
[0200] If the fault start time is within the start tracing time of process 1, indicating that the time intervals match, the eBPF collection service can query the resource information of process 1 and execute step S705.
[0201] S705: Generate a unit ID of a valid interval.
[0202] The specific process of generating the unit ID of the valid interval can refer to the above Figure 6 After generating the unit ID of the valid interval, the eBPF collection service may execute step S706.
[0203] S706: Query the resource information of each bucket according to the PID and bucket ID.
[0204] The process of querying the data table based on PID and bucket ID can refer to the above Figure 6 The relevant descriptions in the corresponding embodiments are not repeated here. After querying the resource information in each bucket, the eBPF collection service may execute step S707.
[0205] S707: Merge resource information within the interval.
[0206] S708. Return resource information.
[0207] The eBPF collection service can merge the resource information in each bucket and return the merged resource information to the electronic device.
[0208] S709. Return a null string.
[0209] The null string can be used to indicate that no matching results were found. It is understandable that the eBPF collection service can also return other values, and the specific return value is not limited in this embodiment of the application.
[0210] The following describes the method of the embodiment of the present application in detail through specific embodiments. The following embodiments can be combined with each other or implemented independently, and the same or similar concepts or processes may not be repeated in some embodiments.
[0211] Figure 8The resource management method of an embodiment of the present application is shown. The method includes:
[0212] S801. At a first moment, a first process runs in the foreground, a second process is awakened, and resource information of the second process is saved to a first area of a first memory, where the resource information includes information used to reflect the running status of the process.
[0213] In the embodiment of the present application, the first moment can be understood as the moment when the second process is awakened.
[0214] The first process and the second process can be any process in the electronic device, and are not limited in the embodiments of the present application.
[0215] The first memory may be any memory in the electronic device that stores resource information of the second process, and is not limited in the embodiment of the present application.
[0216] The first area is any memory area of the first memory. The first area can be understood as the above Figure 6 The process of saving the resource information of the second process to the first area of the first memory can refer to the above Figure 6 The relevant descriptions in the corresponding embodiments are not repeated here.
[0217] Resource information may include the following: Figure 6 In the corresponding embodiment, the segment ID, scheduling delay information, Sleep status information, D status information, or running status information that can be recorded by each bucket may also include information recorded by other electronic devices, which is not limited in the embodiment of this application.
[0218] S802. At the second moment, the second process is switched to the foreground, and resource information of the second process is saved to the second area of the first memory, and resource information of the first process is saved to the third area of the second memory, where the second area is the same as or different from the first area.
[0219] In the embodiment of the present application, the second moment can be understood as the moment when the second process switches to the foreground.
[0220] The second memory may be any memory in the electronic device that stores resource information of the first process, and is not limited in the embodiment of the present application.
[0221] The second area is any memory area of the first memory. The third area is any memory area of the second memory. The second area and the third area can be understood as the above Figure 6 The process of saving the resource information of the second process to the second area of the first memory and saving the resource information of the first process to the third area of the second memory can refer to the above Figure 6 The relevant descriptions in the corresponding embodiments are not repeated here.
[0222] S803. At the third moment, the first process switches to the foreground, and the resource information of the second process is saved to the fourth area of the first memory, and the resource information of the first process is saved to the fifth area of the second memory. The fourth area is the same as or different from the second area, and the fifth area is the same as or different from the third area.
[0223] In the embodiment of the present application, the third moment can be understood as the moment when the first process switches to the foreground.
[0224] The fourth area is any memory area of the first memory. The fifth area is any memory area of the second memory. The fourth area and the fifth area can be understood as the above Figure 6 The process of saving the resource information of the second process to the fourth area of the first memory and the process of saving the resource information of the first process to the fifth area of the second memory can refer to the above Figure 6 The relevant descriptions in the corresponding embodiments are not repeated here.
[0225] It is understandable that in one possible implementation, the electronic device can save the resource information of the second process at each moment into the same memory area, for example, the memory area is the first memory, in which case the first area, the second area, and the fourth area can be the same memory area. The electronic device can save the resource information of the first process at each moment into the same memory area, for example, the memory area is the second memory, in which case the third area and the fifth area can be the same memory area. In this way, the electronic device can save the resource information of different processes into different memory areas, making it easier for developers to obtain the resource information corresponding to a certain process when locating problems.
[0226] In another possible implementation, the electronic device can also save the resource information of the second process at each moment in different areas of the first memory. In this case, the first area, the second area, and the fourth area may be different memory areas. The electronic device can also save the resource information of the first process at each moment in different areas of the second memory. In this case, the third area and the fifth area may be different memory areas. In this way, the electronic device can obtain more accurate resource information from the corresponding memory interval based on time, thereby reducing the difficulty for developers to locate problems.
[0227] Optional, in Figure 8 Based on the corresponding embodiment, the first memory has N1 memory areas, and the second memory has N2 memory areas, N1 and N2 are both positive integers, and the specific storage location of the resource information of the first process in the N2 memory areas is related to the moment when the state of the first process changes; the specific storage location of the resource information of the second process in the N1 memory areas is related to the moment when the state of the second process changes.
[0228] In the embodiment of the present application, N1 and N2 may include the above Figure 6 The number of buckets in the corresponding embodiment, for example, in a decimal scenario, N1 and N2 can each be 10, and in a binary scenario, N1 and N2 can each be 128. Of course, N1 and N2 can also be other values, and the specific values of N1 and N2 are not limited in the embodiment of the present application.
[0229] It is understandable that by determining the storage location of the process resource information in the memory area according to the time when the process state changes, it is possible to more conveniently and accurately obtain the resource information of a certain time period when obtaining the resource information of the process.
[0230] Optional, in Figure 8 On the basis of the corresponding embodiment, saving the resource information of the second process to the first area of the first memory may include: saving the resource information of the second process to the first area of the first memory according to the first moment and the preset mapping rules, wherein the preset mapping rules include mapping rules between the moment and each memory area in the first memory.
[0231] In the embodiment of the present application, the calculation method of the preset mapping rule can refer to the above Figure 6 The relevant descriptions in the corresponding embodiments are omitted here. Based on the preset mapping rules, the electronic device can continuously record the resource information of the current process within the recent period. In this way, developers can more accurately obtain the process information related to the fault problem, thereby facilitating the developer's fault location and analysis.
[0232] Optional, in Figure 8 On the basis of the corresponding embodiment, according to the first moment and the preset mapping rule, the resource information of the second process is saved to the first area of the first memory, which can include: right shifting the first moment by L bits to obtain the ID of the first unit information, where L is a positive integer; dividing the ID of the first unit information by N and taking the remainder to obtain a first value M1; and saving the resource information of the second process to the M1th memory area of the first memory based on the ID of the first unit information.
[0233] In the embodiment of the present application, the calculation method of the specific preset mapping rule can refer to the above Figure 6 The relevant descriptions in the corresponding embodiments are not repeated here.
[0234] Among them, in the above Figure 6 In the binary calculation method of the corresponding embodiment, the value of L can include 26, 27, or 29, or other values, which are not limited in the embodiment of the present application. The value of N can include 64, 128, or 256, or other values, which are not limited in the embodiment of the present application.
[0235] The ID of the first unit information can be understood as the segment ID of the bucket.
[0236] It can be understood that reasonable values of L and N can ensure that the resource information of the process stored in the memory is not too little, reducing the probability of losing fault information, and can also ensure that the resource information of the process stored in the memory is not too much, reducing the pressure of storage information on the system memory.
[0237] Optional, in Figure 8 On the basis of the corresponding embodiment, before saving the resource information of the second process to the first area of the first memory based on the ID of the first unit information, it can also include: if the ID of the unit information of the existing data in the first area is different from the ID of the first unit information, then clearing the existing data in the first area.
[0238] In the embodiment of the present application, the process of clearing the existing data in the first area can refer to the above Figure 6 The electronic device first clears the previously saved content and then saves the new process resource information. In this way, the process resource information of the most recent period can be continuously recorded.
[0239] Optional, in Figure 8 On the basis of the corresponding embodiment, there is a target queue in the electronic device. Before saving the resource information of the second process to the first area of the first memory, it can also include: generating a task of the second process in the target queue and saving the process identifier PID of the second process; saving the resource information of the second process to the first area of the first memory can include: based on the task of the second process, instructing the kernel layer to save the resource information of the second process to the first area of the first memory.
[0240] In the embodiment of the present application, the target queue can be understood as the above Figure 3 The specific process of saving the resource information of the second process to the first area of the first memory can refer to the above Figure 3 The relevant descriptions in the corresponding embodiments are not repeated here.
[0241] By collecting statistics on the resource information of the process and feeding the statistical resource information back to the upper-level application, developers can analyze and locate problems based on the resource information.
[0242] Optional, in Figure 8On the basis of the corresponding embodiment, the number of process tasks in the target queue is less than or equal to the preset value. Before generating the task of the second process in the target queue, it can also include: if the number of process tasks in the target queue is equal to the preset value, stop one or more target processes in the target queue, and clean up the resource information in the memory corresponding to the one or more target processes.
[0243] In the embodiment of the present application, the preset value may include the above Figure 3 In the corresponding embodiment, the number of process tasks that the TaskQueue queue can track, for example, can be preset to 5. Of course, the preset value can also be set to other values. The specific value of the preset value is not limited in the embodiment of this application.
[0244] The target process can be understood as a process that has been tracked in the TaskQueue queue. For example, the target process can include one or more processes that are first tracked in the TaskQueue queue. The specific number of target processes is not limited in the embodiment of this application.
[0245] It is understandable that timely clearing of the process tasks tracked in the TaskQueue queue can provide more cache space for new tracking tasks, thereby reducing the risk of data loss and reducing the jamming during task processing.
[0246] Optional, in Figure 8 Based on the corresponding embodiment, the method may further include: acquiring resource information of the second process within the first time period from the first memory.
[0247] In the embodiment of the present application, the process of obtaining the resource information of the second process in the first time period from the first memory can refer to the above Figure 6 The relevant descriptions in the corresponding embodiments are not repeated here.
[0248] The first time period may be any time period during which the electronic device acquires resource information of a process, and the first time period may also include a time period during which the electronic device experiences ANR or freeze problems. Figure 6 In the decimal calculation method of the corresponding embodiment, the first time period can be 81s to 89s; Figure 6 In the binary calculation method of the corresponding embodiment, the first time period can be 74306175231ns to 76306540283ns. The specific value of the first time period is not limited in the embodiment of the present application.
[0249] When an electronic device encounters a fault such as ANR or freeze, the resource information of the process can be obtained from the first memory, making it easier for developers to locate the problem.
[0250] Optional, in Figure 8On the basis of the corresponding embodiment, before obtaining the resource information of the second process in the first time period from the first memory, it can also include: shifting the start time of the first time period right by L bits to obtain the ID of the second unit information; dividing the ID of the second unit information by N and taking the modulus to obtain a second value M2; shifting the end time of the first time period right by L bits to obtain the ID of the third unit information; dividing the ID of the third unit information by N and taking the modulus to obtain a third value M3; obtaining the resource information of the second process in the first time period from the first memory can include: obtaining the resource information of the second process from the M2th memory area to the M3th memory area in the first memory; merging the resource information of the M2th memory area to the M3th memory area.
[0251] In the embodiment of the present application, the process of obtaining the resource information of the second process in the first time period from the first memory can refer to the above Figure 6 The relevant descriptions in the corresponding embodiments are not repeated here.
[0252] The ID of the second unit information and the ID of the third unit information can both be understood as the segment ID of the bucket.
[0253] It is understandable that the electronic device will select and obtain the resource information of the process from N buckets, so that smaller-granularity and more accurate resource information can be obtained, making it easier for developers to locate problems.
[0254] Optional, in Figure 8 Based on the corresponding embodiments, the resource information includes one or more of the following: the PID of the process, the total time the process is in the Runnable state, the number of times the process is in the Runnable state, the start time of the longest time the process is in the Runnable state, the end time of the longest time the process is in the Runnable state, the total time the process is in the Sleep state, the number of times the process is in the Sleep state, the start time of the longest time the process is in the Sleep state, the end time of the longest time process 1 is in the Sleep state, the total time the process is in the D state, the number of times the process is in the D state, the start time of the longest time the process is in the D state, the end time of the longest time the process is in the D state, the total time the process is in the Running state, the time the process runs on each core of the central processing unit CPU, or the time the process runs on each frequency band of each core of the CPU.
[0255] In the embodiment of the present application, the resource information may include the above Figure 6 In the corresponding embodiment, the segment ID, scheduling delay information, Sleep status information, D status information, or running status information that can be recorded by each bucket may also include information recorded by other electronic devices, which is not limited in the embodiment of this application.
[0256] By recording the resource information of the process in memory, we can understand the various status data during the process operation, which makes it easier for developers to locate and solve problems and improve the user experience.
[0257] Optional, in Figure 8 On the basis of the corresponding embodiment, merging the resource information of the M2th memory area to the M3th memory area may include one or more of the following: summing the total time that the process in the M2th memory area to the M3th memory area is in the Runnable state, summing the total time that the process in the M2th memory area to the M3th memory area is in the Sleep state, summing the total time that the process in the M2th memory area to the M3th memory area is in the D state, summing the total time that the process in the M2th memory area to the M3th memory area is in the Running state, summing the number of times the process in the M2th memory area to the M3th memory area is in the Runnable state, summing the number of times the process in the M2th memory area to the M3th memory area is in the Sleep state, summing the total time that the process in the M2th memory area to the M3th memory area is in the D state, summing the total time that the process in the M2th memory area to the M3th memory area is in the Running state, summing the number of times the process in the M2th memory area to the M3th memory area is in the Runnable state, summing the number of times the process in the M2th memory area to the M3th memory area is in the Sleep state, Sum the number of times a process is in the D state from the M2th memory area to the M3th memory area, sum the number of times a process is in the Running state from the M2th memory area to the M3th memory area, maximize the longest time a process is in the Runnable state from the M2th memory area to the M3th memory area, maximize the longest time a process is in the Sleep state from the M2th memory area to the M3th memory area, maximize the longest time a process is in the D state from the M2th memory area to the M3th memory area, sum the time that the processes from the M2th memory area to the M3th memory area run on each core of the CPU, or sum the time that the processes from the M2th memory area to the M3th memory area run on each frequency band of each core of the CPU.
[0258] In the embodiment of the present application, the merging of the resource information of the process can refer to the above Figure 6 The relevant descriptions in the corresponding embodiments are omitted here. In this way, the electronic device can continuously record process resource information within the current period. Developers can more accurately obtain process information related to the fault problem, thereby facilitating the developer's fault location and analysis.
[0259] Optional, in Figure 8 Based on the corresponding embodiment, obtaining resource information of the second process in the first time period from the first memory may include: obtaining resource information of the second process in the first time period from the first memory when the target queue includes the PID of the second process.
[0260] In an embodiment of the present application, if there is no PID of the second process in the target queue, it means that the electronic device has not performed task tracking on the second process; if there is a PID of the second process in the target queue, it means that the electronic device has performed task tracking on the second process.
[0261] By determining whether the target queue includes the PID of the second process, it is possible to determine whether the electronic device has performed task tracking on the second process. In this way, when the second process is not tracked, the resource information of the second process in the first time period will not be obtained from the first memory, thereby reducing the execution logic of the code, reducing the computing power of the electronic device, and improving computing efficiency.
[0262] Optional, in Figure 8 Based on the corresponding embodiment, obtaining the resource information of the second process within the first time period from the first memory may include: obtaining the resource information of the second process within the first time period from the first memory when the start time of the first time period is earlier than the time of generating the task of the second process.
[0263] In an embodiment of the present application, if the start time of the first time period is earlier than the time when the task of the second process is generated, it indicates that the time intervals do not match, and the electronic device does not query the resource information of the second process. If the start time of the first time period is equal to or later than the time when the task of the second process is generated, it indicates that the time intervals match, and the electronic device may query the resource information of the second process.
[0264] By determining the order of the start time of the first time period and the time of the task generating the second process, it is possible to determine whether the time intervals do not match. This way, when the time intervals do not match, the resource information of the second process does not need to be queried, thereby reducing the execution logic of the code and the computing power of the electronic device.
[0265] Optional, in Figure 8 On the basis of the corresponding embodiment, obtaining the resource information of the second process within the first time period from the first memory may include: when an application unresponsive ANR or freeze event occurs, obtaining the resource information of the second process within the first time period from the first memory.
[0266] In an embodiment of the present application, when an electronic device has an ANR or performance freeze problem, the electronic device can detect the ANR or performance freeze event and obtain resource information of the second process within the first time period from the first memory, thereby facilitating developers to locate and analyze the problem.
[0267] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0268] The above mainly introduces the solution provided by the embodiment of the present application from the perspective of method. In order to realize the above functions, it includes hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should easily appreciate that, in combination with the method steps of each example described in the embodiment disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in a hardware or computer software driven hardware manner 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 this application.
[0269] The embodiment of the present application can divide the functional modules of the device implementing the method according to the above method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one processing module. The integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. In actual implementation, there may be other division methods.
[0270] like Figure 9 FIG. 9 is a schematic diagram of a chip structure provided by an embodiment of the present application. The chip 900 includes one or more (including two) processors 901 , a communication circuit 902 , a communication interface 903 , and a memory 904 .
[0271] In some embodiments, the memory 904 stores the following elements: executable modules or data structures, or a subset thereof, or an extended set thereof.
[0272] The method described in the above embodiment of the present application can be applied to the processor 901, or implemented by the processor 901. The processor 901 may be an integrated circuit chip with signal processing capabilities. During the implementation process, each step of the above method can be completed by an integrated logic circuit of the hardware in the processor 901 or an instruction in the form of software. The above-mentioned processor 901 can be a general-purpose processor (for example, a microprocessor or a conventional processor), a digital signal processor (digital signal processing, DSP), an application specific integrated circuit (application specific integrated circuit, ASIC), a field-programmable gate array (field-programmable gate array, FPGA) or other programmable logic devices, discrete gates, transistor logic devices or discrete hardware components. The processor 901 can implement or execute the methods, steps and logic block diagrams related to each processing disclosed in the embodiment of the present application.
[0273] The steps of the method disclosed in the embodiments of the present application can be directly implemented as being executed by a hardware decoding processor, or can be implemented by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium mature in the art, such as a random access memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable read-only memory (EEPROM). The storage medium is located in the memory 904, and the processor 901 reads the information in the memory 904 and completes the steps of the above method in combination with its hardware.
[0274] The processor 901 , the memory 904 , and the communication interface 903 may communicate with each other via a communication line 902 .
[0275] In the above embodiment, the instructions stored in the memory for execution by the processor may be implemented in the form of a computer program product, wherein the computer program product may be pre-written in the memory or downloaded and installed in the memory in the form of software.
[0276] The present application also provides a computer program product including one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. 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 site, computer, server or data center to another website site, computer, server or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a server or data center that includes one or more available media integrated. For example, the available medium can include magnetic media (e.g., floppy disk, hard disk or tape), optical media (e.g., digital versatile disc (DVD)), or semiconductor media (e.g., solid state disk (SSD)).
[0277] The present application also provides a computer-readable storage medium. The methods described in the above embodiments can be implemented in whole or in part via software, hardware, firmware, or any combination thereof. Computer-readable media can include computer storage media and communication media, and can also include any medium that can transfer a computer program from one location to another. The storage medium can be any target medium that can be accessed by a computer.
[0278] As one possible design, computer-readable media may include compact disc read-only memory (CD-ROM), RAM, ROM, EEPROM, or other optical disc storage; computer-readable media may include magnetic disk storage or other magnetic disk storage devices. Moreover, any connecting line may also be appropriately referred to as a computer-readable medium. For example, if the software is transmitted from a website, server, or other remote source using a coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave, then the coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave are included in the definition of medium. Disk and disc, as used herein, include compact disc (CD), laser disc, optical disc, digital versatile disc (DVD), floppy disk, and Blu-ray disc, where disks typically reproduce data magnetically, while discs reproduce data optically using lasers.
[0279] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processing unit of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
Claims
1. A resource management method, characterized in that: The method comprises: At a first moment, the first process runs in the foreground, the second process is awakened, and resource information of the second process is saved in a first area of the first memory, the resource information including information used to reflect the running status of the process; At a second moment, the second process is switched to the foreground, resource information of the second process is saved to a second area of the first memory, and resource information of the first process is saved to a third area of the second memory, where the second area is the same as or different from the first area; At a third moment, the first process is switched to the foreground, and the resource information of the second process is saved to a fourth area of the first memory, and the resource information of the first process is saved to a fifth area of the second memory, wherein the fourth area is the same as or different from the second area, and the fifth area is the same as or different from the third area; Among them, the first memory has N1 memory areas, the second memory has N2 memory areas, the N1 and the N2 are both positive integers, and the specific storage locations of the resource information of the first process in the N2 memory areas are related to the moment when the state of the first process changes; the specific storage locations of the resource information of the second process in the N1 memory areas are related to the moment when the state of the second process changes.
2. The method according to claim 1, characterized in that: Saving the resource information of the second process to a first area of a first memory includes: According to the first time and a preset mapping rule, the resource information of the second process is saved in the first area of the first memory, wherein the preset mapping rule includes a mapping rule between a time and each memory area in the first memory.
3. The method according to claim 2, characterized in that The step of saving the resource information of the second process to the first area of the first memory according to the first moment and the preset mapping rule includes: Shift the first moment right by L bits to obtain the ID of the first unit information, where L is a positive integer; Divide the ID of the first unit information by N and obtain the modulus to obtain a first value M1; The resource information of the second process is saved in the M1th memory area of the first memory based on the ID of the first unit information.
4. The method according to claim 3, characterized in that Before the resource information of the second process is saved to the M1th memory area of the first memory based on the ID of the first unit information, the method further includes: If the ID of the unit information of the existing data in the first area is different from the ID of the first unit information, the existing data in the first area is cleared.
5. The method according to any one of claims 1 to 4, characterized in that: There is a target queue in the electronic device, and before the resource information of the second process is saved in the first area of the first memory, the method further includes: Generate a task of the second process in the target queue, and save the process identifier PID of the second process; Saving the resource information of the second process to a first area of a first memory includes: Based on the task of the second process, instruct the kernel layer to save the resource information of the second process to the first area of the first memory.
6. The method according to claim 5, characterized in that The number of process tasks in the target queue is less than or equal to a preset value, and before generating a task of the second process in the target queue, the method further includes: If the number of process tasks in the target queue is equal to the preset value, one or more target processes in the target queue are stopped, and resource information in the memory corresponding to the one or more target processes is cleared.
7. The method according to any one of claims 1 to 4 and 6, characterized in that: The method further comprises: The resource information of the second process within a first time period is obtained from the first memory.
8. The method according to claim 7, characterized in that Before acquiring the resource information of the second process in the first time period from the first memory, the method further includes: Shift the start time of the first time period right by L bits to obtain the ID of the second unit information; Divide the ID of the second unit information by N and obtain the modulus to obtain a second value M2; Shift the end time of the first time period right by L bits to obtain the ID of the third unit information; Divide the ID of the third unit information by N and obtain the modulus to obtain a third value M3; Acquiring resource information of the second process within a first time period from the first memory includes: Acquire resource information of the second process from the M2th memory area to the M3th memory area in the first memory; The resource information of the M2th memory area is merged into the M3th memory area.
9. The method according to any one of claims 1 to 4, 6 and 8, characterized in that: The resource information includes one or more of the following: the PID of the process, the total time that the process is in the Runnable state, the number of times the process is in the Runnable state, the start time of the longest time the process is in the Runnable state, the end time of the longest time the process is in the Runnable state, the total time that the process is in the Sleep state, the number of times the process is in the Sleep state, the start time of the longest time the process is in the Sleep state, the end time of the longest time that process 1 is in the Sleep state, the total time that the process is in the D state, the number of times the process is in the D state, the start time of the longest time the process is in the D state, the end time of the longest time the process is in the D state, the total time that the process is in the Running state, the time the process runs on each core of the central processing unit CPU, or the time the process runs on each frequency band of each core of the CPU.
10. The method according to claim 8, characterized in that The resource information of merging the M2th memory area into the M3th memory area includes one or more of the following: Sum the total time that the process is in the Runnable state from the M2th memory area to the M3th memory area, sum the total time that the process is in the Sleep state from the M2th memory area to the M3th memory area, sum the total time that the process is in the D state from the M2th memory area to the M3th memory area, sum the total time that the process is in the Running state from the M2th memory area to the M3th memory area, sum the number of times the process is in the Runnable state from the M2th memory area to the M3th memory area, sum the number of times the process is in the Sleep state from the M2th memory area to the M3th memory area, sum the number of times the process is in the D state from the M2th memory area to the M3th memory area The method comprises the following steps: summing the number of times a process is in the Running state from the M2th memory area to the M3th memory area, summing the number of times a process is in the Running state from the M2th memory area to the M3th memory area, maximizing the longest time a process is in the Runnable state from the M2th memory area to the M3th memory area, maximizing the longest time a process is in the Sleep state from the M2th memory area to the M3th memory area, maximizing the longest time a process is in the D state from the M2th memory area to the M3th memory area, summing the time a process from the M2th memory area to the M3th memory area runs on each core of the CPU, or summing the time a process from the M2th memory area to the M3th memory area runs in each frequency band of each core of the CPU.
11. The method according to claim 8 or 10, characterized in that: Acquiring resource information of the second process within a first time period from the first memory includes: In a case where the target queue includes the PID of the second process, resource information of the second process in the first time period is obtained from the first memory.
12. The method according to claim 8 or 10, characterized in that: Acquiring resource information of the second process within a first time period from the first memory includes: When the start time of the first time period is earlier than the time of generating the task of the second process, resource information of the second process in the first time period is obtained from the first memory.
13. The method according to claim 8 or 10, characterized in that: Acquiring resource information of the second process within a first time period from the first memory includes: When an application unresponsiveness (ANR) or freeze event occurs, resource information of the second process in the first time period is obtained from the first memory.
14. An electronic device, characterized in that: include: A memory and a processor, the memory being used to store a computer program, and the processor being used to execute the computer program to perform the method according to any one of claims 1 to 13.
15. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed, the computer executes the method according to any one of claims 1 to 13.
16. A computer program product, characterized in that The invention comprises a computer program, which, when being executed, enables an electronic device to execute the method according to any one of claims 1 to 13.
Citation Information
Patent Citations
Process management method and device and electronic equipment
CN113407368A