Power consumption detection method and device, electronic equipment and storage medium

文档序号:1576940 发布日期:2020-01-31 浏览:33次 中文

阅读说明:本技术 耗电量检测方法、装置、电子设备及存储介质 (Power consumption detection method and device, electronic equipment and storage medium ) 是由 夏宏伟 于 2019-09-25 设计创作,主要内容包括:本发明实施例公开了一种耗电量检测方法、装置、电子设备及存储介质,其中,方法包括:遍历CPU线程,得到第一线程列表,再次遍历CPU线程,得到第二线程列表,根据所述第一线程列表及所述第二线程列表确定所述第二线程列表中各个线程从所述第一时间到所述第二时间所占用的CPU时间片;根据所述第二线程列表中各个线程从所述第一时间到所述第二时间所占用的CPU时间片确定所述第二线程列表中各个线程的耗电状态,将所述第二线程列表中耗电状态为异常状态的线程确定为目标线程,获取与所述目标线程匹配的省电策略,采用所述省电策略对所述目标线程进行处理。本发明实施例通过对耗电异常的线程进行处理,能够节省电子设备的耗电量。(The embodiment of the invention discloses power consumption detection methods and devices, electronic equipment and a storage medium, wherein the method comprises the steps of traversing a CPU thread to obtain a thread list, traversing the CPU thread again to obtain a second thread list, determining a CPU time slice occupied by each thread in the second thread list from the th time to the second time according to the thread list and the second thread list, determining the power consumption state of each thread in the second thread list according to the CPU time slice occupied by each thread in the second thread list from the th time to the second time, determining the thread with the power consumption state being an abnormal state in the second thread list as a target thread, obtaining a power saving strategy matched with the target thread, and processing the target thread by adopting the power saving strategy.)

1, power consumption detection method, applied to electronic equipment, comprising:

traversing CPU threads to obtain an th thread list, wherein the th thread list comprises the identification of each thread running in the electronic equipment at the th time and a th CPU time slice corresponding to the thread;

traversing the CPU thread again to obtain a second thread list, wherein the second thread list comprises the identification of each thread operated in the electronic equipment at a second time and a second CPU time slice corresponding to the identification;

determining the CPU time slice occupied by each thread in the second thread list from the th time to the second time according to the th thread list and the second thread list;

determining the power consumption state of each thread in the second thread list according to the CPU time slice occupied by each thread in the second thread list from the th time to the second time;

determining the thread with the power consumption state being an abnormal state in the second thread list as a target thread;

and acquiring a power saving strategy matched with the target thread, and processing the target thread by adopting the power saving strategy.

2. The method of claim 1 wherein the identification of the thread included in the th thread list is the same as the identification of the thread included in the second thread list;

determining the CPU time slice occupied by each thread in the second thread list from the th time to the second time according to the th thread list and the second thread list, including:

acquiring the difference value between the second CPU time slice and the CPU time slice of each thread in the second thread list according to the identification of each thread in the second thread list and the th thread list;

determining the difference as the CPU time slice occupied by each thread in the second thread list from the th time to the second time.

3. The method of claim 1 wherein the identities of the threads included in the th thread list are different from the identities of the threads included in the second thread list, wherein the identities of the th thread are included in the second thread list, wherein the identities of the th thread are not included in the th thread list;

determining the CPU time slice occupied by each thread in the second thread list from the th time to the second time according to the th thread list and the second thread list, including:

determining a second CPU time slice of the th thread in the second thread list as a CPU time slice occupied by the th thread from the th time to the second time.

4. The method of claim 1 wherein the identities of the threads included in the th thread list are different from the identities of the threads included in the second thread list, wherein the th thread is included in the second thread list, wherein the th thread is not included in the th thread list, wherein the second thread list and the th thread list each include an identity of a second thread;

determining the CPU time slice occupied by each thread in the second thread list from the th time to the second time according to the th thread list and the second thread list, including:

determining a second CPU time slice of the thread in the second thread list as a CPU time slice occupied by the thread from the time to the second time;

determining a difference value between a second CPU time slice and an CPU time slice of the second thread as a CPU time slice occupied by the second thread from the th time to the second time.

5. The method as claimed in any one of claims 1-4 and , wherein said determining the power consumption state of each thread in the second thread list based on the CPU time slice occupied by each thread in the second thread list from the th time to the second time comprises:

determining the power consumption occupied by each thread in the second thread list according to the CPU time slice occupied by each thread in the second thread list from the th time to the second time;

and determining the power consumption state of each thread in the second thread list according to the power consumption occupied by each thread in the second thread list.

6. The method as claimed in claim 5, wherein said determining the power consumption status of each thread in the second thread list according to the power consumption occupied by each thread in the second thread list comprises:

acquiring the calling times of calling the target function by the threads with the power consumption larger than a preset power threshold in the second thread list;

and determining the power consumption state corresponding to the thread with the calling frequency larger than a preset frequency threshold value in the second thread list as an abnormal power consumption state.

7. The method of any of claims 1-4, wherein obtaining a power saving policy that matches the target thread, and wherein processing the target thread using the power saving policy comprises:

acquiring the priority level of a target task currently executed by the target thread;

if the priority level is greater than a preset level, controlling the target thread to suspend calling a target function, wherein the target function is a function of which the calling times meet a calling time condition in the process of executing the target task by the target thread, or the target function is a function of which the calling time meets a calling time condition in the process of executing the target task by the target thread;

and if the grade is less than or equal to the preset grade, controlling the target thread to suspend executing the target task.

8, A power consumption detection device, comprising:

the traversing unit is used for traversing the CPU thread to obtain a th thread list, wherein the th thread list comprises the identification of each thread running in the electronic equipment at the th time and the corresponding th CPU time slice;

the determining unit is used for determining the CPU time slice occupied by each thread in the second thread list from the th time to the second time according to the th thread list and the second thread list, determining the power consumption state of each thread in the second thread list according to the CPU time slice occupied by each thread in the second thread list from the th time to the second time, and determining the thread with the power consumption state in the second thread list as an abnormal state as a target thread;

and the processing unit is used for acquiring a power saving strategy matched with the target thread and processing the target thread by adopting the power saving strategy.

An electronic device of type, comprising an input device and an output device, characterized by further comprising:

a processor adapted to implement or more instructions, and,

a computer storage medium storing one or more instructions, the or more instructions adapted to be loaded by the processor and to perform the method of any of claims 1-7 and .

10, computer storage media characterized in that the computer storage media stores computer program instructions that, when executed, implement the method of any of claims 1-7- .

Technical Field

The invention relates to the technical field of mobile communication, in particular to power consumption detection methods, power consumption detection devices, electronic equipment and storage media.

Background

With the continuous development of mobile communication technology, electronic devices (such as smart phones and tablet computers) are increasingly popularized, and more applications capable of running in the electronic devices are required, so that more threads need to be established to execute tasks (such as data processing tasks and data query tasks) corresponding to the applications, and further, the battery endurance time of the electronic devices is shorter and shorter.

Disclosure of Invention

An object of the embodiments of the present invention is to provide methods, apparatuses, electronic devices, and storage media for detecting power consumption, which can save power consumption of the electronic devices by processing a thread with abnormal power consumption.

, the embodiment of the invention provides methods for detecting power consumption, which comprises:

traversing CPU threads to obtain an th thread list, wherein the th thread list comprises the identification of each thread running in the electronic equipment at the th time and a th CPU time slice corresponding to the thread;

traversing the CPU thread again to obtain a second thread list, wherein the second thread list comprises the identification of each thread operated in the electronic equipment at a second time and a second CPU time slice corresponding to the identification;

determining the CPU time slice occupied by each thread in the second thread list from the th time to the second time according to the th thread list and the second thread list;

determining the power consumption state of each thread in the second thread list according to the CPU time slice occupied by each thread in the second thread list from the th time to the second time;

determining the thread with the power consumption state being an abnormal state in the second thread list as a target thread;

and acquiring a power saving strategy matched with the target thread, and processing the target thread by adopting the power saving strategy.

, an embodiment of the present invention provides types of power consumption detection apparatus, including:

the traversing unit is used for traversing the CPU thread to obtain a th thread list, wherein the th thread list comprises the identification of each thread running in the electronic equipment at the th time and the corresponding th CPU time slice;

the determining unit is used for determining the CPU time slice occupied by each thread in the second thread list from the th time to the second time according to the th thread list and the second thread list, determining the power consumption state of each thread in the second thread list according to the CPU time slice occupied by each thread in the second thread list from the th time to the second time, and determining the thread with the power consumption state in the second thread list as an abnormal state as a target thread;

and the processing unit is used for acquiring a power saving strategy matched with the target thread and processing the target thread by adopting the power saving strategy.

In another aspect of , an embodiment of the present invention provides kinds of electronic devices, including an input device and an output device, further including:

a processor adapted to implement or more instructions, and,

a computer storage medium storing one or more instructions, the one or more instructions adapted to be loaded by the processor and perform the steps of:

traversing CPU threads to obtain an th thread list, wherein the th thread list comprises the identification of each thread running in the electronic equipment at the th time and a th CPU time slice corresponding to the thread;

traversing the CPU thread again to obtain a second thread list, wherein the second thread list comprises the identification of each thread operated in the electronic equipment at a second time and a second CPU time slice corresponding to the identification;

determining the CPU time slice occupied by each thread in the second thread list from the th time to the second time according to the th thread list and the second thread list;

determining the power consumption state of each thread in the second thread list according to the CPU time slice occupied by each thread in the second thread list from the th time to the second time;

determining the thread with the power consumption state being an abnormal state in the second thread list as a target thread;

and acquiring a power saving strategy matched with the target thread, and processing the target thread by adopting the power saving strategy.

In yet another aspect, embodiments of the invention provide computer storage media, the computer storage media storing or more instructions, the or more instructions adapted to be loaded by a processor and perform the steps of:

traversing CPU threads to obtain an th thread list, wherein the th thread list comprises the identification of each thread running in the electronic equipment at the th time and a th CPU time slice corresponding to the thread;

traversing the CPU thread again to obtain a second thread list, wherein the second thread list comprises the identification of each thread operated in the electronic equipment at a second time and a second CPU time slice corresponding to the identification;

determining the CPU time slice occupied by each thread in the second thread list from the th time to the second time according to the th thread list and the second thread list;

determining the power consumption state of each thread in the second thread list according to the CPU time slice occupied by each thread in the second thread list from the th time to the second time;

determining the thread with the power consumption state being an abnormal state in the second thread list as a target thread;

and acquiring a power saving strategy matched with the target thread, and processing the target thread by adopting the power saving strategy.

In the embodiment of the invention, whether the thread is in an abnormal power consumption state or not can be quickly determined by determining the power consumption state of the corresponding thread according to the CPU time slice occupied by each thread from the th time to the second time in the second thread list, and step is carried out.

Drawings

In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only embodiments of the present invention, and other drawings can be obtained by those skilled in the art without creative efforts.

Fig. 1 is a schematic flow chart of methods for detecting power consumption according to an embodiment of the present invention;

FIG. 2 is a diagram illustrating an thread list according to an embodiment of the present invention;

FIG. 3 is a schematic diagram of another thread list provided by an embodiment of the present invention;

FIG. 4 is a diagram of another types of thread lists provided by an embodiment of the invention;

fig. 5 is a schematic flow chart of another power consumption detection methods according to an embodiment of the present invention;

fig. 6 is a schematic structural diagram of power consumption detection devices according to an embodiment of the present invention;

fig. 7 is a schematic structural diagram of electronic devices according to an embodiment of the present invention.

Detailed Description

The technical solutions in the embodiments of the present invention will be described clearly and completely with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only partial embodiments of of the present invention, rather than all embodiments.

The electronic equipment can be provided with and run a plurality of application programs, such as a social application program, a taxi taking application program, a shopping application program, a takeout application program and the like, wherein in the running process of the application programs, at least two threads need to be established to execute tasks corresponding to the application programs, are UI threads or are called main threads, and are background threads, wherein the background threads are responsible for data interaction when the whole application programs run on a system of the electronic equipment, the UI threads are automatically created by the system when the application programs run, and are mainly responsible for realizing display, update, control interaction and the like of UI interfaces corresponding to the application programs according to task requests submitted by users, and the users can issue task requests to the UI threads through menus, links and the like provided by the UI interfaces.

S101, traversing the CPU threads to obtain an th thread list, wherein the th thread list comprises the identification of each thread running in the electronic equipment at the th time and the corresponding th CPU time slice.

And S102, traversing the CPU thread again to obtain a second thread list, wherein the second thread list comprises the identification of each thread operated in the electronic equipment at a second time and a second CPU time slice corresponding to the identification.

In steps S101 and S102, the electronic device may periodically traverse the CPU threads to obtain a thread list that the electronic device runs at each time point, that is, the electronic device may traverse the CPU threads to obtain a thread list, where the thread list includes an identification of each thread running in the electronic device at th time and its corresponding th CPU time slice, traverse the CPU threads again to obtain a second thread list, where the second thread list includes an identification of each thread running in the electronic device at second time and its corresponding second CPU time slice, the identification of the thread in the th thread list and the identification of the thread in the second thread list may be identical, completely different, or partially identical, a time interval between the th time and the second time refers to a period of traversing the CPU threads, which may be manually set by a user, which may refer to a default value in the electronic device, where the CPU time slice refers to a CPU time that an operating system of each running process is assigned to, that the thread is allowed to occupy, which may include a monitoring application time, and the current thread information may include a current thread ID/thread information, such as a program ID/program ID.

S103, determining the CPU time slice occupied by each thread in the second thread list from the th time to the second time according to the th thread list and the second thread list.

If a thread is in the thread list but the thread is not in the second thread list, indicating that the thread has been turned off before the time reaches the second time, the electronic device only needs to determine the CPU time slice occupied by each thread in the second thread list.

In embodiments, the identifier of the thread included in the thread list is the same as the identifier of the thread included in the second thread list, that is, the identifier of the thread included in the thread list is completely the same as the identifier of the thread included in the second thread list, step S103 includes obtaining a difference value between the second CPU time slice and the CPU time slice of each thread in the second thread list according to the identifiers of the threads in the second thread list and the thread list, and determining the difference value as the CPU time slice occupied by each thread in the second thread list from the th time to the second time.

The electronic device compares the identifier of the thread in the second thread list with the identifier of each thread in the th thread list, and if the identifier of the thread in the th thread list is identical to the identifier of the thread in the second thread list, the electronic device may obtain a difference between a second CPU time slice and a th CPU time slice of each thread in the second thread list according to the identifiers of the threads in the second thread list and the th thread list, and determine the difference as a CPU time slice occupied by each thread in the second thread list from the th time to the second time.

In another embodiments, the identification of the thread included in the thread list is different from the identification of the thread included in the second thread list, i.e., the identification of the thread included in the 0 th thread list is completely different from the identification of the thread included in the second thread list, the identification of the th thread is included in the second thread list, the identification of the th thread is not included in the th thread list, where the th thread may be any thread in the second thread list, and step S103 includes determining the second CPU time slice of the th thread in the second thread list as the CPU time slice occupied by the th thread from the th time to the second time.

In yet another embodiments, when the identification of the thread included in the second thread list is different from the identification of the thread included in the second thread list, that is, the identification of the thread included in the -th thread list is partially different from the identification of the thread included in the second thread list, for example, the second thread list includes the identification of the -th thread, the -th thread list does not include the identification of the -th thread, when the -th thread is any thread included in the second thread list but not included in the -th thread list, the identification of the second thread is included in the second thread -th thread list, when the second thread may be any thread included in both the -th thread list and the second thread list, step S103 includes determining the second CPU time slice of the second thread 36 in the second thread list as the difference between the CPU time of the second thread from the second to the second time slice and determining the CPU time taken between the second thread time slice and the second CPU time taken up by the second thread.

For example, as shown in fig. 2, the thread list 11 of the second thread includes the identifiers of the thread 1, the thread 3, and the thread 10, the time slice of the thread 1, the thread 3, and the thread 10 occupied at the th time is 110ms, 50ms, and 0 ms. thread is 0, which indicates that the thread is not currently executing a task, the thread list includes a second thread set 12 including the thread 1, the thread 3, the thread 4, and the thread 10, the thread 1, the thread 3, the thread 4, and the thread 10 occupy the second time in 11110ms, 250ms, 1022ms, and 111 ms., since the thread 1, the thread 3, and the thread 10 are included in the thread list of the second th thread and the thread list of the second thread list, the thread list of the CPU 1, the thread th thread time slice of the CPU 1, which is occupied by the second thread time slice of the thread 1, and the thread 1 is a second CPU time slice of the thread 464, which is a longest time, which is from the thread 21 st thread 26 th thread, to the thread 3, the thread 7, the thread list of the thread 12, which is a longest thread, the thread 12, the thread list of the thread 12, which is a thread 12, the thread which is a thread 12, which is a thread 12, a thread which is a thread 12 th thread which is a thread 12, a thread which is a thread 12 th thread which is a thread which is.

And S104, determining the power consumption state of each thread in the second thread list according to the CPU time slice occupied by each thread in the second thread list from the th time to the second time.

S105, determining the thread with the abnormal power consumption state in the second thread list as a target thread.

In steps S104 to S105, the electronic device may determine the power consumption state of each thread in the second thread list according to the CPU time slice occupied by each thread in the second thread list from the th time to the second time, i.e., determine the power consumption of each thread in the second thread list according to the CPU time slice occupied by each thread in the second thread list from the th time to the second time, where the power consumption of a thread is proportional to the CPU time slice occupied by the thread from the th time to the second time, i.e., the longer the CPU time slice occupied by a thread from the th time to the second time, the more the power consumption of the thread is consumed, and conversely, the shorter the CPU time slice occupied by a thread from the th time to the second time, the less the power consumption of the thread is consumed, then advance , determine the power consumption state of each thread according to the power consumption of each thread in the second thread list, where the power consumption state includes an abnormal state and a normal state, where the power consumption state is a sudden increase, and the power consumption rate of the thread is determined as a target task.

In embodiments, step S104 includes steps S11-S12 as follows.

s11, determining the power consumption of each thread in the second thread list according to the CPU time slice occupied by each thread in the second thread list from the th time to the second time.

s12, determining the power consumption state of each thread in the second thread list according to the power consumption occupied by each thread in the second thread list.

In embodiments, the step s12 may include obtaining a number of calls of the thread to call the target function if the power consumed by any thread in the second thread list is greater than a preset power threshold, and determining that the power consumption state of the thread is an abnormal power consumption state if the number of calls is greater than the preset number threshold.

If the electricity consumed by any thread in the second thread list is greater than the preset electricity threshold, the electricity consumed by the thread is more, therefore, the electronic device can obtain log data generated in the process of executing the task by the thread, the log data comprises functions called in the process of executing the task by the thread and the calling times of calling each function, the calling times of calling the target function by the thread are obtained from the log data, the target function can be any function in the functions called in the process of executing the task by the thread, if the calling times are less than or equal to the preset times threshold, the thread is determined to be in a normal electricity consumption state, and if the calling times are greater than the preset times threshold, the thread is determined to be in an abnormal state of repeatedly calling the target function, the thread is determined to be in an abnormal electricity consumption state.

In another embodiments, step s12 may include obtaining a sum of power consumed by all threads in the second thread list, calculating a ratio between the power consumed by any threads in the second thread list and the sum of power, and if the ratio is greater than a predetermined ratio, determining that the power consumption status of the thread is an abnormal power consumption status.

Therefore, the electronic device can obtain the sum of the electric quantity consumed by all threads in a second thread list, calculate the ratio between the electric quantity consumed by any thread in the second thread list and the sum of the electric quantity, if the ratio is smaller than or equal to a preset ratio, the difference between the electric quantity consumed by the thread and the electric quantity consumed by other threads in the second thread list is smaller, determine that the electric consumption state of the thread is a normal electric consumption state, and if the ratio is larger than the preset ratio, the difference between the electric quantity consumed by the thread and the electric quantity consumed by other threads in the second thread list is larger, determine that the electric consumption state of the thread is an abnormal electric consumption state.

In still another embodiments, step s12 may include obtaining a running duration of any thread in the second thread list, determining a power consumption change rate of the thread according to the running duration of the thread and the consumed power, and determining the power consumption state of the thread to be an abnormal power consumption state if the power consumption change rate is greater than a preset change rate threshold.

The electronic equipment can acquire the time when any threads in the second thread list are established and the current time, and determines the running time of the thread according to the established time and the current time of the thread.

And S106, acquiring a power saving strategy matched with the target thread, and processing the target thread by adopting the power saving strategy.

If the power consumption state of the target thread is a normal state, indicating that the power consumption of the target thread is low, ending the process; if the power consumption state of the target thread is an abnormal power consumption state, which indicates that the power consumption of the target thread is too high, a power saving strategy matched with the target thread can be obtained, and the target thread is processed by adopting the power saving strategy. Therefore, the problem that the other threads cannot normally run due to overhigh consumed electric quantity of the target thread can be avoided, and the electric quantity can be saved.

In embodiments, if the power consumption status of the target thread is an abnormal power consumption status, the electronic device may output a prompt for prompting a user to select a power saving policy.

In the embodiment of the invention, whether the thread is in an abnormal power consumption state or not can be quickly determined by determining the power consumption state of the corresponding thread according to the CPU time slice occupied by each thread from the th time to the second time in the second thread list, and step is carried out.

Based on the above description, another power consumption detection methods are provided in the embodiments of the present invention, which can be executed by the electronic device described above, and please refer to fig. 5, the power consumption detection methods include S201-S206.

S201, traversing the CPU threads to obtain an th thread list, wherein the th thread list comprises the identification of each thread running in the electronic equipment at the th time and the corresponding th CPU time slice.

S202, traversing the CPU thread again to obtain a second thread list, wherein the second thread list comprises the identification of each thread operated in the electronic equipment at a second time and a second CPU time slice corresponding to the identification.

S203, determining the CPU time slice occupied by each thread in the second thread list from the th time to the second time according to the th thread list and the second thread list.

S204, determining the power consumption state of each thread in the second thread list according to the CPU time slice occupied by each thread in the second thread list from the th time to the second time.

S205, the thread whose power consumption state is in the abnormal state in the second thread list is determined as the target thread.

It should be noted that, in the embodiment of the present invention, for the explanation of steps S201 to S205, reference may be made to the explanation of steps S101 to S105 in fig. 1, and repetition is not repeated and is not repeated.

S206, acquiring the priority level of the target task currently executed by the target thread.

For example, if the type of the target task is a service type with stronger real-time performance, such as a web page loading type task, higher priorities may be set for the target task, if the type of the target task is a service type with lower real-time performance, such as a data query type task, lower priorities may be set for the target task, or if the frequency of the target task history being executed is higher, it indicates that the target task is a hot task, i.e., the importance of the target task is higher, higher priorities may be set for the target task, if the frequency of the target task history being executed is lower, it indicates that the target task is not a hot task, i.e., the importance of the target task is lower, higher priorities may be set for the target task.

S207, if the priority level is higher than a preset level, controlling the target thread to suspend calling a target function, wherein the target function is a function of which the calling times meet the calling time condition in the process of executing the target task by the target thread, or the target function is a function of which the calling time meets the calling time condition in the process of executing the target task by the target thread.

If the priority level is higher than the preset level, which indicates that the real-time performance and the importance of the target task are higher, part of functions of the target thread can be suspended, namely, the target thread is controlled to suspend calling the target function. The target function is a function of which the calling times meet the calling time condition in the process of executing the target task by the target thread, namely the target function is a function repeatedly called by the target thread in the process of executing the target task, namely the target function is a function of which the calling times are larger than a preset calling time threshold value in the process of executing the target task by the target thread. Or, the target function is a function whose calling time meets the calling time condition in the process of executing the target task by the target thread, and the electric quantity consumed by the target thread in the process of calling the target function is in direct proportion to the calling time of the target function, that is, the target function is a function whose electric consumption is the most in the process of executing the target task by the target thread, for example, the target function is a function whose calling time is greater than a preset time threshold in the process of executing the target task by the target thread.

S208, if the level is less than or equal to the preset level, controlling the target thread to suspend executing the target task.

If the priority level is less than or equal to the preset level, which indicates that the real-time performance of the target task is weaker and the importance of the target task is lower, all functions of the target thread can be suspended, that is, the target thread is controlled to suspend executing the target task.

In the embodiment of the invention, whether the thread is in an abnormal power consumption state or not can be quickly determined by determining the power consumption state of the corresponding thread according to the CPU time slice occupied by each thread from the th time to the second time in the second thread list, and step is carried out.

An embodiment of the present invention provides types of power consumption detecting devices, which can be disposed in an electronic device, as shown in fig. 6, and the device includes:

the traversing unit 501 is configured to traverse the CPU threads to obtain an th thread list, where the th thread list includes the identifier of each thread running in the electronic device at the th time and the corresponding th CPU time slice, and traverse the CPU threads again to obtain a second thread list, where the second thread list includes the identifier of each thread running in the electronic device at the second time and the corresponding second CPU time slice.

The determining unit 502 is configured to determine, according to the th thread list and the second thread list, a CPU time slice occupied by each thread in the second thread list from the th time to the second time, determine, according to the CPU time slice occupied by each thread in the second thread list from the th time to the second time, a power consumption state of each thread in the second thread list, and determine, as a target thread, a thread in the second thread list whose power consumption state is an abnormal state.

The processing unit 503 is configured to acquire a power saving policy matched with the target thread, and process the target thread by using the power saving policy.

Optionally, the determining unit 502 is specifically configured to obtain a difference between a second CPU time slice and a th CPU time slice of each thread in the second thread list according to the identifier of each thread in the second thread list and the th thread list, and determine the difference as the CPU time slice occupied by each thread in the second thread list from the th time to the second time.

Optionally, the determining unit 502 is specifically configured to determine the second CPU time slice of the th thread in the second thread list as the CPU time slice occupied by the th thread from the th time to the second time.

Optionally, the determining unit 502 is specifically configured to determine the second CPU time slice of the th thread in the second thread list as the CPU time slice occupied by the th thread from the th time to the second time, and determine the difference between the second CPU time slice of the second thread and the th CPU time slice as the CPU time slice occupied by the second thread from the th time to the second time.

Optionally, the determining unit 502 is specifically configured to determine power consumption occupied by each thread in the second thread list according to the CPU time slice occupied by each thread in the second thread list from the th time to the second time, and determine the power consumption state of each thread in the second thread list according to the power consumption occupied by each thread in the second thread list.

Optionally, the determining unit 502 is configured to obtain the number of times for calling the target function by the thread with the power consumption greater than the preset power threshold in the second thread list; and determining the power consumption state corresponding to the thread with the calling frequency larger than a preset frequency threshold value in the second thread list as an abnormal power consumption state.

A unit 503, specifically configured to obtain a priority level of a target task currently executed by the target thread; if the priority level is greater than a preset level, controlling the target thread to suspend calling a target function, wherein the target function is a function of which the calling times meet a calling time condition in the process of executing the target task by the target thread, or the target function is a function of which the calling time meets a calling time condition in the process of executing the target task by the target thread; and if the grade is less than or equal to the preset grade, controlling the target thread to suspend executing the target task.

Optionally, the priority level of the target task is determined according to the type of the target task, and/or the priority level of the target task is determined according to the frequency of the target task history being executed.

In the embodiment of the invention, whether the thread is in an abnormal power consumption state or not can be quickly determined by determining the power consumption state of the corresponding thread according to the CPU time slice occupied by each thread from the th time to the second time in the second thread list, and step is carried out.

An embodiment of the present invention provides electronic devices, please refer to fig. 7, which includes a processor 151, a user interface 152, a network interface 154 and a storage device 155, wherein the processor 151, the user interface 152, the network interface 154 and the storage device 155 are connected via a bus 153.

The storage 155 may include a high speed random access memory and may also include a non-volatile memory such as or more disk storage devices, flash memory devices, or other non-volatile solid state storage devices, the storage 155 may store an operating system (hereinafter referred to as a system) such as ANDROID, IOS, WINDOWS, or LINUX embedded operating systems, the storage 155 may also store a network communication program that may be used to communicate with or more additional devices, or more application servers, or more network devices, the storage 155 may also store a user interface program that may display the content of the application in a realistic manner via a graphical operating interface and receive user control data such as user dialog controls via menus, buttons, input menus, and buttons, etc. the storage 155 may also store video data.

In embodiments, the storage device 155 may be configured to store or more instructions, and the processor 151 may be configured to implement the power consumption detection method when invoking the or more instructions, specifically, the processor 151 invokes the or more instructions to perform the following steps:

traversing CPU threads to obtain an th thread list, wherein the th thread list comprises the identification of each thread running in the electronic equipment at the th time and a th CPU time slice corresponding to the thread;

traversing the CPU thread again to obtain a second thread list, wherein the second thread list comprises the identification of each thread operated in the electronic equipment at a second time and a second CPU time slice corresponding to the identification;

determining the CPU time slice occupied by each thread in the second thread list from the th time to the second time according to the th thread list and the second thread list;

determining the power consumption state of each thread in the second thread list according to the CPU time slice occupied by each thread in the second thread list from the th time to the second time;

determining the thread with the power consumption state being an abnormal state in the second thread list as a target thread;

and acquiring a power saving strategy matched with the target thread, and processing the target thread by adopting the power saving strategy.

Optionally, the processor calls an instruction to perform the following steps:

acquiring the difference value between the second CPU time slice and the CPU time slice of each thread in the second thread list according to the identification of each thread in the second thread list and the th thread list;

determining the difference as the CPU time slice occupied by each thread in the second thread list from the th time to the second time.

Optionally, the processor calls an instruction to perform the following steps:

determining a second CPU time slice of the th thread in the second thread list as a CPU time slice occupied by the th thread from the th time to the second time.

Optionally, the processor calls an instruction to perform the following steps:

determining the CPU time slice occupied by each thread in the second thread list from the th time to the second time according to the th thread list and the second thread list, including:

determining a second CPU time slice of the thread in the second thread list as a CPU time slice occupied by the thread from the time to the second time;

determining a difference value between a second CPU time slice and an CPU time slice of the second thread as a CPU time slice occupied by the second thread from the th time to the second time.

Optionally, the processor calls an instruction to perform the following steps:

determining the power consumption occupied by each thread in the second thread list according to the CPU time slice occupied by each thread in the second thread list from the th time to the second time;

and determining the power consumption state of each thread in the second thread list according to the power consumption occupied by each thread in the second thread list.

Optionally, the processor calls an instruction to perform the following steps:

acquiring the calling times of calling the target function by the threads with the power consumption larger than a preset power threshold in the second thread list;

and determining the power consumption state corresponding to the thread with the calling frequency larger than a preset frequency threshold value in the second thread list as an abnormal power consumption state.

Optionally, the processor calls an instruction to perform the following steps:

acquiring the priority level of a target task currently executed by the target thread;

if the priority level is greater than a preset level, controlling the target thread to suspend calling a target function, wherein the target function is a function of which the calling times meet a calling time condition in the process of executing the target task by the target thread, or the target function is a function of which the calling time meets a calling time condition in the process of executing the target task by the target thread;

and if the grade is less than or equal to the preset grade, controlling the target thread to suspend executing the target task.

In the embodiment of the invention, whether the thread is in an abnormal power consumption state or not can be quickly determined by determining the power consumption state of the corresponding thread according to the CPU time slice occupied by each thread from the th time to the second time in the second thread list, and step is carried out.

The embodiment of the present invention further provides computer-readable storage media, on which a computer program is stored, and for implementation and beneficial effects of the program for solving the problems, reference may be made to the implementation and beneficial effects of the power consumption detection method described in fig. 1, and repeated details are not repeated.

The above disclosure is intended to be illustrative of only some embodiments of the invention, and is not intended to limit the scope of the invention.

19页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种低功耗显示背景图像的图像显示装置及其方法

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!