CN115793837A - Power consumption acquisition method and device, electronic equipment and storage medium - Google Patents

Power consumption acquisition method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN115793837A
CN115793837A CN202211599721.XA CN202211599721A CN115793837A CN 115793837 A CN115793837 A CN 115793837A CN 202211599721 A CN202211599721 A CN 202211599721A CN 115793837 A CN115793837 A CN 115793837A
Authority
CN
China
Prior art keywords
power consumption
thread
application
linked list
obtaining
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211599721.XA
Other languages
Chinese (zh)
Inventor
吴涛
董志钢
唐小凯
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Xiaomi Mobile Software Co Ltd
Original Assignee
Beijing Xiaomi Mobile Software Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Xiaomi Mobile Software Co Ltd filed Critical Beijing Xiaomi Mobile Software Co Ltd
Priority to CN202211599721.XA priority Critical patent/CN115793837A/en
Publication of CN115793837A publication Critical patent/CN115793837A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The disclosure relates to a power consumption acquisition method and apparatus, an electronic device, and a storage medium. The method comprises the following steps: respectively acquiring application power consumption of an application program, framework power consumption of an application framework and support power consumption of the application framework for supporting the application program; and respectively acquiring the actual power consumption of the application program and the actual power consumption of the application framework according to the application power consumption, the framework power consumption and the support power consumption. In the embodiment, the power consumption of the application program and the application framework is adjusted by obtaining the support power consumption consumed by the application framework to support the application program, so that the problem that the power consumption of the application program is directly obtained or the power consumption of the application framework is inaccurate is solved, the accuracy of the actual power consumption of the application program and the application framework can be improved, and the application program with higher power consumption can be accurately positioned.

Description

Power consumption acquisition method and device, electronic equipment and storage medium
Technical Field
The present disclosure relates to the field of data processing technologies, and in particular, to a power consumption obtaining method and apparatus, an electronic device, and a storage medium.
Background
An operating system of an electronic device generally has a power consumption ranking function, that is, power consumption of each application program and each service framework is counted and ranked and displayed, so that a user can conveniently locate the application program with more power consumption.
At present, an operating system respectively counts the CPU use durations of all threads of each process in an application program according to a Kernel mechanism, and accumulates the CPU use durations of all threads to obtain the CPU use duration of the process; then, the CPU usage duration of the application program can be obtained by accumulating the CPU usage durations of all the processes. Similarly, the CPU use duration of each process in the application framework is obtained according to the method. Finally, the electronic device can display the CPU power consumption use condition of each application program and each process of the application framework process.
However, the scheme for acquiring the CPU power consumption of the application framework in the existing scheme is not accurate, which results in that the CPU power consumption of the application framework is neglected, so that a user cannot determine the actual power consumption of the application framework, and the use experience is reduced.
Disclosure of Invention
The present disclosure provides a power consumption obtaining method and apparatus, an electronic device, and a storage medium to solve the deficiencies of the related art.
According to a first aspect of the embodiments of the present disclosure, there is provided a power consumption obtaining method, adapted to an electronic device, the method including:
respectively acquiring application power consumption of an application program, framework power consumption of an application framework and support power consumption of the application framework for supporting the application program;
and respectively acquiring the actual power consumption of the application program and the actual power consumption of the application framework according to the application power consumption, the framework power consumption and the support power consumption.
Optionally, obtaining the supported power consumption of the application framework for supporting the application program includes:
in response to detecting that the application program calls the thread of the application framework, acquiring a thread calling linked list; the thread call linked list comprises at least one element;
respectively acquiring the CPU service time corresponding to each element in the at least one element;
acquiring the sum of the CPU service durations of the at least one element to obtain the CPU service duration of the application process;
and determining the power consumption of the application process according to the CPU service time of the application process to obtain the supported power consumption of the application program.
Optionally, obtaining the thread call linked list includes:
when an application program calls a thread of an application framework, an initial linked list is created, and initial elements of the initial linked list comprise an identification code of a calling thread, an identification code of a called thread and CPU (Central processing Unit) use duration;
and when the called thread is taken as a calling thread to continuously call other called threads, creating intermediate elements according to the identification codes of the calling thread, the identification codes of the other called threads and the CPU use duration of the other called threads, adding the intermediate elements to the initial linked list, and obtaining the thread calling linked list comprising at least one element.
Optionally, obtaining the thread call linked list includes:
acquiring a preset thread calling linked list, wherein the thread calling linked list comprises a plurality of preset elements;
and modifying the data of the corresponding elements in the thread call linked list according to the call thread, the called thread and the CPU use duration to obtain the thread call linked list comprising at least one element.
Optionally, the respectively obtaining the CPU usage durations corresponding to the elements in the at least one element includes:
acquiring the initial use duration corresponding to the called thread in each element when starting to call;
acquiring the corresponding use ending duration of the called thread in each element when the calling is ended;
and acquiring a difference value between the ending using time length and the initial using time length, and taking the difference value as the CPU using time length of each called thread.
Optionally, obtaining actual power consumptions of the application program and the application framework according to the application power consumption, the framework power consumption, and the support power consumption respectively includes:
acquiring the sum of the application power consumption and the support power consumption to obtain the actual power consumption of the application program;
and obtaining the difference value between the frame power consumption and the support power consumption to obtain the actual power consumption of the application frame.
Optionally, the method further comprises:
ranking the actual power consumption of the application program and the actual power consumption of the application framework;
displaying the application programs and the application framework in a sorted order.
According to a second aspect of the embodiments of the present disclosure, there is provided a power consumption obtaining apparatus, adapted to an electronic device, the apparatus including:
the application power consumption acquisition module is used for acquiring the application power consumption of the application program;
the framework power consumption acquisition module is used for acquiring the framework power consumption of the application program;
a support power consumption obtaining module, configured to obtain support power consumption of the application framework for supporting the application program;
and the actual power consumption acquisition module is used for respectively acquiring the actual power consumption of the application program and the actual power consumption of the application framework according to the application power consumption, the framework power consumption and the support power consumption.
Optionally, the module for obtaining supported power consumption includes:
the linked list obtaining submodule is used for responding to the detection that the application program calls the thread of the application frame and obtaining a thread calling linked list; the thread call linked list comprises at least one element;
the thread duration obtaining submodule is used for respectively obtaining the CPU use duration corresponding to each element in the at least one element;
the process duration obtaining submodule is used for obtaining the sum of the CPU usage durations of the at least one element to obtain the CPU usage duration of the application process;
and the supported power consumption obtaining submodule is used for determining the power consumption of the application process according to the CPU service duration of the application process to obtain the supported power consumption of the application program.
Optionally, the linked list obtaining sub-module includes:
the system comprises an initial linked list creating unit, a judging unit and a judging unit, wherein the initial linked list creating unit is used for creating an initial linked list when an application program calls a thread of an application frame, and initial elements of the initial linked list comprise an identification code of a calling thread, an identification code of a called thread and CPU (central processing unit) use time;
and the thread linked list obtaining unit is used for creating intermediate elements according to the identification codes of the calling threads, the identification codes of other called threads and the CPU use duration of other called threads when the called threads serve as calling threads to continuously call other called threads, and adding the intermediate elements to the initial linked list to obtain the thread calling linked list comprising at least one element.
Optionally, the linked list obtaining sub-module includes:
the device comprises a preset linked list creating unit, a thread calling linked list generating unit and a thread calling linked list generating unit, wherein the preset linked list creating unit is used for acquiring a preset thread calling linked list which comprises a plurality of preset elements;
and the thread linked list obtaining unit is used for modifying the data of the corresponding elements in the thread calling linked list according to the calling thread, the called thread and the CPU service time to obtain the thread calling linked list comprising at least one element.
Optionally, the thread duration obtaining sub-module includes:
the device comprises an initial duration obtaining unit, a thread calling unit and a thread calling unit, wherein the initial duration obtaining unit is used for obtaining the corresponding initial use duration of a called thread in each element when the called thread starts to be called;
the end duration obtaining unit is used for obtaining the end use duration corresponding to the called thread in each element when the calling is ended;
and the thread duration obtaining unit is used for obtaining the difference value between the ending use duration and the initial use duration and taking the difference value as the CPU use duration of each called thread.
Optionally, the actual power consumption obtaining module includes:
the application power consumption obtaining submodule is used for obtaining the sum of the application power consumption and the support power consumption to obtain the actual power consumption of the application program;
and the frame power consumption acquisition submodule is used for acquiring the difference value between the frame power consumption and the support power consumption to obtain the actual power consumption of the application frame.
Optionally, the apparatus further comprises:
the actual power consumption sequencing module is used for sequencing the actual power consumption of the application program and the actual power consumption of the application framework;
and the program frame display module is used for displaying the application programs and the application frames according to the sequencing order.
According to a third aspect of the embodiments of the present disclosure, there is provided an electronic apparatus including:
a memory and a processor;
the memory is to store a computer program executable by the processor;
the processor is configured to execute the computer program in the memory to implement the method according to any of the first aspect.
According to a fourth aspect of embodiments of the present disclosure, there is provided a non-transitory computer readable storage medium, in which an executable computer program is capable of implementing the method according to any one of the first aspect when executed by a processor.
The technical scheme provided by the embodiment of the disclosure can have the following beneficial effects:
in the scheme provided by the embodiment of the disclosure, the application power consumption of an application program, the framework power consumption of an application framework and the support power consumption of the application framework for supporting the application program can be respectively obtained; and then, respectively acquiring the actual power consumption of the application program and the actual power consumption of the application framework according to the application power consumption, the framework power consumption and the support power consumption. In this way, in the embodiment, the power consumption of the application program and the application framework is adjusted by obtaining the support power consumption consumed by the application framework to support the application program, so that the problem of directly obtaining the power consumption of the application program or inaccurate power consumption of the application framework is solved, the accuracy of the actual power consumption of the application program and the application framework can be improved, and the application program with high power consumption can be accurately positioned.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and together with the description, serve to explain the principles of the disclosure.
FIG. 1 is a block diagram illustrating a client invoking a server thread in accordance with an exemplary embodiment.
Fig. 2 is a flow chart illustrating a power consumption acquisition method according to an example embodiment.
FIG. 3 is a flow diagram illustrating acquisition of supported power consumption according to an example embodiment.
FIG. 4 is a flowchart illustrating a method for obtaining a thread call linked list in accordance with an illustrative embodiment.
FIG. 5 is a block diagram illustrating CPU usage durations for client-invoked server threads in accordance with an illustrative embodiment.
Fig. 6 is a block diagram illustrating a power consumption acquisition apparatus according to an exemplary embodiment.
FIG. 7 is a block diagram of an electronic device shown in accordance with an example embodiment.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. The following description refers to the accompanying drawings in which the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The following exemplary described embodiments do not represent all embodiments consistent with the present disclosure. Rather, they are merely examples of devices consistent with certain aspects of the present disclosure as recited in the claims below. It should be noted that, in the following examples and embodiments, features may be combined with each other without conflict.
In consideration of the fact that the scheme for determining the CPU power consumption of the application framework in the related art is not accurate, the process of the application framework may continue to call other processes when the application program calls the process of the application framework, and the power consumption of the processes is counted within the power consumption of the application framework, so that the actual power consumption of the application framework and the actual power consumption of the application program are deviated, that is, a part of the power consumption of the application program is hidden within the actual power consumption of the application framework, so that a user cannot determine the actual power consumption of the application framework, and the use experience is reduced.
In order to solve the technical problem, embodiments of the present disclosure provide a power consumption obtaining method and apparatus, an electronic device, and a storage medium. The power consumption obtaining method is applicable to electronic devices, which may include, but are not limited to, smart phones, smart watches, smart glasses, vehicle devices, and the like, and may be selected according to a specific scenario. The electronic equipment is internally provided with an operating system which can support a plurality of application programs to be installed in the electronic equipment and support the normal operation of the application programs.
The operating system includes an application framework (Frame) with which applications can communicate. Taking an Android operating system as an example, the Android operating system comprises a Blinder driving module; the application program can communicate with the application framework through the Blinder driver module, and an interface code file between the client and the server is defined through the AIDL file and generated in a compiling mode.
The application program initiates an initial request, blinder driving is carried out through Blinder communication to find out a server process, the application framework serves as a server to respond, and specific implementation of the server is called through an interface code file, so that one-time interprocess communication is completed. Then, in the subsequent communication interaction process, the application framework serves as a client, and the process called by the application framework serves as a server.
And repeating the communication interaction process until the bottom layer resources (such as a microphone, a camera and the like) of the electronic equipment are operated or the whole calling process is completed.
Based on the above, the inventive concept of the present disclosure is to count the CPU usage time consumed by the application program from the calling of the API interface of the application framework, i.e. the thread calling the application framework, to the subsequent direct or indirect thread call introduced by the calling thread, and then correct the power consumption of the application program and/or the application framework according to the CPU usage time caused by the calling thread, thereby obtaining the actual power consumption of the application program and the application framework, referring to fig. 1.
In order to implement the above inventive concept, the conversion file of the aid dl file in the present disclosure, for example, the aid dl file includes an API interface of an application framework and interface parameters thereof, which can be converted into a JAVA execution file; the CPU lifetime obtaining function may be increased before and after each API interface when converting to JAVA execution files. Then, the processor of the electronic device may compile the JAVA execution file into a compiled file. When the thread of the application framework is called, the application program can send a request, and then the application framework executes the compiled file to obtain the API interface called in the request and convert the API interface into the corresponding thread, namely the use time length obtaining function, the called thread and the use time length obtaining function, so that the effect of obtaining the calling time length of the called thread (equal to the CPU use time length of the called thread) is achieved.
Fig. 2 is a flow chart illustrating a power consumption acquisition method according to an example embodiment. Referring to fig. 1, a power consumption acquisition method includes steps 21 to 22.
In step 21, the application power consumption of the application program, the framework power consumption of the application framework, and the support power consumption of the application framework supporting the application program are respectively obtained.
In this step, the processor of the electronic device may obtain the application power consumption of the application program, the framework power consumption of the application framework, and the support power consumption of the application framework for supporting the application program.
In an example, taking the example that the processor obtains the application power consumption of the application program, the application program may include a plurality of processes, and each process may include at least one thread. The processor obtains the CPU power consumption of each thread of the application. For example, before calling a thread, the processor may obtain an identification number (e.g., pin, task, thread number, schedulstat, proc) of the thread, and for example, before calling a server thread, the processor may obtain a thread number of the current thread by using a preset function model GetThreadID of the javaAPI, and then obtain a CPU usage duration used by the current thread according to the thread number. Finally, the processor can accumulate the CPU power consumption of all threads to obtain the application power consumption of the application program.
In an example, taking the case that the processor obtains the framework power consumption of the application framework as an example, the application framework may include a plurality of processes, and each process may include at least one thread. The processor obtains the CPU power consumption of each thread of the application framework. For example, prior to invoking a thread, the processor may obtain an identification number (e.g., pid, task, thread number, schedulstat, proc) of the thread, and so on. Then, the processor can obtain the thread number of the current thread by using the preset function model GetThreadID of the javaAPI before the application program calls the server thread, and then obtain the CPU use duration used by the current thread according to the thread number. And finally, the processor can accumulate the CPU power consumption of all threads to obtain the frame power consumption of the application frame.
It is understood that the processor may obtain the application power consumption of the application program and/or the framework power consumption of the application framework in real time or according to a set period (e.g., 1-200 ms). In an example, the processor may obtain the application power consumption of the last cycle of the application program and the frame power consumption of the last week of the application frame for use, thereby improving data acquisition efficiency.
In this example, taking the example that the processor obtains the support power consumption of the application framework for supporting the application program, referring to fig. 3, the method includes steps 31 to 34.
In step 31, in response to detecting that the application program calls the thread of the application framework, acquiring a thread call linked list; the thread invocation linked list includes at least one element.
In this step, the processor may obtain whether the application calls the thread of the application framework, that is, whether the application calls the API interface of the application framework. When detecting that the application program calls the thread of the application framework, that is, the processor identifies that the CPU usage duration of the calling thread needs to be counted, the processor may obtain a thread calling linked list, see fig. 4, including step 41 to step 42.
In step 41, when the application calls a thread of the application framework, the processor may create an initial linked list whose initial elements include an identification of the calling thread, an identification of the called thread, and a CPU usage duration. The initial value of the CPU lifetime is 0.
In step 42, when the called thread continues to call other called threads as a calling thread, the processor may create an intermediate element according to the identifier of the calling thread, the identifiers of the other called threads, and the CPU utilization durations of the other called threads, and add the intermediate element to the initial linked list to obtain a thread calling linked list including at least one element.
It should be noted that, in step 42, when the called thread has a need to call other threads, it becomes a new calling thread, and the new calling thread can call other called threads. The process of thread calling is described by taking the application program as a client and the application framework as a server as an example, referring to fig. 5, a process with an identification code Pid in the client can communicate with a thread a of the application framework through a Binder driver, at this time, the calling thread is a thread Pid, and the called thread is a thread a. Then, the thread A communicates with the thread B through the Binder driver, the calling thread is the thread A, and the called thread is the thread B. It should be noted that, fig. 5 also illustrates that the identifier of the calling thread includes a process identifier and a thread identifier, because each process may include multiple threads, the process identifier needs to be added for distinction, and the called threads are the same.
It can be understood that, the conversion between the calling thread and the called thread and the above-mentioned "application program calls the application framework first" as described in the above embodiment, at this time, the application program is the client and the application framework is the server; the application framework in the subsequent interaction serves as a client, and the process called by the application framework serves as a server; and repeating the communication interaction process until the scheme called to the bottom layer resource is consistent. And creating an intermediate element by calling the identification code of the process, the identification code of the called process and the CPU use duration of the called process every time other processes are called, adding the intermediate element into the linked list, and repeating the processes at least once to obtain a thread calling linked list.
In an example, the processor may pre-create at least one thread call linked list and store into the cache, each thread call linked list including a preset number of elements. When the requirement for creating the thread call linked list is determined, the processor can select any one of the thread call linked lists, and sequentially write data of newly added elements, such as an identification code of a call thread, an identification code of a called thread and CPU (central processing unit) use time, into each element in the thread call linked list according to the sequence of the newly added elements. The data written into the newly added element is the data for modifying the corresponding element in the thread call linked list created in advance.
It can be understood that, in the process of writing the newly added elements into the thread call linked list, when the number of the elements in the thread call linked list created in advance is insufficient, the processor can continue to create new elements at this time, thereby meeting the demand of process call. After the thread calling is finished, the processor can restore the data of the corresponding element in the thread calling linked list to a default value, so that the effect of destroying the element is achieved. Thus, in this example, the consumption of creating the destruction linked list can be reduced by creating the thread call linked list in advance and modifying the element data in the thread call linked list.
In step 32, the processor may respectively obtain the CPU usage durations corresponding to the respective elements of the at least one element.
It will be understood that the linked list of thread calls acquired in step 31 may include the processes (or threads) involved in the various stages of call of the application to the underlying resource, and the CPU usage duration of the process of each stage may be calculated.
The processor may begin computing from the last element of the thread call linked list, e.g., when detecting that the interface file begins calling each called thread, the processor may obtain an initial usage duration for each called thread.
Then, when detecting that the interface file finishes calling each called thread after executing one thread call, the processor can acquire the finish use duration of each called thread.
The processor may then obtain the difference between the end-of-use duration and the initial-use duration, and use the difference as the CPU-use duration for each invoked thread.
When the interface file finishes one thread calling, the processor can accumulate the CPU use time consumed by the current thread calling to the sum of the CPU use time of the previous element, delete the last element in the thread calling linked list, and at the moment, the thread calling linked list is shortened.
In step 33, the processor may obtain a sum of the CPU usage durations of the at least one element to obtain the CPU usage duration of the application process.
In this step, the processor may repeat the scheme in step 32, when the current element is the middle element in the process call list, the processor may delete the last element in the process call list, until the only element remains in the thread call linked list, which indicates that the call flow returns to the application program (or the source client), and the processor may obtain the sum of the CPU usage durations of the at least one element, to obtain the CPU usage duration of the application process. And the processor can destroy or reset the thread call linked list. With reference to fig. 5, since the thread B and the thread a can only be executed in sequence and the thread call linked list is not bifurcated, the CPU usage duration corresponding to the thread pid is the sum of the CPU usage duration of the thread B and the CPU usage duration of the thread a.
In this step, the processor may persist the CPU usage duration of the application process after acquiring it, so as to facilitate subsequent sorting or display.
In step 34, the processor may determine the power consumption of the application process according to the CPU usage duration of the application process, and obtain the supported power consumption of the application program.
In this step, the unit power consumption consumed by the CPU unit usage duration at different refresh frequencies is pre-stored in the electronic device. At this time, the processor may obtain a current refresh frequency of the electronic device, and determine a target unit power consumption corresponding to the current refresh frequency. Then, the processor may obtain a product of the CPU usage duration of the application process and the target unit power consumption, and take the product as the power consumption of the application process. It is understood that the application program includes a plurality of application processes, and after calculating the power consumption of each application process, the processor may accumulate the power consumption of all the processes of the application program and use the accumulated value as the supported power consumption of the application program. It is understood that the above-mentioned support power consumption refers to the communication power consumption between the application program and the calling thread of the application framework, i.e. the power consumption consumed by the application program and the communication process calling the application framework in order to call the underlying resource.
In step 22, the actual power consumptions of the application program and the application framework are respectively obtained according to the application power consumption, the framework power consumption and the support power consumption.
In this step, the processor may obtain a sum of the application power consumption of the application program and the above-mentioned support power consumption, and use the sum as the actual power consumption of the application program. And/or the processor can obtain the difference value between the framework power consumption of the application framework and the support power consumption, and the difference value is used as the actual power consumption of the application framework.
In this step, the processor may rank the actual power consumption of the application program and the actual power consumption of the application framework, for example, from large to small. The processor may then display the applications and application frameworks in an order.
It should be noted that, in this step, a scheme for obtaining the ranking display of the actual power consumption of the application program and the application framework is described. In some scenarios, the actual power consumption is displayed in a sequence only when the user queries, at this time, the application power consumption of the application program may become the total power consumption from the application program starting time to the user querying time, correspondingly, the frame power consumption of the application frame becomes the total power consumption from the application frame starting time to the user querying time, and the support power consumption of the application program becomes the total power consumption of all the support power consumptions from the application program starting time to the user querying time.
Therefore, in the scheme provided by the embodiment of the present disclosure, the application power consumption of an application program, the framework power consumption of an application framework, and the support power consumption of the application framework for supporting the application program may be obtained respectively; and then, respectively acquiring the actual power consumption of the application program and the actual power consumption of the application framework according to the application power consumption, the framework power consumption and the support power consumption. In this way, in the embodiment, the actual power consumption of the application program and the application framework is adjusted by obtaining the support power consumption of the application framework supporting the application program, so that the accuracy of the actual power consumption of the application program and the application framework can be improved, the effect of eliminating the problem of directly obtaining the power consumption of the application program or inaccurate power consumption of the application framework is achieved, and the method is favorable for accurately positioning the application program with high power consumption. That is to say, in this step, the power consumption of the application program hidden by the application framework can be reflected, so that the application program with more power consumption and the power consumption services in the application program, such as timing storage cleaning, deadlock detection, application behavior recording and management behavior, persistent writing of system data, triggering of a specific behavior when the memory is insufficient, adding of a thread by a manufacturer for a specific function, and the like, can be conveniently located, and the effect of reducing the power consumption of the application program is achieved.
On the basis of the power consumption obtaining method provided by the embodiment of the present disclosure, the present disclosure further provides a power consumption obtaining apparatus, referring to fig. 6, the apparatus includes:
an application power consumption obtaining module 61, configured to obtain application power consumption of an application program;
a framework power consumption obtaining module 62, configured to obtain framework power consumption of the application program;
a supported power consumption obtaining module 63, configured to obtain supported power consumption of the application framework for supporting the application program;
an actual power consumption obtaining module 64, configured to obtain actual power consumption of the application program and the actual power consumption of the application framework according to the application power consumption, the framework power consumption, and the support power consumption.
In one embodiment, the supported power consumption obtaining module includes:
the linked list obtaining submodule is used for responding to the detection that the application program calls the thread of the application frame and obtaining a thread calling linked list; the thread call linked list comprises at least one element;
the thread duration obtaining submodule is used for respectively obtaining the CPU use duration corresponding to each element in the at least one element;
the process duration obtaining submodule is used for obtaining the sum of the CPU usage durations of the at least one element to obtain the CPU usage duration of the application process;
and the supported power consumption obtaining submodule is used for determining the power consumption of the application process according to the CPU service duration of the application process to obtain the supported power consumption of the application program.
In one embodiment, the linked list obtaining sub-module includes:
the system comprises an initial linked list creating unit, a judging unit and a judging unit, wherein the initial linked list creating unit is used for creating an initial linked list when an application program calls a thread of an application frame, and initial elements of the initial linked list comprise an identification code of a calling thread, an identification code of a called thread and CPU (central processing unit) use time;
and the thread linked list obtaining unit is used for creating intermediate elements according to the identification codes of the calling threads, the identification codes of other called threads and the CPU use duration of other called threads when the called threads serve as calling threads to continuously call other called threads, and adding the intermediate elements to the initial linked list to obtain the thread calling linked list comprising at least one element.
In one embodiment, the linked list obtaining sub-module includes:
the device comprises a preset linked list creating unit, a thread calling linked list generating unit and a thread calling linked list generating unit, wherein the preset linked list creating unit is used for acquiring a preset thread calling linked list which comprises a plurality of preset elements;
and the thread linked list obtaining unit is used for modifying the data of the corresponding elements in the thread calling linked list according to the calling thread, the called thread and the CPU service time to obtain the thread calling linked list comprising at least one element.
In one embodiment, the thread duration obtaining sub-module includes:
the device comprises an initial duration obtaining unit, a thread calling unit and a thread calling unit, wherein the initial duration obtaining unit is used for obtaining the corresponding initial use duration of a called thread in each element when the called thread starts to be called;
the end duration obtaining unit is used for obtaining the end use duration corresponding to the called thread in each element when the calling is ended;
and the thread duration obtaining unit is used for obtaining the difference value between the ending use duration and the initial use duration and taking the difference value as the CPU use duration of each called thread.
In one embodiment, the actual power consumption obtaining module includes:
the application power consumption obtaining submodule is used for obtaining the sum of the application power consumption and the support power consumption to obtain the actual power consumption of the application program;
and the frame power consumption obtaining submodule is used for obtaining the difference value between the frame power consumption and the support power consumption to obtain the actual power consumption of the application frame.
In one embodiment, the apparatus further comprises:
the actual power consumption sequencing module is used for sequencing the actual power consumption of the application program and the actual power consumption of the application framework;
and the program frame display module is used for displaying the application programs and the application frames according to the sequencing order.
It should be noted that, the contents of the system embodiment shown in this embodiment and the method embodiment described above are matched, and reference may be made to the contents of the method embodiment described above, which is not described herein again.
FIG. 7 is a block diagram of an electronic device shown in accordance with an example embodiment. For example, the electronic device 700 may be a smart phone, a computer, a digital broadcasting terminal, a tablet device, a medical device, an exercise device, a personal digital assistant, and the like, as well as the above-mentioned in-vehicle device, and the like.
Referring to fig. 7, electronic device 700 may include one or more of the following components: processing component 702, memory 704, power component 706, multimedia component 708, audio component 710, input/output (I/O) interface 712, sensor component 714, communication component 716, image capture component 718.
The processing component 702 generally controls overall operation of the electronic device 700, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations. The processing component 702 may include one or more processors 720 to execute computer programs. Further, the processing component 702 may include one or more modules that facilitate interaction between the processing component 702 and other components. For example, the processing component 702 may include a multimedia module to facilitate interaction between the multimedia component 708 and the processing component 702.
The memory 704 is configured to store various types of data to support operations at the electronic device 700. Examples of such data include computer programs for any application or method operating on the electronic device 700, contact data, phonebook data, messages, pictures, videos, and so forth. The memory 704 may be implemented by any type or combination of volatile or non-volatile storage devices, such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disks.
The power supply component 706 provides power to the various components of the electronic device 700. The power components 706 may include a power management system, one or more power sources, and other components associated with generating, managing, and distributing power for the electronic device 700. The power supply 706 may include a power chip, and the controller may communicate with the power chip to control the power chip to turn on or off the switching device, so that the battery supplies power or does not supply power to the motherboard circuit.
The multimedia component 708 includes a screen that provides an output interface between the electronic device 700 and the target object. In some embodiments, the screen may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input information from the target object. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.
The audio component 710 is configured to output and/or input audio file information. For example, the audio component 710 includes a Microphone (MIC) configured to receive external audio file information when the electronic device 700 is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio file information may further be stored in the memory 704 or transmitted via the communication component 716. In some embodiments, audio component 710 also includes a speaker for outputting audio file information.
The I/O interface 712 provides an interface between the processing component 702 and peripheral interface modules, which may be keyboards, click wheels, keys, etc.
The sensor assembly 714 includes one or more sensors for providing various aspects of status assessment for the electronic device 700. For example, the sensor component 714 may detect an open/closed state of the electronic device 700, the relative positioning of components, such as a display and keypad of the electronic device 700, the sensor component 714 may also detect a change in the position of the electronic device 700 or one of the components, the presence or absence of a target object in contact with the electronic device 700, orientation or acceleration/deceleration of the electronic device 700, and a change in the temperature of the electronic device 700. In this example, the sensor assembly 714 may include a magnetic sensor, a gyroscope, and a magnetic field sensor, wherein the magnetic field sensor includes at least one of: hall sensor, thin film magneto-resistance sensor, magnetic liquid acceleration sensor.
The communication component 716 is configured to facilitate wired or wireless communication between the electronic device 700 and other devices. The electronic device 700 may access a wireless network based on a communication standard, such as WiFi,2G, 3G, 4G, 5G, or a combination thereof. In an exemplary embodiment, the communication component 716 receives broadcast information or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 716 further includes a Near Field Communication (NFC) module to facilitate short-range communications. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, ultra Wideband (UWB) technology, bluetooth (BT) technology, and other technologies.
In an exemplary embodiment, the electronic device 700 may be implemented by one or more Application Specific Integrated Circuits (ASICs), digital information processors (DSPs), digital information processing devices (DSPDs), programmable Logic Devices (PLDs), field Programmable Gate Arrays (FPGAs), controllers, micro-controllers, microprocessors, or other electronic components.
In an exemplary embodiment, there is also provided an electronic device including:
a memory and a processor;
the memory is to store a computer program executable by the processor;
the processor is configured to execute the computer program in the memory to implement the method as described above.
In an exemplary embodiment, a non-transitory computer readable storage medium, such as the memory 704 including instructions, is also provided, the executable computer program described above being executable by the processor. The readable storage medium may be, among others, ROM, random Access Memory (RAM), CD-ROM, magnetic tape, floppy disk, optical data storage device, and the like.
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.
It will be understood that the present disclosure is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims (16)

1. A power consumption acquisition method applicable to an electronic device, the method comprising:
respectively acquiring application power consumption of an application program, framework power consumption of an application framework and support power consumption of the application framework for supporting the application program;
and respectively acquiring the actual power consumption of the application program and the actual power consumption of the application framework according to the application power consumption, the framework power consumption and the support power consumption.
2. The method of claim 1, wherein obtaining the supported power consumption of the application framework to support the application program comprises:
in response to detecting that the application program calls the thread of the application framework, acquiring a thread calling linked list; the thread call linked list comprises at least one element;
respectively acquiring the CPU service time corresponding to each element in the at least one element;
acquiring the sum of the CPU use duration of the at least one element to obtain the CPU use duration of the application process;
and determining the power consumption of the application process according to the CPU service life of the application process to obtain the supported power consumption of the application program.
3. The method of claim 2, wherein obtaining a thread call linked list comprises:
when an application program calls a thread of an application framework, an initial linked list is created, and initial elements of the initial linked list comprise an identification code of a calling thread, an identification code of a called thread and CPU (Central processing Unit) use duration;
and when the called thread is taken as a calling thread to continuously call other called threads, creating intermediate elements according to the identification codes of the calling thread, the identification codes of the other called threads and the CPU use duration of the other called threads, adding the intermediate elements to the initial linked list, and obtaining the thread calling linked list comprising at least one element.
4. The method of claim 2, wherein obtaining a thread call linked list comprises:
acquiring a preset thread calling linked list, wherein the thread calling linked list comprises a plurality of preset elements;
and modifying the data of the corresponding elements in the thread call linked list according to the call thread, the called thread and the CPU use duration to obtain the thread call linked list comprising at least one element.
5. The method according to claim 2, wherein the step of respectively obtaining the CPU durations corresponding to the respective elements of the at least one element comprises:
acquiring initial use duration corresponding to the called thread in each element when starting to call;
acquiring the corresponding use ending duration of the called thread in each element when the calling is ended;
and acquiring a difference value between the ending use time length and the initial use time length, and taking the difference value as the CPU use time length of each called thread.
6. The method of claim 1, wherein obtaining actual power consumption of the application program and the application framework according to the application power consumption, the framework power consumption, and the supported power consumption comprises:
acquiring the sum of the application power consumption and the support power consumption to obtain the actual power consumption of the application program;
and obtaining the difference value between the frame power consumption and the support power consumption to obtain the actual power consumption of the application frame.
7. The method of claim 1, further comprising:
sorting the actual power consumption of the application program and the actual power consumption of the application framework;
displaying the application programs and the application framework in a sorted order.
8. A power consumption acquisition apparatus adapted for an electronic device, the apparatus comprising:
the application power consumption acquisition module is used for acquiring the application power consumption of the application program;
the framework power consumption acquisition module is used for acquiring the framework power consumption of the application program;
a support power consumption obtaining module, configured to obtain support power consumption of the application framework for supporting the application program;
and the actual power consumption acquisition module is used for respectively acquiring the actual power consumption of the application program and the actual power consumption of the application framework according to the application power consumption, the framework power consumption and the support power consumption.
9. The apparatus of claim 8, wherein the means for supporting power consumption comprises:
the linked list obtaining submodule is used for responding to the detection that the application program calls the thread of the application frame and obtaining a thread calling linked list; the thread call linked list comprises at least one element;
the thread duration obtaining submodule is used for respectively obtaining the CPU use duration corresponding to each element in the at least one element;
the process duration obtaining submodule is used for obtaining the sum of the CPU usage durations of the at least one element to obtain the CPU usage duration of the application process;
and the supported power consumption obtaining submodule is used for determining the power consumption of the application process according to the CPU service duration of the application process to obtain the supported power consumption of the application program.
10. The apparatus of claim 9, wherein the linked list obtaining sub-module comprises:
the system comprises an initial linked list creating unit, a judging unit and a judging unit, wherein the initial linked list creating unit is used for creating an initial linked list when an application program calls a thread of an application frame, and initial elements of the initial linked list comprise an identification code of a calling thread, an identification code of a called thread and CPU (central processing unit) use time;
and the thread linked list obtaining unit is used for creating intermediate elements according to the identification codes of the calling threads, the identification codes of other called threads and the CPU use duration of other called threads when the called threads serve as calling threads to continuously call other called threads, and adding the intermediate elements to the initial linked list to obtain the thread calling linked list comprising at least one element.
11. The apparatus of claim 9, wherein the linked list obtaining sub-module comprises:
the device comprises a preset linked list creating unit, a thread calling linked list generating unit and a thread calling linked list generating unit, wherein the preset linked list creating unit is used for acquiring a preset thread calling linked list which comprises a plurality of preset elements;
and the thread linked list acquisition unit is used for modifying the data of the corresponding elements in the thread call linked list according to the call thread, the called thread and the CPU service time to obtain the thread call linked list comprising at least one element.
12. The apparatus of claim 11, wherein the thread duration obtaining sub-module comprises:
the device comprises an initial duration obtaining unit, a thread calling unit and a thread calling unit, wherein the initial duration obtaining unit is used for obtaining the corresponding initial use duration of a called thread in each element when the called thread starts to be called;
the end duration obtaining unit is used for obtaining the end use duration corresponding to the called thread in each element when the calling is ended;
and the thread duration obtaining unit is used for obtaining the difference value between the ending use duration and the initial use duration and taking the difference value as the CPU use duration of each called thread.
13. The apparatus of claim 8, wherein the actual power consumption obtaining module comprises:
the application power consumption obtaining submodule is used for obtaining the sum of the application power consumption and the support power consumption to obtain the actual power consumption of the application program;
and the frame power consumption obtaining submodule is used for obtaining the difference value between the frame power consumption and the support power consumption to obtain the actual power consumption of the application frame.
14. The apparatus of claim 8, further comprising:
the actual power consumption sequencing module is used for sequencing the actual power consumption of the application program and the actual power consumption of the application framework;
and the program frame display module is used for displaying the application programs and the application frames according to the sequencing order.
15. An electronic device, comprising:
a memory and a processor;
the memory is to store a computer program executable by the processor;
the processor is configured to execute the computer program in the memory to implement the method according to any one of claims 1 to 7.
16. A non-transitory computer readable storage medium, wherein an executable computer program in the storage medium, when executed by a processor, is capable of implementing the method of any one of claims 1 to 7.
CN202211599721.XA 2022-12-12 2022-12-12 Power consumption acquisition method and device, electronic equipment and storage medium Pending CN115793837A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211599721.XA CN115793837A (en) 2022-12-12 2022-12-12 Power consumption acquisition method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211599721.XA CN115793837A (en) 2022-12-12 2022-12-12 Power consumption acquisition method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115793837A true CN115793837A (en) 2023-03-14

Family

ID=85419796

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211599721.XA Pending CN115793837A (en) 2022-12-12 2022-12-12 Power consumption acquisition method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115793837A (en)

Similar Documents

Publication Publication Date Title
EP2945058A1 (en) Processing method and device for application program
EP3242203A1 (en) Method for operating a display device and display device
US11256525B2 (en) Object starting method and device
US10642456B2 (en) Application distribution method and device
CN107193606B (en) Application distribution method and device
CN108182085B (en) Terminal screen awakening method and device, terminal and storage medium
CN111695064B (en) Buried point loading method and device
CN110968492B (en) Information processing method and device and storage medium
CN116048757A (en) Task processing method, device, electronic equipment and storage medium
CN112363825A (en) Elastic expansion method and device
CN115793837A (en) Power consumption acquisition method and device, electronic equipment and storage medium
CN113407879B (en) Data reporting method, device and readable medium
CN110457084B (en) Loading method and device
CN114066370A (en) Inventory service calling method, device, equipment, storage medium and program product
CN113641431A (en) Method and terminal equipment for enhancing display of two-dimensional code
CN113268325A (en) Method, device and storage medium for scheduling task
CN112256445A (en) Data processing method, device and equipment based on application program and storage medium
CN112486658A (en) Task scheduling method and device for task scheduling
CN112000932A (en) Mobile terminal and application control method thereof
CN111459494A (en) Code processing method and device
CN111625251B (en) Method and device for processing application instance
CN112000841B (en) Electronic tag data processing method and device, electronic equipment and storage medium
CN112905255A (en) Information processing method and device and electronic equipment
CN114780334A (en) Power consumption monitoring method, power consumption monitoring device and storage medium
CN114115863A (en) Data processing method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination