Application power consumption detection method and device, electronic equipment and storage medium
By analyzing the cumulative runtime and power consumption per unit time of each process of the application, and calculating and accumulating indirect power consumption, the problem of inaccurate power consumption detection in the prior art is solved, and an accurate reflection of the actual power consumption of the application is achieved.
Patent Information
- Application Number
- CN202410943539.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-15
- Publication Date
- 2026-01-16
AI Technical Summary
In existing technologies, the power consumption detection methods for applications cannot accurately distinguish between the power consumption generated by the application itself and the power consumption generated by being called by other applications, resulting in an inability to reflect the true power consumption of the application.
By identifying each process corresponding to the application under test, calculating the indirect power consumption of the process based on the cumulative runtime and power consumption per unit time when the process is called by the target application, and summing them up to obtain the total indirect power consumption, accurate detection of the power consumption of the application under test when it is called by other applications can be achieved.
It accurately reflects the actual power consumption of the application under test, and can identify and separate the power consumption generated by the application itself and the power consumption generated by being invoked, thus improving the accuracy of power consumption detection.
Smart Images

Figure CN121349792A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of terminal equipment technology, and in particular to an application power consumption detection method, apparatus, electronic device and storage medium. Background Technology
[0002] In the process of using smart terminals, in order to let users know the power consumption of each application, it is usually necessary to detect the power consumption of each application.
[0003] The power consumption detection methods in related technologies can only detect the overall power consumption of an application. However, the overall power consumption of an application may include power consumption caused by calls from other applications. If this part of the power consumption is confused with the power consumption generated by the application itself, it will not accurately reflect the actual power consumption of the application. Summary of the Invention
[0004] To overcome the problems existing in related technologies, this disclosure provides an application power consumption detection method, device, electronic device, and storage medium.
[0005] According to a first aspect of the present disclosure, an application power consumption detection method is provided, comprising:
[0006] In response to a power consumption detection command for the application to be detected, determine the process corresponding to the application to be detected;
[0007] For each process corresponding to the application to be detected, the indirect power consumption of the process when it is called by the target application is determined based on the cumulative runtime of the process when it is called by the target application and the power consumption of the process per unit time.
[0008] The indirect power consumption of each process is summed to obtain the total indirect power consumption when the application under test is called by the target application.
[0009] In some embodiments, the method further includes:
[0010] For each process corresponding to the application to be detected, the following processing is performed:
[0011] Each time the process is detected to be invoked by the target application, the runtime of the process during this invocation is recorded;
[0012] The cumulative runtime includes the sum of the runtimes of the process recorded each time.
[0013] In some embodiments, after determining the process corresponding to the application to be detected, the method further includes:
[0014] For each process corresponding to the application to be detected, the following processing is performed:
[0015] Obtain the total runtime of the process and its corresponding total power consumption. The total runtime includes the runtime of the process when it is invoked by any application and the runtime of the process when it is not invoked.
[0016] Based on the total runtime and its corresponding total power consumption, the power consumption per unit time of the process is determined.
[0017] In some embodiments, after determining the process corresponding to the application to be detected, the method further includes:
[0018] For each process corresponding to the application to be detected, the following processing is performed:
[0019] Obtain the cumulative runtime distribution of the process when it is invoked by any application; wherein the cumulative runtime distribution is used to show the runtime of the process at each operating frequency of each processor;
[0020] Based on the cumulative runtime distribution, the call duration of the process is calculated, and combined with the pre-measured current of each processor at each operating frequency, the power consumption of the process during the call is calculated.
[0021] Based on the duration of the invocation and the power consumption of the invocation, the power consumption per unit time of the process is determined.
[0022] In some embodiments, the method further includes:
[0023] For each process corresponding to the application to be detected, the runtime distribution of the process when it is called by any application is recorded each time the process is detected to be called.
[0024] The cumulative runtime distribution is obtained by accumulating the runtime distribution of the process recorded each time.
[0025] In some embodiments, recording the runtime distribution of the process during this invocation includes:
[0026] Monitor the processor usage status when the process is invoked this time. The processor usage status includes: the processor used by the process and its operating frequency.
[0027] Each time a change in the processor's usage state is detected, the processor identifier, operating frequency, and duration of the process running are recorded until the process terminates, thus obtaining the runtime distribution of the process during this call.
[0028] The target processor is the processor used to run the process before each change.
[0029] In some embodiments, the cumulative runtime distribution is stored in the system's kernel space in the form of key-value pairs;
[0030] The key-value pairs include:
[0031] A process identifier used to indicate the target process; and
[0032] The runtime of the target process at various operating frequencies of various processors when it is invoked by any application;
[0033] The process of obtaining the cumulative runtime distribution when called by any application includes:
[0034] Based on the process identifier of the process, obtain the cumulative runtime distribution corresponding to the process in the kernel space.
[0035] According to a second aspect of the present disclosure, an application power consumption detection device is provided, comprising:
[0036] The first determining module is used to determine the process corresponding to the application under test in response to a power consumption detection command for the application under test.
[0037] The second determining module determines the indirect power consumption of each process corresponding to the application to be detected when it is called by the target application, based on the cumulative runtime of the process when it is called by the target application and the power consumption per unit time of the process.
[0038] The accumulation module is used to accumulate the indirect power consumption of each process to obtain the total indirect power consumption when the application to be detected is called by the target application.
[0039] According to a third aspect of the present disclosure, an electronic device is provided, comprising:
[0040] Processor; and
[0041] Memory for storing the executable instructions of the processor;
[0042] The processor is configured to execute the method described in the first aspect by executing the executable instructions.
[0043] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect.
[0044] The solution provided in this disclosure can determine the process corresponding to the application under test in response to a power consumption detection command. Then, for each process corresponding to the application under test, the indirect power consumption when the process is called by the target application can be determined based on the cumulative runtime of the process when called by the target application and the power consumption per unit time of the process. By summing the indirect power consumption of each process, the total indirect power consumption of the application under test when called by the target application can be obtained. This disclosure can accurately detect the power consumption generated when the application under test is called by other applications, thereby reflecting the true power consumption of the application under test. Attached Figure Description
[0045] Figure 1 This diagram illustrates a flowchart of an application power consumption detection method according to an embodiment of the present disclosure.
[0046] Figure 2 The diagram shows a flowchart of a method for determining power consumption per unit time according to an embodiment of the present disclosure.
[0047] Figure 3 A flowchart illustrating another method for determining power consumption per unit time in an embodiment of this disclosure is shown.
[0048] Figure 4 This diagram illustrates the implementation process of an application power consumption detection method in an embodiment of this disclosure.
[0049] Figure 5 A schematic diagram of the structure of an application power consumption detection device is shown in an embodiment of this disclosure.
[0050] Figure 6 A schematic diagram of the structure of an electronic device according to an embodiment of the present disclosure is shown. Detailed Implementation
[0051] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0052] There are already well-established mechanisms for detecting the overall power consumption of an application. However, since applications may call other applications and be called during operation, attributing the power consumption of an application when it is called by other applications to the application's overall power consumption may not accurately reflect the application's true power consumption.
[0053] For example, suppose application B provides download management functionality. When application A needs to download data, it can call application B's download management function through an interface provided by application B to ensure the integrity of the data download. If power consumption detection methods from related technologies are used, a surge in application B's overall power consumption will be detected when application A frequently downloads data. Clearly, this detection method will fail to allow users to pinpoint the true source of power consumption.
[0054] In view of this, the solution provided in this disclosure can determine the indirect power consumption of each process corresponding to the application under test when it is called by the target application, based on the cumulative runtime of the process when it is called by the target application and the power consumption per unit time of the process, and thus determine the total indirect power consumption of the application under test. Therefore, this disclosure can more accurately detect the power consumption generated when the application under test is called by other applications, thereby reflecting the true power consumption of the application under test.
[0055] The following will describe the exemplary implementation method in detail with reference to the accompanying drawings and embodiments.
[0056] First, this disclosure provides an application power consumption detection method, which can be executed by any electronic device.
[0057] Figure 1 This diagram illustrates a flowchart of a power consumption detection method according to an embodiment of the present disclosure. Figure 1 As shown, the application power consumption detection method provided in this embodiment includes the following steps S101 to S103.
[0058] S101, in response to the power consumption detection command for the application to be detected, determines the process corresponding to the application to be detected.
[0059] In some embodiments, the power consumption detection command can be initiated by the user to view the indirect power consumption of an application.
[0060] For example, the power consumption detection command can also be initiated by the system, enabling the system to capture detailed power consumption data of the application under test in the background in order to monitor the power consumption of the application under test.
[0061] It should be noted that the application to be tested can correspond to at least one process. For example, if an application integrates multiple functions, different functions may need to run different processes to implement them. The application can run the corresponding process according to the function currently used by the user. However, for some applications with relatively simple functions, only one process may be involved, and this disclosure does not limit this.
[0062] Therefore, in order to accurately detect the power consumption of the application under test, it is necessary to determine the power consumption of each process corresponding to the application under test.
[0063] S102, for each process corresponding to the application to be detected, determine the indirect power consumption of the process when it is called by the target application based on the cumulative runtime of the process when it is called by the target application and the power consumption per unit time of the process.
[0064] It should be noted that each process in this embodiment refers to the process corresponding to the application to be tested. The indirect power consumption of each process refers to the power consumption generated when the process is invoked by other applications (not the application to be tested). In other words, if the process is not initiated by the application to be tested itself, but is initiated by other applications (not the application to be tested), then the power consumption generated by the process in this run is the indirect power consumption.
[0065] In some embodiments, the target application can be any non-detectable application already installed in the system. For example, the system can select non-detectable applications that have a calling relationship with the process as the target application based on the process's calling history. Of course, the target application can be specified by the user, and this disclosure does not limit this.
[0066] In some embodiments, the cumulative runtime of the process when it is invoked by the target application can be counted, and the power consumption per unit time of the process can be evaluated. By multiplying the cumulative runtime by the power consumption per unit time, the indirect power consumption of the process when it is invoked by the target application can be obtained.
[0067] S103, sum up the indirect power consumption of each process to obtain the total indirect power consumption when the application to be detected is called by the target application.
[0068] It is understandable that by summing up the indirect power consumption of each process corresponding to the application under test, the total indirect power consumption when the application under test is called by the target application can be obtained.
[0069] In some embodiments, there may be multiple target applications. When there are multiple target applications, the above steps S101 to S103 can be executed for each target application to obtain the total indirect power consumption when the application to be detected is called by each target application.
[0070] Thus, the solution provided in this disclosure can independently detect the power consumption generated when the application to be tested is called by the target application, thereby clarifying the cause of the power consumption of the application to be tested.
[0071] In this embodiment of the disclosure, the indirect power consumption of each process corresponding to the application to be detected is calculated based on the cumulative runtime of the process when it is invoked by the target application and the power consumption per unit time of the process. Therefore, the accuracy of the final calculated indirect power consumption is closely related to the accuracy of these two parameters (cumulative runtime and power consumption per unit time).
[0072] The following section will describe how to determine the cumulative runtime using specific embodiments.
[0073] In some embodiments, for each process corresponding to the application to be detected, the following processing can be performed: each time the process is detected to be called by the target application, the runtime of the process at this time of call is recorded. The cumulative runtime includes the sum of the runtimes recorded each time the process is called by the target application, i.e., the cumulative runtime of the process when called by the target application.
[0074] For example, consider a Linux system. In Linux, when any process is invoked by any target application, it needs to receive the invocation information from the target application through the Binder thread corresponding to that process and maintain communication with the target application until the invocation is complete. Therefore, by monitoring the communication status of the Binder thread corresponding to that process and recording the application that invokes the Binder thread each time and the invocation time, the invocation time (i.e., runtime) of that process each time it is invoked by the target application can be extracted.
[0075] For example, when the Binder thread of a process receives a call from any application, it can record the application identifier (e.g., the application name or UID) that called the process, and record the start time of the Binder thread being called. At the end of this call, the duration between the end time and the start time is taken as the call duration (i.e., the runtime of the process during this call).
[0076] Next, we will combine Figure 2 and Figure 3 The method for determining power consumption per unit time is explained.
[0077] Figure 2 A flowchart illustrating a method for determining power consumption per unit time according to an embodiment of this disclosure is shown. Figure 2 As shown, after determining the process corresponding to the application to be detected, the following steps S201 to S202 can be executed for each process corresponding to the application to be detected in order to obtain the power consumption per unit time of the process.
[0078] S201, obtain the total runtime of the process and its corresponding total power consumption.
[0079] It should be noted that the total runtime can include the runtime of the process when it is invoked by any application and the runtime of the process when it is not invoked.
[0080] In other words, the total runtime obtained in this embodiment does not distinguish whether the process is initiated by the application under test corresponding to the process or by an application other than the application under test. The total runtime here can be understood as the total runtime of the process running in the system. Correspondingly, the power consumption corresponding to the total runtime can be understood as the total power consumption consumed by the process running in the system.
[0081] For example, since the total runtime of a process and its corresponding total power consumption do not distinguish between the causes of the process's execution, they can be directly obtained through a pre-defined power statistics service in the system. For instance, the BatteryStats service in Linux systems.
[0082] S202, Based on the total runtime and its corresponding total power consumption, determine the power consumption per unit time of the process.
[0083] In some embodiments, the power consumption per unit time of the process can be obtained by calculating the ratio of total power consumption to total duration.
[0084] At this point, Figure 2 The illustrated embodiment can directly determine the power consumption per unit time of a process by combining the process's total runtime and total power consumption. Since the process's total runtime and total power consumption can be directly obtained from preset services in the system, therefore... Figure 2 The illustrated embodiment is able to obtain the power consumption per unit time of the process with a small computational cost.
[0085] Figure 3 A flowchart illustrating another method for determining power consumption per unit time in an embodiment of this disclosure is shown. Figure 3 As shown, after determining the process corresponding to the application to be detected, the following S301 to S303 can be executed for each process corresponding to the application to be detected in order to obtain the power consumption per unit time of the process.
[0086] S301, Get the cumulative runtime distribution of the process when it is called by any application.
[0087] For example, the cumulative runtime distribution can show the runtime of the process at various operating frequencies of various processors. Here, each processor refers to a processor integrated into an electronic device used to run the process. In the case of a multi-core processor, embodiments of this disclosure treat each core of the multi-core processor as an independent processor.
[0088] In some embodiments, each processor is pre-configured with one or more operating frequencies, which are frequencies suitable for the processor's operation selected through pre-testing, such as frequencies that enable the processor to have a high energy efficiency ratio. When a process is scheduled to run on any processor, the processor selects a suitable operating frequency from the pre-configured operating frequencies and runs the process at that frequency.
[0089] In some embodiments, obtaining the cumulative runtime distribution involves monitoring the processor and its operating frequency, thus requiring acquisition within the system's kernel space. However, the kernel space cannot distinguish the specific application of the calling process; it can only detect whether the process is in a called or uncalled state.
[0090] Based on this, the obtained cumulative runtime distribution is the cumulative runtime distribution of a process when it is called by any application, or it can be understood as the cumulative runtime distribution of a process when it is in the called state.
[0091] S302 calculates the call duration of the process based on the cumulative runtime distribution, and calculates the power consumption of the process during the call by combining the pre-measured current of each processor at each operating frequency.
[0092] In some embodiments, the invocation duration refers to the total duration during which the process is in the invocation state. The invocation duration of the process can be obtained by summing the runtime of the process at each operating frequency of each processor obtained by S301.
[0093] In some embodiments, the power consumption of a process under a call refers to the total power consumption of the process while it is in a call state. By multiplying the runtime of the process at each operating frequency of each processor, obtained in S301, by the pre-measured corresponding current magnitude, the power consumption of the process at each operating frequency of each processor can be obtained. By summing the power consumption of the process at each operating frequency of each processor, the power consumption of the process under a call can be obtained.
[0094] S303, determine the power consumption per unit time of the process based on the duration of the call and the power consumption of the call.
[0095] In some embodiments, the power consumption per unit time of a process can be obtained by calculating the ratio of the power consumption of the called process to the duration of the called process.
[0096] Thus, with Figure 2 Compared to the illustrated embodiments, Figure 3The illustrated embodiment calculates the power consumption per unit time when the process is in a invoked state. For the same process, the runtime load may differ when it is in an invoked state and when it is not in an invoked state, therefore the power consumption per unit time may differ. Based on Figure 3 The method provided by the illustrated embodiment can calculate the power consumption per unit time when a process is in a called state separately, thereby improving the accuracy of the final calculated indirect power consumption.
[0097] To facilitate understanding, the method for obtaining the cumulative runtime distribution will be explained below with reference to specific embodiments.
[0098] In some embodiments, the cumulative runtime distribution can be obtained in the following way:
[0099] For each process corresponding to the application to be detected, the runtime distribution of the process when it is called by any application can be recorded each time it is detected that the process is called.
[0100] The cumulative runtime distribution can be obtained by accumulating the runtime distribution of the process recorded each time.
[0101] For example, the runtime distribution recorded each time includes the runtime of the process at each operating frequency of each processor. By summing the runtimes corresponding to the same operating frequency of the same processor in each recorded runtime distribution, the cumulative runtime distribution can be obtained.
[0102] In some embodiments, the runtime distribution of a process each time it is invoked can be recorded in the following manner:
[0103] Each time a process is invoked by any application, monitor the processor usage status of that process at the time of the invocation. Each time a change in processor usage status is detected, record the processor identifier, operating frequency, and duration of the process running on the target processor until the process terminates, thus obtaining the runtime distribution of the process at the time of the invocation.
[0104] For example, processor usage status includes: the processor used by the process and its operating frequency. The target processor is the processor used to run the process, which changes each time.
[0105] In other words, whenever a change is detected in the processor used by the process or the processor's operating frequency, the processor identifier, operating frequency, and duration of the process before the change can be recorded.
[0106] For example, assuming the process initially runs at 0.8 GHz on the first processor, if it is scheduled to run at 1.2 GHz on the second processor after one minute, the time of scheduling can be recorded as "CPU1, 0.8 GHz, 1 min". If the process runs at 1.2 GHz on the second processor for 30 seconds, and then the second processor's operating frequency is adjusted to 1.0 GHz, the time can be recorded as "CPU2, 1.2 GHz, 30 s".
[0107] In some embodiments, both the runtime distribution and the cumulative runtime distribution can be stored in the system's kernel space as key-value pairs. The system's kernel space can be understood as the system's kernel layer. As mentioned earlier, obtaining the cumulative runtime distribution involves monitoring the processor and its operating frequency; therefore, it needs to be obtained and stored in the system's kernel space.
[0108] For example, key-value pairs may include:
[0109] A process identifier used to indicate the target process; and
[0110] The runtime of the target process at various operating frequencies on various processors when it is invoked by any application.
[0111] In this context, the process identifier can be used as the key of the key-value pair, while the runtime of the target process at various operating frequencies on various processors can be used as the value of the key-value pair.
[0112] For example, the key-value pair can be represented as:
[0113] {Process ID}:{
[0114] CPU1: {[Runtime],[Runtime],[Runtime],[Runtime],……}
[0115] CPU2: {[Runtime],[Runtime],[Runtime],[Runtime],……}
[0116] ...
[0117] }
[0118] In this embodiment, CPU1 and CPU2 are processor identifiers, and the runtimes following each processor identifier correspond to different operating frequencies of the processor. For example, the first runtime after CPU1 corresponds to the runtime of the first processor at the first preset operating frequency; the second runtime after CPU1 corresponds to the runtime of the first processor at the second preset operating frequency, and so on. This embodiment will not be elaborated further.
[0119] In some embodiments, when obtaining the cumulative runtime distribution of a process when it is invoked by any application, the cumulative runtime distribution corresponding to the process can be obtained in the kernel space based on the process identifier of the process.
[0120] The following will combine Figure 4 Taking the Linux system architecture as an example, this paper illustrates the complete implementation process of the application power consumption detection method provided in this disclosure.
[0121] like Figure 4 As shown, the Linux system can be divided into the application layer, framework layer, native layer, and kernel layer. Both the native layer and the kernel layer contain pre-written BPF programs. The BPF program in the kernel layer monitors various system performance metrics, while the BPF program in the native layer is used to implement data interaction between user space (application layer, framework layer, native layer) and kernel space (kernel layer).
[0122] For example, the application to be detected runs in the application layer. The BatteryStats service in the framework layer can send the process identifier of each process corresponding to the application to be detected to the local layer, and the BPF program in the local layer forwards it to the BPF program in the kernel layer.
[0123] BPF programs running in the kernel can monitor the running status of processes corresponding to these process identifiers. When a process is detected to be in a called state, the cumulative running time distribution of the process is recorded in the kernel as key-value pairs.
[0124] The BPF program in the local layer can also respond to power consumption detection commands for the application to be detected, obtain the cumulative runtime distribution of the process recorded in the kernel layer, and forward it to the BinderStats service in the framework layer, so as to calculate the power consumption per unit time of the process in the framework layer.
[0125] The BinderStats service monitors the Binder thread corresponding to a process, recording the duration of each call to the process and the application that called it. By summing up the durations of each call to the process by the target application, the cumulative runtime of the process when called by the target application can be obtained. Combining the cumulative runtime of each process with the power consumption per unit time, the total indirect power consumption of the application under test when called by the target application can be calculated.
[0126] Based on this, the total power consumption of the application under test, as statistically analyzed by BatteryStats itself, can be divided into two parts: the power consumption of the application under test running itself and the power consumption of the application being called (total indirect power consumption). This allows for a more detailed display and analysis of the power consumption of the application under test.
[0127] For example, when displaying the power consumption of the application under test, the indirect power consumption generated when the application under test is called by various target applications can be removed from the total power consumption of the application under test, and the indirect power consumption can be displayed independently according to its corresponding target application.
[0128] For example, the excluded indirect power consumption can be added to the total power consumption of the corresponding target application to ensure the accuracy of the overall power consumption display.
[0129] Based on the same inventive concept, this disclosure also provides an application power consumption detection device, as shown in the following embodiment. Since the principle of this application power consumption detection device embodiment in solving the problem is the same as that described above... Figure 1 The method embodiments shown are similar, therefore, the implementation of this application power consumption detection device embodiment can be found in the above description. Figure 1 The implementation of the method embodiments shown will not be repeated here.
[0130] Figure 5 This diagram illustrates the structure of a power consumption detection device according to an embodiment of the present disclosure. Figure 5 As shown, the power consumption detection device 500 includes: a first determination module 501, a second determination module 502, and an accumulation module 503.
[0131] The first determining module 501 is used to determine the process corresponding to the application to be detected in response to the power consumption detection command for the application to be detected.
[0132] The second determining module 502 determines the indirect power consumption of each process corresponding to the application to be detected when it is called by the target application, based on the cumulative runtime of the process when it is called by the target application and the power consumption per unit time of the process.
[0133] The accumulator module 503 is used to accumulate the indirect power consumption of each process to obtain the total indirect power consumption when the application under test is called by the target application.
[0134] In some embodiments, the application power consumption detection device 500 further includes: a first recording module (not shown in the figure), which is used to perform the following processing for each process corresponding to the application to be detected: each time the process is detected to be called by the target application, the runtime of the process when it is called this time is recorded; wherein, the cumulative runtime includes: the sum of the runtime of the process recorded each time.
[0135] In some embodiments, the application power consumption detection device 500 further includes: a third determining module (not shown in the figure), configured to perform the following processing for each process corresponding to the application to be detected: obtain the total runtime of the process and its corresponding total power consumption, the total runtime including: the runtime of the process when it is called by any application and the runtime of the process when it is not called; and determine the power consumption per unit time of the process based on the total runtime and its corresponding total power consumption.
[0136] In some embodiments, the application power consumption detection device 500 further includes: a fourth determining module (not shown in the figure), configured to perform the following processing for each process corresponding to the application to be detected: obtaining the cumulative runtime distribution of the process when it is called by any application; wherein the cumulative runtime distribution is used to show the runtime of the process at each operating frequency of each processor; calculating the call duration of the process based on the cumulative runtime distribution, and calculating the call power consumption of the process by combining the pre-measured current of each processor at each operating frequency; and determining the power consumption per unit time of the process based on the call duration and the call power consumption.
[0137] In some embodiments, the application power consumption detection device 500 further includes: a second recording module (not shown in the figure), used to record the runtime distribution of each process corresponding to the application to be detected when the process is called by any application each time it is detected; and to accumulate the runtime distribution of the process recorded each time to obtain a cumulative runtime distribution.
[0138] In some embodiments, the fourth determining module is further configured to monitor the processor usage status of the process when it is invoked this time. The processor usage status includes the processor used by the process and its operating frequency. Each time a change in processor usage status is detected, the processor identifier, operating frequency, and duration of the process running are recorded until the process terminates, thus obtaining the runtime distribution of the process when it is invoked this time. The target processor is the processor used to run the process before each change.
[0139] In some embodiments, the cumulative runtime distribution is stored in the system's kernel space as key-value pairs. The key-value pairs include: a process identifier indicating the target process; and the runtime of the target process at various operating frequencies of various processors when invoked by any application. The fourth determining module is further configured to obtain the cumulative runtime distribution corresponding to the process in the kernel space based on the process identifier of the process.
[0140] The following reference Figure 6 To describe an electronic device 600 capable of implementing embodiments of the present disclosure. Figure 6The electronic device 600 shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.
[0141] like Figure 6 As shown, the electronic device 600 is presented in the form of a general-purpose computing device. The components of the electronic device 600 may include, but are not limited to: at least one processor 610, at least one memory 620, and a bus 630 connecting different system components (including memory 620 and processor 610).
[0142] The memory stores program code that can be executed by the processor 610, causing the processor 610 to perform the steps described in the "Exemplary Methods" section of this disclosure according to various exemplary embodiments of this disclosure.
[0143] In some embodiments, the processor 610 may also perform the following steps of the above method embodiments:
[0144] In response to a power consumption detection command for the application under test, determine the process corresponding to the application under test;
[0145] For each process corresponding to the application to be detected, the indirect power consumption of the process when it is called by the target application is determined based on the cumulative runtime of the process when it is called by the target application and the power consumption of the process per unit time.
[0146] The indirect power consumption of each process is summed to obtain the total indirect power consumption when the application under test is called by the target application.
[0147] The memory 620 may include a readable medium in the form of volatile memory, such as random access memory (RAM) 6201 and / or cache memory 6202, and may further include read-only memory (ROM) 6203.
[0148] The memory 620 may also include a program / utility 6204 having a set (at least one) of program modules 6205, including but not limited to: an operating system, one or more application programs, other program modules, and program data, each or some combination of these examples may include an implementation of a network environment.
[0149] Bus 630 can represent one or more of several types of bus structures, including a memory bus or memory controller, peripheral bus, graphics acceleration port, processor, or a local bus using any of the various bus structures.
[0150] Electronic device 600 can also communicate with one or more external devices 640 (e.g., keyboard, pointing device, Bluetooth device, etc.), and with one or more devices that enable a user to interact with electronic device 600, and / or with any device that enables electronic device 600 to communicate with one or more other computing devices (e.g., router, modem, etc.). This communication can be performed via input / output (I / O) interface 650. Furthermore, electronic device 600 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 660. Figure 6 As shown, network adapter 660 communicates with other modules of electronic device 600 via bus 630. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with electronic device 600, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0151] From the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, terminal device, or network device, etc.) to execute the methods according to the embodiments of this disclosure.
[0152] In exemplary embodiments of this disclosure, a computer-readable storage medium is also provided, which may be a readable signal medium or a readable storage medium. A program product capable of implementing the methods described above is stored thereon. In some possible implementations, various aspects of this disclosure may also be implemented as a program product including program code, which, when run on a terminal device, causes the terminal device to perform the steps described in the "Exemplary Methods" section of this disclosure according to various exemplary embodiments of this disclosure.
[0153] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the appended claims.
Claims
1. An application power consumption detection method, characterized by, The method comprises: in response to a power consumption detection instruction for a to-be-detected application, determining a process corresponding to the to-be-detected application; for each process corresponding to the to-be-detected application, determining an indirect power consumption of the process when the process is called by a target application according to a cumulative running time length of the process when the process is called by the target application and a unit time power consumption of the process; accumulating the indirect power consumption of each process to obtain a total indirect power consumption of the to-be-detected application when the to-be-detected application is called by the target application.
2. The method of claim 1, wherein, The method further comprises: for each process corresponding to the to-be-detected application, the following processing is performed respectively: each time the process is detected to be called by the target application, record the running time length of the process when the process is called this time; wherein the cumulative running time length comprises the sum of the running time length of the process recorded each time.
3. The method of claim 1, wherein, After the process corresponding to the to-be-detected application is determined, the method further comprises: for each process corresponding to the to-be-detected application, the following processing is performed respectively: obtain the total running time length of the process and the total power consumption corresponding thereto, the total running time length comprising the running time length of the process when the process is called by any application and the running time length of the process when the process is not called; determine the unit time power consumption of the process based on the total running time length and the total power consumption corresponding thereto.
4. The method of claim 1, wherein, After the process corresponding to the to-be-detected application is determined, the method further comprises: for each process corresponding to the to-be-detected application, the following processing is performed respectively: obtain the cumulative running time length distribution of the process when the process is called by any application; wherein the cumulative running time length distribution is used to show the running time length of the process at various working frequencies of various processors; based on the cumulative running time length distribution, calculate the called time length of the process, and in combination with the current size of each processor at each working frequency measured in advance, calculate the called power consumption of the process; determine the unit time power consumption of the process based on the called time length and the called power consumption.
5. The method of claim 4, wherein, The method further comprises: for each process corresponding to the to-be-detected application, record the running time length distribution of the process when the process is called this time each time the process is detected to be called by any application; accumulate the running time length distribution of the process recorded each time to obtain the cumulative running time length distribution.
6. The method of claim 5, wherein, The recording of the running time length distribution of the process when the process is called this time comprises: monitoring the processor usage state of the process when the process is called this time, the processor usage state comprising the processor used by the process and the working frequency thereof; each time the processor usage state is detected to change, recording the processor identifier, working frequency and running time length of the target processor until the process ends running to obtain the running time length distribution of the process when the process is called this time; wherein the target processor is the processor used to run the process before each change.
7. The method of claim 4, wherein, The cumulative running time length distribution is stored in the kernel space of the system in the form of key-value pairs; the key-value pair comprises: a process identifier used to show a target process; and the running time length of the target process at various working frequencies of various processors when the target process is called by any application; The cumulative running time distribution of the process when called by any application is acquired, including: According to the process identifier of the process, the cumulative running time distribution corresponding to the process is acquired in the kernel space.
8. An application power consumption detection apparatus characterized by comprising: Including: A first determination module is configured to determine a process corresponding to a to-be-detected application in response to a power consumption detection instruction for the to-be-detected application; A second determination module is configured to, for each process corresponding to the to-be-detected application, determine an indirect power consumption of the process when called by a target application according to the cumulative running time of the process when called by the target application and the unit time power consumption of the process; An accumulation module is configured to accumulate the indirect power consumption of each process to obtain a total indirect power consumption of the to-be-detected application when called by the target application.
9. An electronic device, comprising: Including: A processor; And A memory is configured to store executable instructions of the processor; Wherein, the processor is configured to execute the method of any one of claims 1 to 7 via executing the executable instructions.
10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the method of any one of claims 1 to 7.