CN114860534A - Electronic device and method for obtaining power consumption of processor thereof, and computer-readable storage medium - Google Patents
Electronic device and method for obtaining power consumption of processor thereof, and computer-readable storage medium Download PDFInfo
- Publication number
- CN114860534A CN114860534A CN202110150043.8A CN202110150043A CN114860534A CN 114860534 A CN114860534 A CN 114860534A CN 202110150043 A CN202110150043 A CN 202110150043A CN 114860534 A CN114860534 A CN 114860534A
- Authority
- CN
- China
- Prior art keywords
- processor
- target
- power consumption
- time period
- frequency
- 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
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/3058—Monitoring arrangements for monitoring environmental properties or parameters of the computing system or of the computing system component, e.g. monitoring of power, currents, temperature, humidity, position, vibrations
- G06F11/3062—Monitoring arrangements for monitoring environmental properties or parameters of the computing system or of the computing system component, e.g. monitoring of power, currents, temperature, humidity, position, vibrations where the monitored property is the power consumption
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F1/00—Details not covered by groups G06F3/00 - G06F13/00 and G06F21/00
- G06F1/26—Power supply means, e.g. regulation thereof
- G06F1/32—Means for saving power
- G06F1/3203—Power management, i.e. event-based initiation of a power-saving mode
- G06F1/3206—Monitoring of events, devices or parameters that trigger a change in power modality
-
- Y—GENERAL 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
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE 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/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computing Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Quality & Reliability (AREA)
- Debugging And Monitoring (AREA)
Abstract
本发明公开了一种处理器功耗获取方法,该方法包括:获取目标时间段和目标运行频率;所述目标时间段为处理器调用目标线程执行任务的时间段,所述目标运行频率为所述目标时间段内所述处理器的运行频率;根据所述目标时间段和所述目标运行频率确定所述处理器的功耗参数。本发明还公开了一种电子设备和计算机可读存储介质。本发明旨在提高处理器的功耗获取结果的准确性,以为设备续航性能优化提供准确依据。
The invention discloses a method for obtaining power consumption of a processor. The method includes: obtaining a target time period and a target operating frequency; the target time period is a time period when a processor calls a target thread to execute a task, and the target operating frequency is all The operating frequency of the processor in the target time period; the power consumption parameter of the processor is determined according to the target time period and the target operating frequency. The invention also discloses an electronic device and a computer-readable storage medium. The invention aims to improve the accuracy of the power consumption acquisition result of the processor, so as to provide an accurate basis for optimizing the battery life performance of the device.
Description
技术领域technical field
本发明涉及电子设备技术领域,尤其涉及处理器功耗获取方法、电子设备和计算机可读存储介质。The present invention relates to the technical field of electronic devices, and in particular, to a method for obtaining power consumption of a processor, an electronic device, and a computer-readable storage medium.
背景技术Background technique
随着经济技术的发展,电子设备的应用越来越广泛,电子设备的性能也越来越优化。目前,大多电子设备均搭载了处理器以适应于多样化的性能需求,其中,处理器的功耗情况分析成为电子设备续航性能优化中亟待解决的问题。With the development of economy and technology, the application of electronic equipment is more and more extensive, and the performance of electronic equipment is more and more optimized. At present, most electronic devices are equipped with processors to meet diverse performance requirements. Among them, the analysis of the power consumption of the processors has become an urgent problem to be solved in the optimization of the battery life performance of the electronic devices.
目前,一般通过检测电子设备在执行不同用户操作时耗电数据来得到处理器的功耗参数,然而这样的方式得到的处理器的功耗参数容易受到其他耗电器件的能耗影响,未能反映处理器实际数据处理过程中资源消耗情况,由此可见,当前获取的处理器功耗结果存在准确性不足,无法为设备续航性能优化提供准确依据。At present, the power consumption parameters of the processor are generally obtained by detecting the power consumption data of electronic devices when performing different user operations. However, the power consumption parameters of the processor obtained in this way are easily affected by the power consumption of other power-consuming devices, and cannot It reflects the resource consumption in the actual data processing process of the processor. It can be seen that the accuracy of the currently obtained processor power consumption results is insufficient, and cannot provide an accurate basis for optimizing the battery life performance of the device.
发明内容SUMMARY OF THE INVENTION
本发明的主要目的在于提供一种处理器功耗获取方法、电子设备和计算机可读存储介质,旨在提高处理器的功耗获取结果的准确性,以为设备续航性能优化提供准确依据。The main purpose of the present invention is to provide a processor power consumption acquisition method, an electronic device and a computer-readable storage medium, which aim to improve the accuracy of the processor power consumption acquisition result and provide an accurate basis for the optimization of device endurance performance.
为实现上述目的,本发明提供一种处理器功耗获取方法,所述处理器功耗获取方法包括以下步骤:In order to achieve the above object, the present invention provides a method for obtaining power consumption of a processor, and the method for obtaining power consumption of a processor includes the following steps:
获取目标时间段和目标运行频率;所述目标时间段为处理器调用目标线程执行任务的时间段,所述目标运行频率为所述目标时间段内所述处理器的运行频率;Obtain a target time period and a target operating frequency; the target time period is the time period during which the processor invokes the target thread to perform a task, and the target operating frequency is the operating frequency of the processor within the target time period;
根据所述目标时间段和所述目标运行频率确定所述处理器的功耗参数。The power consumption parameter of the processor is determined according to the target time period and the target operating frequency.
可选地,所述目标运行频率包括至少两个不同的子频率,所述根据所述目标时间段和所述目标运行频率确定所述处理器的功耗参数的步骤包括:Optionally, the target operating frequency includes at least two different sub-frequency, and the step of determining the power consumption parameter of the processor according to the target time period and the target operating frequency includes:
确定所述目标时间段内每个所述子频率对应运行的子时间段;determining a sub-time period corresponding to the operation of each of the sub-frequency within the target time period;
根据每个所述子时间段及其对应的子频率确定所述功耗参数。The power consumption parameter is determined according to each of the sub-time periods and its corresponding sub-frequency.
可选地,所述目标线程的数量有多个,所述根据所述目标时间段和所述目标运行频率确定所述处理器的功耗参数的步骤包括:Optionally, there are multiple target threads, and the step of determining the power consumption parameter of the processor according to the target time period and the target operating frequency includes:
根据每个所述目标线程对应的目标时间段和目标运行频率确定所述处理器调用每个所述目标线程时的子功耗参数;Determine the sub-power consumption parameter when the processor calls each of the target threads according to the target time period and target operating frequency corresponding to each of the target threads;
确定多个所述目标线程中目标进程对应的所有子线程;Determine all sub-threads corresponding to the target process in the plurality of target threads;
根据所述目标进程对应的所有子线程的子功耗参数确定所述处理器执行所述目标进程时的总功耗参数;Determine the total power consumption parameter when the processor executes the target process according to the sub-power consumption parameters of all sub-threads corresponding to the target process;
确定总功耗参数为所述处理器的功耗参数。The total power consumption parameter is determined as the power consumption parameter of the processor.
可选地,所述获取目标时间段和目标运行频率的步骤包括:Optionally, the step of obtaining the target time period and the target operating frequency includes:
获取所述处理器对应的线程调度日志、处理器状态日志和处理器频率日志;Obtain the thread scheduling log, the processor status log and the processor frequency log corresponding to the processor;
根据所述处理器状态日志确定所述处理器的运行时间段;determining the running time period of the processor according to the processor state log;
根据所述线程调度日志在所述运行时间段内确定所述目标线程对应的目标时间段;Determine the target time period corresponding to the target thread within the running time period according to the thread scheduling log;
提取所述处理器频率日志中所述目标时间段对应的频率作为所述目标运行频率。The frequency corresponding to the target time period in the processor frequency log is extracted as the target operating frequency.
可选地,所述根据所述处理器状态日志确定所述处理器的运行时间段的步骤包括:Optionally, the step of determining the running time period of the processor according to the processor state log includes:
当所述处理器状态日志包含设定状态标识时,根据所述处理器状态日志的第一时间戳确定所述运行时间段;When the processor state log contains a set state identifier, determining the running time period according to the first timestamp of the processor state log;
其中,所述第一时间戳为电子设备从开机到所述处理器状态日志生成时的运行时长,所述设定状态标识为所述处理器处于运行状态时的标识。Wherein, the first time stamp is the running duration of the electronic device from power-on to when the processor state log is generated, and the set state identifier is an identifier when the processor is in a running state.
可选地,所述线程调度日志包括若干条调度数据,所述调度数据包括所述处理器所调度的线程的标识信息、线程的任务状态信息及其对应的第二时间戳,所述根据所述线程调度日志在所述运行时间段内确定所述目标线程对应的目标时间段的步骤包括:Optionally, the thread scheduling log includes several pieces of scheduling data, and the scheduling data includes the identification information of the thread scheduled by the processor, the task status information of the thread, and the corresponding second time stamp. The step of determining the target time period corresponding to the target thread in the running time period in the thread scheduling log includes:
确定所述线程调度日志中的目标调度数据;所述目标调度数据为第二时间戳位于所述运行时间段内、且所述标识信息为所述目标线程的标识的调度数据;Determine the target scheduling data in the thread scheduling log; the target scheduling data is the scheduling data whose second timestamp is within the running time period, and the identification information is the identification of the target thread;
将第一目标数据的第二时间戳确定为第一目标时间,将第二目标数据的第二时间戳确定为第二目标时间;所述第一目标数据为所述目标调度数据中任务状态信息为任务开始的调度数据,所述第二目标数据为所述目标调度数据中任务状态信息为任务结束的调度数据;The second time stamp of the first target data is determined as the first target time, and the second time stamp of the second target data is determined as the second target time; the first target data is the task status information in the target scheduling data is the scheduling data of the task start, and the second target data is the task status information in the target scheduling data that the task ends;
根据所述第一目标时间和所述第二目标时间确定所述目标时间段。The target time period is determined according to the first target time and the second target time.
可选地,所述处理器频率日志包括若干个频率数据,所述频率数据包括所述处理器运行的频率值及其对应的第三时间戳,所述提取所述处理器频率日志中所述目标时间段对应的频率作为所述目标运行频率的步骤包括:Optionally, the processor frequency log includes several pieces of frequency data, and the frequency data includes a frequency value of the processor running and its corresponding third timestamp, and the extracting the processor frequency log described in the The step of using the frequency corresponding to the target time period as the target operating frequency includes:
确定所述处理器频率日志中的目标频率数据;所述目标频率数据为第三时间戳位于所述目标时间段内的频率数据;determining target frequency data in the processor frequency log; the target frequency data is frequency data whose third timestamp is within the target time period;
提取所述频率数据中的频率值作为所述目标运行频率。The frequency value in the frequency data is extracted as the target operating frequency.
可选地,所述获取所述处理器对应的线程调度日志、处理器状态日志和处理器频率日志的步骤之前,还包括:Optionally, before the step of acquiring the thread scheduling log, the processor status log and the processor frequency log corresponding to the processor, the method further includes:
在电子设备处于设定模式时,根据所述处理器的状态信息和当前时间戳生成所述处理器状态日志;所述状态信息为所述处理器是否处于运行状态的信息;When the electronic device is in the setting mode, the processor state log is generated according to the state information of the processor and the current time stamp; the state information is the information of whether the processor is in a running state;
根据所述处理器所调度的线程的标识信息、线程的任务状态信息以及当前时间戳生成所述线程调度日志;generating the thread scheduling log according to the identification information of the thread scheduled by the processor, the task state information of the thread and the current timestamp;
根据所述电子设备的处理器运行的频率值和当前时间戳生成所述处理器频率日志;generating the processor frequency log according to the frequency value of the running frequency of the processor of the electronic device and the current timestamp;
其中,所述设定模式为对所述处理器功耗进行监控的模式,所述时间戳从所述电子设备开机时开始计时。The setting mode is a mode for monitoring the power consumption of the processor, and the time stamp starts timing when the electronic device is powered on.
可选地,所述获取所述处理器对应的线程调度日志、处理器状态日志和处理器频率日志的步骤之前,还包括:Optionally, before the step of acquiring the thread scheduling log, the processor status log and the processor frequency log corresponding to the processor, the method further includes:
以循环链表形式保存所述线程调度日志、处理器状态日志和处理器频率日志。The thread scheduling log, the processor status log and the processor frequency log are saved in the form of a circular linked list.
可选地,所述获取目标时间段和目标运行频率的步骤之前,还包括:Optionally, before the step of acquiring the target time period and the target operating frequency, further comprising:
监测所述电子设备的耗电速率;monitoring the rate of power consumption of the electronic device;
当所述耗电速率大于或等于设定速率阈值时,执行所述获取目标时间段和目标运行频率的步骤。When the power consumption rate is greater than or equal to a set rate threshold, the step of acquiring a target time period and a target operating frequency is performed.
此外,为了实现上述目的,本申请还提出一种电子设备,所述电子设备包括:In addition, in order to achieve the above purpose, the present application also proposes an electronic device, the electronic device comprising:
第一处理器;the first processor;
功耗监控模块,所述功耗监控模块与所述第一处理器连接,所述功耗监控模块包括:存储器、第二处理器及存储在所述存储器上并可在所述第二处理器上运行的计算机程序,所述计算机程序被所述第二处理器执行时实现如上任一项所述的处理器功耗获取方法的步骤。a power consumption monitoring module, the power consumption monitoring module is connected to the first processor, and the power consumption monitoring module includes: a memory, a second processor, and a power consumption monitoring module stored on the memory and available on the second processor A computer program running on the computer program, when the computer program is executed by the second processor, implements the steps of the method for obtaining power consumption of a processor according to any one of the above.
此外,为了实现上述目的,本申请还提出一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现如上任一项所述的处理器功耗获取方法的步骤。In addition, in order to achieve the above purpose, the present application also proposes a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the processing described in any one of the preceding items is implemented. The steps of the method for obtaining the power consumption of the device.
本发明提出的一种处理器功耗获取方法,该方法结合处理器调用目标线程执行任务的目标时间段和该目标时间段内处理器的运行频率来确定处理器的功耗参数,由于目标时间段和目标运行频率均为处理器调用目标线程执行任务时的相关运行参数,因此所得到的功耗参数可准确反映处理器调用线程执行任务过程中的能耗情况,不受其他耗电器件的能耗影响,有效提高处理器的功耗获取结果的准确性,保证处理器的功耗获取结果可为设备续航性能优化提供准确依据,实现电子设备续航能力的有效提高。The present invention provides a method for obtaining power consumption of a processor, which determines the power consumption parameter of the processor by combining the target time period during which the processor calls the target thread to execute the task and the operating frequency of the processor in the target time period. The segment and target operating frequency are the relevant operating parameters when the processor calls the target thread to execute the task, so the obtained power consumption parameter can accurately reflect the energy consumption in the process of the processor calling the thread to execute the task, and is not affected by other power-consuming devices. The influence of energy consumption can effectively improve the accuracy of the power consumption acquisition result of the processor, and ensure that the power consumption acquisition result of the processor can provide an accurate basis for the optimization of the battery life performance of the device, so as to effectively improve the battery life of the electronic device.
附图说明Description of drawings
图1为本发明电子设备一实施例运行涉及的硬件结构示意图;1 is a schematic diagram of a hardware structure involved in the operation of an embodiment of an electronic device of the present invention;
图2为本发明处理器功耗获取方法一实施例的流程示意图;FIG. 2 is a schematic flowchart of an embodiment of a method for obtaining power consumption of a processor according to the present invention;
图3为本发明处理器功耗获取方法另一实施例的流程示意图;3 is a schematic flowchart of another embodiment of a method for obtaining power consumption of a processor according to the present invention;
图4为电子设备开机后处理器执行任务时相关参数的时序图;4 is a sequence diagram of relevant parameters when the processor performs a task after the electronic device is turned on;
图5为本发明处理器功耗获取方法又一实施例的流程示意图;FIG. 5 is a schematic flowchart of another embodiment of a method for obtaining power consumption of a processor according to the present invention;
图6为本发明处理器功耗获取方法再一实施例的流程示意图。FIG. 6 is a schematic flowchart of still another embodiment of a method for obtaining power consumption of a processor according to the present invention.
本发明目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。The realization, functional characteristics and advantages of the present invention will be further described with reference to the accompanying drawings in conjunction with the embodiments.
具体实施方式Detailed ways
应当理解,此处所描述的具体实施例仅仅用以解释本发明,并不用于限定本发明。It should be understood that the specific embodiments described herein are only used to explain the present invention, but not to limit the present invention.
本发明实施例的主要解决方案是:获取目标时间段和目标运行频率;所述目标时间段为处理器调用目标线程执行任务的时间段,所述目标运行频率为所述目标时间段内所述处理器的运行频率;根据所述目标时间段和所述目标运行频率确定所述处理器的功耗参数。The main solution of the embodiment of the present invention is to obtain a target time period and a target operating frequency; the target time period is the time period during which the processor calls the target thread to perform a task, and the target operating frequency is the The operating frequency of the processor; the power consumption parameter of the processor is determined according to the target time period and the target operating frequency.
由于现有技术中,一般通过检测电子设备在执行不同用户操作时耗电数据来得到处理器的功耗参数,然而这样的方式得到的处理器的功耗参数容易受到其他耗电器件的能耗影响,未能反映处理器实际数据处理过程中资源消耗情况,由此可见,当前获取的处理器功耗结果存在准确性不足,无法为设备续航性能优化提供准确依据。In the prior art, the power consumption parameter of the processor is generally obtained by detecting the power consumption data of the electronic device when performing different user operations. However, the power consumption parameter of the processor obtained in this way is easily affected by the power consumption of other power-consuming devices. It cannot reflect the resource consumption in the actual data processing process of the processor. It can be seen that the accuracy of the currently obtained processor power consumption results is insufficient and cannot provide an accurate basis for the optimization of device battery life performance.
本发明提供上述的解决方案,旨在提高处理器的功耗获取结果的准确性,以为设备续航性能优化提供准确依据。The present invention provides the above solution, aiming to improve the accuracy of the power consumption acquisition result of the processor, and provide an accurate basis for optimizing the battery life performance of the device.
本发明实施例提出一种电子设备,可以是电子手表、电子手环、手机、平板电脑等任意具有处理器的用电设备。在本实施例中,电子设备所运行的操作系统为安卓系统;在其他实施例中,电子设备所运行的操作系统还可根据实际需求设置为其他类型的操作系统,如linux系统、windows系统、ios系统等。The embodiment of the present invention proposes an electronic device, which may be any electrical device with a processor, such as an electronic watch, an electronic wristband, a mobile phone, and a tablet computer. In this embodiment, the operating system run by the electronic device is the Android system; in other embodiments, the operating system run by the electronic device can also be set to other types of operating systems according to actual needs, such as ios system, etc.
在本发明实施例中,参照图1,电子设备包括第一处理器1和功耗监控模块2,功耗监控模块2与第一处理器1连接,以对第一处理器1的功耗情况进行分析。In this embodiment of the present invention, referring to FIG. 1 , the electronic device includes a first processor 1 and a power
具体的,在本实施例中,功耗监控模块2包括:第二处理器2001,存储器2002,计时器2003等。存储器2002可以是高速RAM存储器,也可以是稳定的存储器(non-volatilememory),例如磁盘存储器。存储器1002可选的还可以是独立于前述处理器1001的存储装置。其中,第一处理器1也具有对应的存储器等数据处理所需的硬件模块,第一处理器1对应的存储器中存储有电子设备功能相关任务的运行程序等。第一处理器1与第二处理器2001可根据实际需求共用一个存储器或采用不同的存储器。Specifically, in this embodiment, the power
在本实施例中,第一处理器1具体为CPU,在其他实施例中,第一处理器1还可根据实际需求设置为电子设备中除CPU以外的其他类型的处理器。In this embodiment, the first processor 1 is specifically a CPU. In other embodiments, the first processor 1 can also be set to other types of processors other than the CPU in the electronic device according to actual requirements.
第一处理器1在进行数据处理的过程中,不同的任务可采用不同的进程,一个任务可分为若干个子任务,不同的子任务由一个进程对应的不同线程并行执行。In the process of data processing by the first processor 1, different tasks may adopt different processes, one task may be divided into several subtasks, and different subtasks are executed in parallel by different threads corresponding to one process.
进一步的,在本实施例中,参照图1,电子设备还可包括电池3和与电池3连接的电量监控模块4,电量监控模块4用于检测电池3的耗电参数(如耗电速率等)。Further, in this embodiment, referring to FIG. 1 , the electronic device may further include a
本领域技术人员可以理解,图1中示出的设备结构并不构成对设备的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。Those skilled in the art can understand that the device structure shown in FIG. 1 does not constitute a limitation on the device, and may include more or less components than the one shown, or combine some components, or arrange different components.
如图1所示,作为一种计算机可读存储介质的存储器1002中可以包括计算机程序。在图1所示的设备中,处理器1001可以用于调用存储器1002中存储的计算机程序,并执行以下实施例中处理器功耗获取方法的相关步骤操作。As shown in FIG. 1, the memory 1002, which is a computer-readable storage medium, may include a computer program. In the device shown in FIG. 1 , the processor 1001 can be used to call the computer program stored in the memory 1002 and execute the relevant steps of the method for obtaining the power consumption of the processor in the following embodiments.
本发明实施例还提供一种处理器功耗获取方法,应用于对上述第一处理器的功耗进行分析。An embodiment of the present invention further provides a method for obtaining power consumption of a processor, which is applied to analyze the power consumption of the first processor.
参照图2,提出本申请处理器功耗获取方法一实施例。在本实施例中,所述处理器功耗获取方法包括:Referring to FIG. 2 , an embodiment of a method for obtaining power consumption of a processor of the present application is proposed. In this embodiment, the method for obtaining the power consumption of the processor includes:
步骤S10,获取目标时间段和目标运行频率;所述目标时间段为处理器调用目标线程执行任务的时间段,所述目标运行频率为所述目标时间段内所述处理器的运行频率;Step S10, obtaining a target time period and a target operating frequency; the target time period is the time period during which the processor invokes the target thread to perform a task, and the target operating frequency is the operating frequency of the processor within the target time period;
目标线程具体指的是在对电子设备在特定场景下的处理器能耗分析时处理器所调用来执行运行场景下的任务的线程。目标线程可以基于测试指令确定的线程、也可以将特定运行场景下所有线程作为目标线程。目标线程的数据可根据需求有一个或多于一个。The target thread specifically refers to a thread called by the processor to execute a task in the running scenario when analyzing the processor energy consumption of the electronic device in a specific scenario. The target thread can be determined based on the test instruction, or all threads in a specific running scenario can be used as the target thread. The target thread's data can have one or more than one as needed.
这里的特定场景可根据实际情况进行设置,可以是电子设备运行过程中运行参数达到设定状态时的场景、也可以是电子设备从开机到当前时刻或到关机时的整个运行过程、也可以是接收到设定检测指令时电子设备的运行状态,等等。The specific scene here can be set according to the actual situation. It can be the scene when the operating parameters of the electronic device reach the set state during the operation of the electronic device, or the entire running process of the electronic device from power-on to the current moment or to the power-off time, or The operating state of the electronic equipment when the set detection command is received, etc.
对于一个目标线程而言,其对应的目标时间段可根据实际情况有一个或多于一个。具体的,在特定场景下,处理器调用目标线程的次数为一次时,则目标时间段有一个,处理器调用目标线程的次数多于一次时,则目标时间段多于一个。For a target thread, its corresponding target time period may have one or more than one according to the actual situation. Specifically, in a specific scenario, when the processor calls the target thread once, there is one target time period, and when the processor calls the target thread more than once, there is more than one target time period.
处理器在其运行过程中,不同的时间段内可有不同的运行频率。目标运行频率具体为目标时间段内处理器所运行的实际频率。若处理器在目标时间段内以固定频率运行,则目标运行频率的数量为一个;若处理器在目标时间段内以不同的频率运行,则目标运行频率的数量多于一个。During its operation, the processor may have different operating frequencies in different time periods. The target operating frequency is specifically the actual frequency at which the processor operates within the target time period. If the processor operates at a fixed frequency within the target time period, the number of target operating frequencies is one; if the processor operates at different frequencies within the target time period, the number of target operating frequencies is more than one.
目标时间段和目标运行频率可通过获取测试人员输入的参数得到;也可以在电子设备开机后运行过程中记录的运行信息进行提取;还可通过读取电子设备在处理器功耗监控模式下生成监控日志数据分析得到。The target time period and target operating frequency can be obtained by obtaining the parameters input by the tester; it can also be extracted from the operating information recorded during the operation of the electronic device after it is turned on; it can also be generated by reading the electronic device in the processor power consumption monitoring mode. Monitoring log data analysis is obtained.
步骤S20,根据所述目标时间段和所述目标运行频率确定所述处理器的功耗参数。Step S20, determining a power consumption parameter of the processor according to the target time period and the target operating frequency.
功耗参数具体为表征处理器消耗资源大小的特征参数,可以是一个具体的数值,也可以是一个功耗等级。The power consumption parameter is specifically a characteristic parameter representing the size of the processor's consumption resources, which may be a specific value or a power consumption level.
处理器的功耗参数包括处理器执行单个线程时的功耗参数、处理器执行多个线程(可以是一个进程中的部分或全部线程、也可以是不同进程中执行关键任务的多个线程)时的功耗参数、处理器执行单个进程(一个进程可包括单个线程或多个线程)时的功耗参数、处理器执行多个进程时的功耗参数和/或处理器搭载的操作系统(如安卓系统)的功耗参数等。The power consumption parameters of the processor include the power consumption parameters when the processor executes a single thread, the processor executes multiple threads (which can be some or all threads in a process, or multiple threads that perform critical tasks in different processes) power consumption parameters when the processor executes a single process (a process may include a single thread or multiple threads), power consumption parameters when the processor executes multiple processes and/or the operating system ( Such as Android system) power consumption parameters, etc.
目标时间段、目标运行频率与功耗参数之间的对应关系可预先设置,可以是计算公式、映射关系、机器学习模型等。基于该对应关系,可确定当前目标时间段和目标运行频率所对应的处理器的功耗参数。The corresponding relationship between the target time period, the target operating frequency and the power consumption parameter can be preset, which can be a calculation formula, a mapping relationship, a machine learning model, and the like. Based on the corresponding relationship, the power consumption parameters of the processor corresponding to the current target time period and the target operating frequency can be determined.
在本实施例中,可通过目标时间段对应的时长和目标运行频率来计算处理器的功耗参数。具体的,目标线程对应的目标时间段为T至T’,该时间段内处理器运行的频率为固定为F时,则可将(T’-T)*F作为处理器的功耗参数。In this embodiment, the power consumption parameter of the processor may be calculated according to the duration corresponding to the target time period and the target operating frequency. Specifically, the target time period corresponding to the target thread is from T to T', and when the operating frequency of the processor in this time period is fixed as F, then (T'-T)*F can be used as the power consumption parameter of the processor.
进一步的,在另一实施例中,所述目标运行频率包括至少两个不同的子频率,所述根据所述目标时间段和所述目标运行频率确定所述处理器的功耗参数的步骤包括:确定所述目标时间段内每个所述子频率对应运行的子时间段;根据每个所述子时间段及其对应的子频率确定所述功耗参数。例如,目标线程对应的目标时间段为T至T’,目标时间段内处理器在T至T”时间段内以F1频率运行,处理器在T”至T’时间段内以F2频率运行,则处理器的功耗参数=(T”-T)*F1+(T’-T”)*F2。Further, in another embodiment, the target operating frequency includes at least two different sub-frequency, and the step of determining the power consumption parameter of the processor according to the target time period and the target operating frequency includes: : determine the sub-time period corresponding to each of the sub-frequency in the target time period; determine the power consumption parameter according to each of the sub-time period and its corresponding sub-frequency. For example, the target time period corresponding to the target thread is T to T', the processor runs at the F1 frequency in the T to T" time period during the target time period, and the processor runs at the F2 frequency in the T" to T' time period. Then the power consumption parameter of the processor=(T"-T)*F1+(T'-T")*F2.
本发明实施例提出的一种处理器功耗获取方法,该方法结合处理器调用目标线程执行任务的目标时间段和该目标时间段内处理器的运行频率来确定处理器的功耗参数,由于目标时间段和目标运行频率均为处理器调用目标线程执行任务时的相关运行参数,因此所得到的功耗参数可准确反映处理器调用线程执行任务过程中的能耗情况,不受其他耗电器件的能耗影响,有效提高处理器的功耗获取结果的准确性,保证处理器的功耗获取结果可为设备续航性能优化提供准确依据,实现电子设备续航能力的有效提高。An embodiment of the present invention provides a method for obtaining power consumption of a processor, which determines a power consumption parameter of a processor in combination with a target time period during which the processor calls a target thread to execute a task and the operating frequency of the processor in the target time period. The target time period and target operating frequency are the relevant operating parameters when the processor calls the target thread to execute the task, so the obtained power consumption parameter can accurately reflect the energy consumption during the process of the processor calling the thread to execute the task, and is not subject to other power consumption. The influence of the power consumption of the device can effectively improve the accuracy of the power consumption acquisition result of the processor, ensure that the power consumption acquisition result of the processor can provide an accurate basis for the optimization of the battery life performance of the device, and effectively improve the battery life of the electronic device.
进一步的,基于上述实施例,提出本申请处理器功耗获取方法另一实施例。在本实施例中,所述目标线程的数量有多个,对应获取的目标时间段和目标运行频率也有多个;其中,在每个目标线程对应的目标时间段可有一个或多个(根据处理器调用每个目标线程的次数具体确定),每个目标时间段对应的目标运行频率可有一个或多个(具体根据处理器在该时间段内的实际运行情况确定)。基于此,参照图3,所述步骤S20包括:Further, based on the above embodiment, another embodiment of the method for obtaining power consumption of a processor of the present application is proposed. In this embodiment, there are multiple target threads, and there are also multiple target time periods and target operating frequencies obtained correspondingly; wherein, there may be one or more target time periods corresponding to each target thread (according to The number of times the processor calls each target thread is specifically determined), and each target time period corresponds to one or more target operating frequencies (specifically determined according to the actual operation of the processor in the time period). Based on this, referring to FIG. 3 , the step S20 includes:
步骤S21,根据每个所述目标线程对应的目标时间段和目标运行频率确定所述处理器调用每个所述目标线程时的子功耗参数;Step S21, determining the sub-power consumption parameter when the processor calls each of the target threads according to the target time period and target operating frequency corresponding to each of the target threads;
一个目标线程对应得到一个子功耗参数。每个目标线程对应的子功耗参数可通过每个目标线程对应的目标时间段和目标运行频率按照预设对应关系中的方式进行计算、映射或代入算法模型中得到。A target thread corresponds to a sub-power consumption parameter. The sub-power consumption parameter corresponding to each target thread can be obtained by calculating, mapping or substituting into the algorithm model the target time period and target operating frequency corresponding to each target thread according to the preset corresponding relationship.
参照图4,图4为电子设备开机状态下一段时间内处理器执行任务时相关运行参数。具体的,图4a表征的是不同处理器调用不同线程执行任务的时间信息,其中A、B、C表示的是不同线程,相对基线的凸出部表示对应的线程调用;图4b表征的是处理器的运行状态信息(运行状态或未运行状态),相对基线的凸出部表示处理器处于运行状态;图4c表征的处理器在不同时间的运行频率,凸出部的高低表征的是频率的大小。其中,在本实施例中,T0具体指的是电子设备开机后处理器的启动时刻。在其他实施例中,T0也可以是电子设备在运行状态下达到设定条件时(如电量低于设定阈值或接收到设定指令等)的时刻。Referring to FIG. 4 , FIG. 4 shows relevant operating parameters when the processor executes a task for a period of time when the electronic device is powered on. Specifically, Figure 4a represents the time information when different processors call different threads to execute tasks, wherein A, B, and C represent different threads, and the bulge relative to the baseline represents the corresponding thread call; Figure 4b represents the processing The operating state information (operating state or non-operating state) of the processor, the protrusion relative to the baseline indicates that the processor is in the operating state; Figure 4c represents the operating frequency of the processor at different times, and the height of the protrusion represents the frequency size. Wherein, in this embodiment, T0 specifically refers to the start time of the processor after the electronic device is powered on. In other embodiments, T0 may also be the time when the electronic device reaches a set condition in a running state (eg, the power level is lower than a set threshold or a set instruction is received, etc.).
基于此,线程A的子功耗参数M1=F0*(T1-T0)+F1*(T5-T4);线程B的子功耗参数M2=F0*(T3-T2)+F1*(T6-T5);线程C的子功耗参数M3=F1*(T7–T6);此外,在T1-T2时间段内处理器未有调用线程执行任务,基于此还可确定该时间段内处理器搭载的操作系统的功耗参数M4=F0*(T2-T1)。Based on this, the sub-power consumption parameter M1 of thread A=F0*(T1-T0)+F1*(T5-T4); the sub-power consumption parameter M2 of thread B=F0*(T3-T2)+F1*(T6- T5); the sub-power consumption parameter of thread C M3=F1*(T7-T6); in addition, the processor does not call the thread to perform tasks during the T1-T2 time period, based on this, it can also be determined that the processor is equipped with The power consumption parameter of the operating system M4=F0*(T2-T1).
步骤S22,确定多个所述目标线程中目标进程对应的所有子线程;Step S22, determining all sub-threads corresponding to the target process in the multiple described target threads;
目标进程具体为需要获取功耗的处理器所执行进程。目标进程可通过根据接收到的测试指令(可由测试人员发出)确定,也可在电子设备运行达到设定状态时(例如电量低于设定阈值或耗电速率大于设定速率等)处理器所执行的进出作为目标进程。The target process is specifically the process executed by the processor that needs to obtain power consumption. The target process can be determined according to the received test instructions (which can be issued by the tester), or can be determined by the processor when the electronic equipment runs to a set state (for example, the power is lower than the set threshold or the power consumption rate is greater than the set rate, etc.). Execute in and out as the target process.
其中,电子设备在运行过程中,处理器执行某个任务进程时可调用多个线程并行执行该任务对应的多个子任务,系统中会记录其所执行进程的进程标识以及对应线程的线程标识,形成进程与线程的对应关系。基于此,获取进程与线程的对应关系,便可确定目标进程所对应的所有子线程。Among them, during the operation of the electronic device, when the processor executes a certain task process, the processor can call multiple threads to execute multiple sub-tasks corresponding to the task in parallel, and the system will record the process ID of the executed process and the thread ID of the corresponding thread. The corresponding relationship between processes and threads is formed. Based on this, by acquiring the correspondence between processes and threads, all child threads corresponding to the target process can be determined.
步骤S23,根据所述目标进程对应的所有子线程的子功耗参数确定所述处理器执行所述目标进程时的总功耗参数;Step S23, determining a total power consumption parameter when the processor executes the target process according to the sub-power consumption parameters of all sub-threads corresponding to the target process;
具体的,可将所有子功率参数的总和作为总功耗参数。Specifically, the sum of all sub-power parameters may be used as the total power consumption parameter.
例如,目标进程对应的所有线程为上述的线程A和线程B,则目标进程对应的总功耗参数=M1+M2。For example, if all threads corresponding to the target process are the above-mentioned thread A and thread B, the total power consumption parameter corresponding to the target process=M1+M2.
步骤S24,确定总功耗参数为所述处理器的功耗参数。Step S24, determining that the total power consumption parameter is the power consumption parameter of the processor.
需要说明的是,在其他实施例中,也可将M1+M2+M3作为处理器的功耗参数;或者,将M1+M2+M3+M4作为处理器的功耗参数,等等。It should be noted that, in other embodiments, M1+M2+M3 may also be used as the power consumption parameter of the processor; or, M1+M2+M3+M4 may be used as the power consumption parameter of the processor, and so on.
在本实施例中,进程作为计算机执行任务过程中独立运行和拥有资源的最小单位,因此进程可反映处理器在执行特定任务时的资源分配情况,这里通过上述步骤可实现以进程为单位获取处理器执行任务过程中功耗参数,可保证所得到的功耗参数可准确反映处理器在分配资源固定时功耗情况,实现对处理器的功耗情况实现准确表征。In this embodiment, a process is the smallest unit that runs independently and owns resources in the process of a computer performing a task. Therefore, a process can reflect the resource allocation of the processor when performing a specific task. Here, the above steps can be used to obtain processing in units of processes. The power consumption parameters during the execution of tasks by the processor can ensure that the obtained power consumption parameters can accurately reflect the power consumption of the processor when the allocated resources are fixed, so as to achieve accurate representation of the power consumption of the processor.
进一步的,基于上述任一实施例,提出本申请处理器功耗获取方法又一实施例。在本实施例中,参照图5,所述步骤S10包括:Further, based on any of the above embodiments, another embodiment of the method for obtaining power consumption of a processor of the present application is proposed. In this embodiment, referring to FIG. 5 , the step S10 includes:
步骤S11,获取所述处理器对应的线程调度日志、处理器状态日志和处理器频率日志;Step S11, acquiring the thread scheduling log, the processor status log and the processor frequency log corresponding to the processor;
线程调度日志具体为在处理器调用线程执行任务过程中记录的日志信息。处理器状态日志具体为记录电子设备开机后处理器是否运行的日志信息。处理器频率日志具体为记录处理器在运行过程运行频率的日志信息。The thread scheduling log is specifically log information recorded in the process of the processor invoking the thread to execute the task. The processor status log is specifically log information that records whether the processor is running after the electronic device is powered on. The processor frequency log is specifically log information that records the running frequency of the processor during the running process.
线程调度日志、处理器状态日志和处理器频率日志可具体在电子设备处于设定模式时生成。设定模式具体为对所述电子设备的处理器功耗进行监控的模式。具体的,可在电子设备运行达到设定条件时(如电子设备的电量低于设定电量时)进入设定模式,也可在接收到测试人员或用户输入的设定指令时控制电子设备进入设定模式。The thread scheduling log, the processor status log, and the processor frequency log may be generated specifically when the electronic device is in set mode. The setting mode is specifically a mode for monitoring the power consumption of the processor of the electronic device. Specifically, the electronic device can enter the setting mode when the operation of the electronic device reaches the set condition (for example, when the power of the electronic device is lower than the set power), or control the electronic device to enter the setting mode when receiving the setting instruction input by the tester or the user. Set mode.
具体的,在步骤S11之前,在电子设备处于设定模式时,根据所述处理器的状态信息和当前时间戳生成所述处理器状态日志;所述状态信息为处理器是否处于运行状态的信息;根据所述处理器所调度的线程的标识信息(如下面的线程id、线程名称等)、线程的任务状态信息(如下面的sched_start、sched_end等)以及当前时间戳生成所述线程调度日志;根据所述处理器运行的频率值和当前时间戳生成所述处理器频率日志;其中,所述设定模式为对所述电子设备的处理器功耗进行监控的模式,所述时间戳从所述电子设备开机时开始计时。这里在需要处理器的功耗进行监控时,获取相应的数据生成处理器功耗监控所需的日志数据,从而使后续处理器功耗获取时可快速地获取到处理器执行任务有关的状态数据,有利于提高处理器功耗获取的速率,实现快速、准确地实现处理器功耗获取。Specifically, before step S11, when the electronic device is in the setting mode, the processor state log is generated according to the state information of the processor and the current time stamp; the state information is information about whether the processor is in a running state ; Generate the thread scheduling log according to the identification information of the thread scheduled by the processor (such as the following thread id, thread name, etc.), the task status information of the thread (such as the following sched_start, sched_end, etc.) and the current timestamp; The processor frequency log is generated according to the running frequency value of the processor and the current time stamp; wherein the setting mode is a mode for monitoring the power consumption of the processor of the electronic device, and the time stamp is obtained from all Start timing when the electronic device is turned on. Here, when the power consumption of the processor needs to be monitored, the corresponding data is obtained to generate the log data required for monitoring the power consumption of the processor, so that the status data related to the tasks executed by the processor can be quickly obtained when the power consumption of the processor is obtained subsequently. , which is beneficial to improve the rate of processor power consumption acquisition, and realize the fast and accurate realization of processor power consumption acquisition.
具体的,在获取到相应的信息后可按照预设日志格式生成上述三种类型的日志,在本实施例中,三种类型的日志格式及其日志内容具体如下:Specifically, after obtaining the corresponding information, the above three types of logs can be generated according to the preset log format. In this embodiment, the three types of log formats and their log contents are as follows:
1.线程调度日志:1. Thread scheduling log:
日志格式:[线程名]-[线程号][空格](进程号)[空格][时间戳][:][线程任务][:][CPU索引];Log format: [thread name]-[thread number][space](process number)[space][timestamp][:][thread task][:][CPU index];
参数说明:Parameter Description:
[线程名]当前运行任务所属的线程名称;[Thread name] The thread name to which the currently running task belongs;
[线程号]当前运行任务所属的线程id;[Thread number] The thread id to which the currently running task belongs;
[进程号]当前运行任务所属的进程id;其中,上述实施例中确定目标进程对应的所有进程时,可基于这里线程调度日志记载的进程号与线程标识(线程号或线程名)来分析得到线程与进程的对应关系。[process number] the process id to which the current running task belongs; wherein, when all processes corresponding to the target process are determined in the above-mentioned embodiment, the process number and thread identifier (thread number or thread name) recorded in the thread scheduling log here can be analyzed and obtained Correspondence between threads and processes.
[时间戳]从开机到目前的运行时间,单位可为毫秒,也可精确到纳秒;[Timestamp] The running time from boot to current, in milliseconds, or accurate to nanoseconds;
[线程任务]有两个值,sched_start代表任务开始运行,sched_end代表任务调度结束;[Thread task] has two values, sched_start represents the start of the task, and sched_end represents the end of the task scheduling;
[CPU索引]CPU的唯一标识,表征当前调度执行在哪个CPU上。CPU索引具体用于区分不同处理器的日志数据。目标处理器所对应的线程调度日志可通过这里的CPU索引进行确定。[CPU index] The unique identifier of the CPU, which indicates which CPU is currently scheduled to execute. The CPU index is specifically used to distinguish the log data of different processors. The thread scheduling log corresponding to the target processor can be determined by the CPU index here.
示例:Binder:571_1-649(571)92103.062452:sched_start:cpu_id=2。Example: Binder:571_1-649(571)92103.062452:sched_start:cpu_id=2.
其中,可在电子设备开机后间隔设定时长按照这里的约定日志格式获取相应的信息生成日志数据。在电子设备的运行过程中,设定模式下,电子设备口可采用不同处理器调用线程执行任务,每个处理器执行任务时均可按照这里的日志格式生成相应的日志数据,将日志数据保存到内存中形成线程调度日志。Wherein, log data can be generated by obtaining corresponding information according to the agreed log format here at intervals of a set time period after the electronic device is turned on. During the operation of the electronic device, in the setting mode, the electronic device port can use different processors to call threads to execute tasks. When each processor executes a task, it can generate corresponding log data according to the log format here, and save the log data. To the memory to form a thread scheduling log.
2.处理器状态日志:2. Processor status log:
日志格式:[线程名]-[线程号][空格](进程号)[空格][时间戳][:][CPU状态][:][状态信息][CPU索引];Log format: [thread name]-[thread number][space](process number)[space][timestamp][:][CPU status][:][status information][CPU index];
参数说明:Parameter Description:
[线程名]固定为idle;[Thread name] is fixed to idle;
[线程号]固定为0;[Thread number] is fixed to 0;
[进程号]固定为-----;[Process ID] is fixed to -----;
[时间戳]从开机到目前的运行时间,单位为毫秒,也可精确到纳秒;[Timestamp] The running time from boot to current, in milliseconds, and accurate to nanoseconds;
[CPU状态]固定值cpu_idle,代表当前数据为处理器状态日志;[CPU status] A fixed value of cpu_idle, which means the current data is the processor status log;
[状态信息]代表当前CPU是否处于运行态,0代表运行,其它代表未运行,关键字为state=;[Status information] represents whether the current CPU is in the running state, 0 means running, other means not running, the keyword is state=;
[CPU索引]CPU的唯一标识,表征当前调度执行在哪个CPU上,关键字为“cpu_id=”。CPU索引具体用于区分不同处理器的日志数据。目标处理器所对应的处理器状态日志可通过这里的CPU索引进行确定。[CPU index] The unique identifier of the CPU, which indicates which CPU is currently scheduled to be executed, and the keyword is "cpu_id=". The CPU index is specifically used to distinguish the log data of different processors. The processor status log corresponding to the target processor can be determined by the CPU index here.
示例:<idle>-0(-----)92103.062452:cpu_idle:state=2cpu_id=2。Example: <idle>-0(-----)92103.062452:cpu_idle:state=2cpu_id=2.
其中,可在电子设备开机后间隔设定时长按照这里的约定日志格式获取相应的信息生成日志数据。在电子设备开机后,设定模式下电子设备中不同的处理器可根据任务执行需求运行或停止运行,每个处理器在运行状态下或在未运行状态下均可按照这里的日志格式生成相应的日志数据,将日志数据保存到内存中形成处理器状态日志。Wherein, log data can be generated by obtaining corresponding information according to the agreed log format here at intervals of a set time period after the electronic device is turned on. After the electronic device is turned on, different processors in the electronic device can run or stop running according to the task execution requirements in the setting mode, and each processor can generate corresponding logs in the log format here in the running state or in the non-running state. The log data is stored in the memory to form the processor status log.
3.处理器频率日志:3. Processor frequency log:
日志格式:[线程名]-[线程号][空格](进程号)[空格][时间戳][:][CPU频率][:][频率信息][CPU索引];Log format: [thread name]-[thread number][space](process number)[space][timestamp][:][CPU frequency][:][frequency information][CPU index];
参数说明:Parameter Description:
[线程名]固定为run;[Thread name] is fixed to run;
[线程号]固定为0;[Thread number] is fixed to 0;
[进程号]固定为-----;[Process ID] is fixed to -----;
[时间戳]从开机到目前的运行时间,单位为毫秒,也可精确到纳秒;[Timestamp] The running time from boot to current, in milliseconds, and accurate to nanoseconds;
[CPU频率]固定值cpu_frequency,代表当前数据为处理器频率日志;[CPU frequency] A fixed value of cpu_frequency, which means the current data is the processor frequency log;
[频率信息]代表当前CPU运行频率值,关键字为state=;[Frequency information] represents the current CPU operating frequency value, the keyword is state=;
[CPU索引]CPU的唯一标识,表征当前调度执行在哪个CPU上,关键字为“cpu_id=”。CPU索引具体用于区分不同处理器的日志数据。目标处理器所对应的处理器频率日志可通过这里的CPU索引进行确定。[CPU index] The unique identifier of the CPU, which indicates which CPU is currently scheduled to be executed, and the keyword is "cpu_id=". The CPU index is specifically used to distinguish the log data of different processors. The processor frequency log corresponding to the target processor can be determined by the CPU index here.
示例:<run>-0(-----)92103.062452:cpu_frequency:state=2016000cpu_id=2。Example: <run>-0(-----)92103.062452:cpu_frequency:state=2016000cpu_id=2.
其中,可在电子设备开机后间隔设定时长按照这里的约定日志格式获取相应的信息生成日志数据。在电子设备开机后,设定模式下电子设备中不同的处理器可根据任务执行需求运行或停止运行,每个处理器在运行状态以固定或不同频率运行时均可按照这里的日志格式生成相应的日志数据,将日志数据保存到内存中形成处理器频率日志。Wherein, log data can be generated by obtaining corresponding information according to the agreed log format here at intervals of a set time period after the electronic device is turned on. After the electronic device is turned on, different processors in the electronic device can run or stop running according to the task execution requirements in the setting mode. When each processor runs at a fixed or different frequency in the running state, it can generate corresponding logs according to the log format here. The log data is stored in the memory to form the processor frequency log.
进一步的,在获取上述三种日志进行处理器功耗获取之前,可以循环链表形式保存所述线程调度日志、处理器状态日志和处理器频率日志。由于设备开机后设定模式下会持续生成上述三种日志,通过循环链表形式对日志数据进行保存,有利于减少日志存储所占用的内存空间同时方便后续的处理器功耗获取效率和准确性。Further, before obtaining the above three kinds of logs to obtain the processor power consumption, the thread scheduling log, the processor status log and the processor frequency log may be saved in the form of a circular linked list. Since the above three kinds of logs are continuously generated in the setting mode after the device is powered on, the log data is saved in the form of a circular linked list, which is beneficial to reduce the memory space occupied by the log storage and facilitate the subsequent processor power consumption to obtain efficiency and accuracy.
步骤S12,根据所述处理器状态日志确定所述处理器的运行时间段;Step S12, determining the running time period of the processor according to the processor state log;
运行时间段指的是处理器处于运行状态的时间段,解析处理器状态日志中的数据可得到处理器的运行时间段。The running time period refers to the time period when the processor is in the running state. The running time period of the processor can be obtained by parsing the data in the processor status log.
具体的,当所述处理器状态日志包含设定状态标识时,根据所述处理器状态日志的第一时间戳确定所述运行时间段;其中,所述第一时间戳为所述处理器所在的电子设备从开机到所述处理器状态日志生成时的运行时长,所述设定状态标识为所述处理器处于运行状态时的标识。在本实施例中,处理器状态日志可包括多个以上述日志格式保存的状态数据,在多个状态数据中“状态信息”字段为state=0时,可提取该条状态数据的时间戳,所提取到的时间戳集合对应形成的时间段可作为处理器的运行时间段。Specifically, when the processor status log contains a set status identifier, the running time period is determined according to a first timestamp of the processor status log; wherein the first timestamp is where the processor is located The running duration of the electronic device from power-on to when the processor state log is generated, and the set state identifier is an identifier when the processor is in a running state. In this embodiment, the processor state log may include a plurality of state data saved in the above log format, and when the "state information" field in the plurality of state data is state=0, the timestamp of the piece of state data can be extracted, The time period corresponding to the extracted time stamp set can be used as the running time period of the processor.
具体的,依据处理器状态日志的解析结果生成如图4b所示的时序图,基于图4b,可确定在T0至T7的时间段内处理器处于运行状态,也就是说,处理器的运行时间段为T0至T7的时间段。Specifically, the sequence diagram shown in Figure 4b is generated according to the analysis result of the processor state log. Based on Figure 4b, it can be determined that the processor is in the running state during the time period from T0 to T7, that is, the running time of the processor The segment is the time period from T0 to T7.
步骤S13,根据所述线程调度日志在所述运行时间段内确定所述目标线程对应的目标时间段;Step S13, determining the target time period corresponding to the target thread within the running time period according to the thread scheduling log;
所述线程调度日志包括若干条调度数据,在若干条调度数据段内筛选所述运行时间段对应的数据,对筛选出的调度数据的日志内容进行解析得到这里的目标时间段。The thread scheduling log includes several pieces of scheduling data, the data corresponding to the running time period is screened in the several pieces of scheduling data, and the target time period is obtained by parsing the log content of the screened scheduling data.
具体的,所述调度数据包括所述处理器所调度的线程的标识信息、线程的任务状态信息及其对应的第二时间戳,所述第二时间戳为所述处理器所在设备从开机到所述调度数据生成时的运行时长,确定所述线程调度日志中的目标调度数据;所述目标调度数据为第二时间戳位于所述运行时间段内、且所述标识信息为所述目标线程的标识的调度数据;将第一目标数据的第二时间戳确定为第一目标时间,将第二目标数据的第二时间戳确定为第二目标时间;所述第一目标数据为所述目标调度数据中任务状态信息为任务开始(如上述的sched_start)的调度数据,所述第二目标数据为所述目标调度数据中任务状态信息为任务结束(如上述的sched_end)的调度数据;根据所述第一目标时间和所述第二目标时间确定所述目标时间段。具体的,若第一目标时间和第二目标时间各有一个,则第一目标时间与第二目标时间之间的时间段可为目标时间段;若第一目标时间和第二目标时间分别多于一个,则将时间相邻的第一目标时间与第二目标时间之间的时间段分别作为目标时间段,则得到的目标时间段多于一个,需要说明的是,目标时间段以第一目标时间为时间起点。Specifically, the scheduling data includes the identification information of the thread scheduled by the processor, the task status information of the thread, and a corresponding second time stamp, and the second time stamp is the time from the boot to the time when the device where the processor is located. The running duration when the scheduling data is generated determines the target scheduling data in the thread scheduling log; the target scheduling data is that the second timestamp is within the running time period, and the identification information is the target thread The scheduling data of the identifier; the second time stamp of the first target data is determined as the first target time, and the second time stamp of the second target data is determined as the second target time; the first target data is the target The task status information in the scheduling data is the scheduling data of the task start (such as the above-mentioned sched_start), and the second target data is the scheduling data of the task status information in the target scheduling data that the task ends (such as the above-mentioned sched_end); The first target time and the second target time determine the target time period. Specifically, if there is one first target time and one second target time, the time period between the first target time and the second target time may be the target time period; if the first target time and the second target time are longer than If there is more than one target time period, the time period between the adjacent first target time and the second target time is respectively used as the target time period, then the obtained target time period is more than one. The target time is the start of time.
具体的,线程调度日志具体可包括多个以上述日志格式存储的调度数据,基于此,首先可基于调度数据中的时间戳与目标时间段内的匹配结果对所有调度数据进行筛选,时间戳在目标时间段内则作为目标调度数据,时间戳不在目标时间段内则暂不作处理。对筛选得到的所有目标调度数据中的日志内容进行解析,可得到类似图4a所示的处理器调用线程的时序图等解析结果,解析结果中包含处理器在其运行时间段内调用的所有线程(包含目标线程在内的一个或多个线程,其中多个线程除了包括目标线程以外还可包括其他线程)、每个线程调用的起始时间和结束时间等信息。基于解析结果可确定目标线程所对应的目标时间段。Specifically, the thread scheduling log can specifically include a plurality of scheduling data stored in the above log format. Based on this, firstly, all scheduling data can be filtered based on the matching result between the timestamp in the scheduling data and the target time period, and the timestamp is in Within the target time period, it is used as the target scheduling data, and if the timestamp is not within the target time period, it will not be processed temporarily. By analyzing the log content in all the target scheduling data obtained by screening, the analysis results such as the sequence diagram of the processor calling thread shown in Figure 4a can be obtained, and the analysis result includes all the threads called by the processor during its running time period. (including one or more threads including the target thread, where the multiple threads may include other threads in addition to the target thread), the start time and end time of each thread call, etc. The target time period corresponding to the target thread may be determined based on the parsing result.
具体的,结合图4a,目标线程为线程A时,目标时间段包括T0至T1时间段以及T4至T5时间段;目标线程为线程B时,目标时间段包括T2至T4时间段以及T5至T6时间段,等等。Specifically, referring to Fig. 4a, when the target thread is thread A, the target time period includes the time period from T0 to T1 and the time period from T4 to T5; when the target thread is thread B, the target time period includes the time period from T2 to T4 and the time period from T5 to T6 time period, etc.
步骤S14,提取所述处理器频率日志中所述目标时间段对应的频率作为所述目标运行频率。Step S14, extracting the frequency corresponding to the target time period in the processor frequency log as the target operating frequency.
所述处理器频率日志包括若干个频率数据,所述频率数据包括所述处理器运行的频率值及其对应的第三时间戳。具体的,每个频率数据可按照上述日志格式进行存储。基于此,首先可基于每个频率数据中的时间戳与目标时间段内的匹配结果对所有频率数据进行筛选,时间戳在目标时间段内则作为目标频率数据,时间戳不在目标时间段内则暂不作处理。对筛选得到的所有目标频率数据中的日志内容进行解析,可得到类似图4c所示的处理器调用频率的时序图等解析结果,解析结果中包含处理器在其运行时间段内调用频率的频率值(可有一个或多于一个)、每个频率值调用的时间信息等。基于解析结果可确定目标线程在其目标时间段对应的处理器的目标运行频率。The processor frequency log includes several pieces of frequency data, and the frequency data includes a frequency value of the processor running and its corresponding third time stamp. Specifically, each frequency data may be stored according to the above log format. Based on this, all frequency data can be filtered based on the matching result between the timestamp in each frequency data and the target time period. If the timestamp is within the target time period, it is used as the target frequency data, and if the timestamp is not within the target time period Not processed for the time being. By analyzing the log content in all the target frequency data obtained by screening, the analysis results such as the sequence diagram of the processor calling frequency shown in Figure 4c can be obtained, and the analysis results include the frequency of the processor calling frequency during its running time period. value (there can be one or more than one), time information for each frequency value call, etc. Based on the parsing result, the target running frequency of the processor corresponding to the target thread in its target time period may be determined.
具体的,结合图4a和图4c,目标线程为线程A时,在T0至T1时间段内目标运行频率为F0,在T4至T5时间段内目标运行频率为F1;目标线程为线程B时,在T2至T4时间段内目标运行频率有两个(T2至T3时间段对应的F0和T3至T4时间段对应的F1),在T5至T6时间段目标运行频率为F1。Specifically, with reference to Figure 4a and Figure 4c, when the target thread is thread A, the target running frequency is F0 in the time period from T0 to T1, and the target running frequency is F1 in the time period from T4 to T5; when the target thread is thread B, There are two target operating frequencies in the time period from T2 to T4 (F0 corresponding to the time period T2 to T3 and F1 corresponding to the time period T3 to T4), and the target operating frequency in the time period T5 to T6 is F1.
在本实施例中,通过上述方式基于三种日志数据解析得到处理器调用目标进程的目标时间段和目标运行频率,从而实现快速获取到分析处理器功耗所需的数据,实现处理器功耗快速、准确地获取。In this embodiment, the target time period and target running frequency of the processor calling the target process are obtained by analyzing the above three kinds of log data, so that the data required for analyzing the power consumption of the processor can be quickly obtained and the power consumption of the processor can be realized. Get it quickly and accurately.
进一步的,基于上述任一实施例,提出本申请处理器功耗获取方法再一实施例。在本实施例中,参照图6,所述步骤S10之前,还包括:Further, based on any of the above embodiments, another embodiment of the method for obtaining power consumption of a processor of the present application is proposed. In this embodiment, referring to FIG. 6 , before the step S10, it further includes:
步骤S01,监测所述电子设备的耗电速率;Step S01, monitoring the power consumption rate of the electronic device;
这里的耗电速率为表征电子设备的电池耗电快慢的参数。The power consumption rate here is a parameter that characterizes the power consumption speed of the battery of the electronic device.
在电子设备开机后,通过电量监控模块间隔设定时长检测单位时间内电子设备的耗电量,将耗电量与单位时间的比值作为这里的耗电速率。这里的单位时间具体可根据分析需求进行具体设置。After the electronic device is turned on, the power consumption of the electronic device in a unit time is detected by the interval setting of the power monitoring module, and the ratio of the power consumption to the unit time is used as the power consumption rate here. The unit time here can be specifically set according to the analysis requirements.
具体的,可在上述设定模式下,生成上述三种类型日志的同时执行这里的步骤S01,上述生成的三种类型日志可以循环链表的形式保存在内存中。Specifically, in the above setting mode, the above three types of logs are generated and the step S01 is executed at the same time, and the above generated three types of logs can be stored in the memory in the form of a circular linked list.
步骤S02,判断所述耗电速率是否大于或等于设定速率阈值;Step S02, judging whether the power consumption rate is greater than or equal to a set rate threshold;
当所述耗电速率大于或等于设定速率阈值时,执行所述获取目标时间段和目标运行频率的步骤。When the power consumption rate is greater than or equal to a set rate threshold, the step of acquiring a target time period and a target operating frequency is performed.
设定速率阈值的具体大小可根据实际情况进行设置。耗电速率大于或等于设定速率阈值,表明电子设备耗电过快,此时电量监控模块生成保存信号,在检测到保存信号生成时,将内存中的日志数据保存到非易失存储器(flash存储器)中,基于此,后续可实时或延时或接收到设定功耗获取指令时读取非易失存储器中的日志数据解析得到目标时间段和目标运行频率。The specific size of the set rate threshold can be set according to the actual situation. If the power consumption rate is greater than or equal to the set rate threshold, it indicates that the power consumption of the electronic device is too fast. At this time, the power monitoring module generates a save signal. When the generation of the save signal is detected, the log data in the memory is saved to the non-volatile memory (flash). memory), based on this, the target time period and target operating frequency can be obtained by reading log data in the non-volatile memory and analysing the log data in the non-volatile memory in subsequent real-time or delayed or when receiving the set power consumption acquisition instruction.
在本实施例中,在电子设备耗电过快时,触发处理器功耗获取,有利于基于功耗获取结果确定电子设备耗电过快的原因,以为电子设备的续航性能的优化提供更有效更准确的依据,实现电子设备续航能力的提高。In this embodiment, when the power consumption of the electronic device is too fast, the acquisition of the power consumption of the processor is triggered, which is beneficial to determine the cause of the excessive power consumption of the electronic device based on the power consumption acquisition result, so as to provide more effective optimization of the battery life performance of the electronic device A more accurate basis to achieve the improvement of the battery life of electronic equipment.
需要说明的是,在其他实施例中,在不采用日志数据解析方式来获取目标时间段和目标运行频率时,耗电速率监控的过程中可无需生成日志,当所述耗电速率大于或等于设定速率阈值时,按照其他方式(如人工输入等)来获取目标时间段和目标运行频率。It should be noted that, in other embodiments, when the log data parsing method is not used to obtain the target time period and the target operating frequency, there is no need to generate a log in the process of monitoring the power consumption rate. When the power consumption rate is greater than or equal to When setting the rate threshold, obtain the target time period and target operating frequency according to other methods (such as manual input, etc.).
此外,本发明实施例还提出一种计算机可读存储介质,所述计算机可读存储介质上存储有空调控制程序,所述空调控制程序被处理器执行时实现如上处理器功耗获取方法任一实施例的相关步骤。In addition, an embodiment of the present invention also provides a computer-readable storage medium, where an air-conditioning control program is stored on the computer-readable storage medium, and when the air-conditioning control program is executed by a processor, any one of the above methods for obtaining power consumption of the processor is implemented. Relevant steps of the example.
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者系统不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者系统所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者系统中还存在另外的相同要素。It should be noted that, herein, the terms "comprising", "comprising" or any other variation thereof are intended to encompass non-exclusive inclusion, such that a process, method, article or system comprising a series of elements includes not only those elements, It also includes other elements not expressly listed or inherent to such a process, method, article or system. Without further limitation, an element qualified by the phrase "comprising a..." does not preclude the presence of additional identical elements in the process, method, article or system that includes the element.
上述本发明实施例序号仅仅为了描述,不代表实施例的优劣。The above-mentioned serial numbers of the embodiments of the present invention are only for description, and do not represent the advantages or disadvantages of the embodiments.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在如上所述的一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,电子设备,或者网络设备等)执行本发明各个实施例所述的方法。From the description of the above embodiments, those skilled in the art can clearly understand that the method of the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is better implementation. Based on such understanding, the technical solutions of the present invention can be embodied in the form of software products in essence or the parts that make contributions to the prior art, and the computer software products are stored in a storage medium (such as ROM/RAM) as described above. , magnetic disk, optical disk), including several instructions to make a terminal device (which may be a mobile phone, a computer, a server, an electronic device, or a network device, etc.) to execute the methods described in the various embodiments of the present invention.
以上仅为本发明的优选实施例,并非因此限制本发明的专利范围,凡是利用本发明说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本发明的专利保护范围内。The above are only preferred embodiments of the present invention, and are not intended to limit the scope of the present invention. Any equivalent structure or equivalent process transformation made by using the contents of the description and drawings of the present invention, or directly or indirectly applied in other related technical fields , are similarly included in the scope of patent protection of the present invention.
Claims (12)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202110150043.8A CN114860534A (en) | 2021-02-03 | 2021-02-03 | Electronic device and method for obtaining power consumption of processor thereof, and computer-readable storage medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202110150043.8A CN114860534A (en) | 2021-02-03 | 2021-02-03 | Electronic device and method for obtaining power consumption of processor thereof, and computer-readable storage medium |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN114860534A true CN114860534A (en) | 2022-08-05 |
Family
ID=82623015
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202110150043.8A Pending CN114860534A (en) | 2021-02-03 | 2021-02-03 | Electronic device and method for obtaining power consumption of processor thereof, and computer-readable storage medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN114860534A (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| WO2025161419A1 (en) * | 2024-02-02 | 2025-08-07 | 华为技术有限公司 | Performance analysis method, application method, device, readable medium and program product |
Citations (8)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US8281160B1 (en) * | 2008-04-17 | 2012-10-02 | Marvell International Ltd. | Method and system for selecting an operating frequency for a chip to provide a desired overall power dissipation value for the chip |
| JP2012190197A (en) * | 2011-03-10 | 2012-10-04 | Canon Inc | Log processing system |
| CN104820618A (en) * | 2015-04-24 | 2015-08-05 | 华为技术有限公司 | Task scheduling method, task scheduling device and multi-core system |
| CN107436839A (en) * | 2017-07-17 | 2017-12-05 | 广东欧珀移动通信有限公司 | Process load acquisition method, electronic terminal and computer-readable storage medium |
| CN108228414A (en) * | 2017-04-06 | 2018-06-29 | 珠海市魅族科技有限公司 | Processor process parameter monitoring method and monitoring system based on Linux |
| CN108845659A (en) * | 2018-01-30 | 2018-11-20 | 武汉大学 | A kind of embeded processor real-time task distribution method that power consumption is preferential |
| CN109906437A (en) * | 2016-11-01 | 2019-06-18 | 微软技术许可有限责任公司 | Processor core based on thread importance stops and frequency selection |
| CN111651328A (en) * | 2020-06-08 | 2020-09-11 | 北京字节跳动网络技术有限公司 | Thread monitoring method and device |
-
2021
- 2021-02-03 CN CN202110150043.8A patent/CN114860534A/en active Pending
Patent Citations (8)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US8281160B1 (en) * | 2008-04-17 | 2012-10-02 | Marvell International Ltd. | Method and system for selecting an operating frequency for a chip to provide a desired overall power dissipation value for the chip |
| JP2012190197A (en) * | 2011-03-10 | 2012-10-04 | Canon Inc | Log processing system |
| CN104820618A (en) * | 2015-04-24 | 2015-08-05 | 华为技术有限公司 | Task scheduling method, task scheduling device and multi-core system |
| CN109906437A (en) * | 2016-11-01 | 2019-06-18 | 微软技术许可有限责任公司 | Processor core based on thread importance stops and frequency selection |
| CN108228414A (en) * | 2017-04-06 | 2018-06-29 | 珠海市魅族科技有限公司 | Processor process parameter monitoring method and monitoring system based on Linux |
| CN107436839A (en) * | 2017-07-17 | 2017-12-05 | 广东欧珀移动通信有限公司 | Process load acquisition method, electronic terminal and computer-readable storage medium |
| CN108845659A (en) * | 2018-01-30 | 2018-11-20 | 武汉大学 | A kind of embeded processor real-time task distribution method that power consumption is preferential |
| CN111651328A (en) * | 2020-06-08 | 2020-09-11 | 北京字节跳动网络技术有限公司 | Thread monitoring method and device |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| WO2025161419A1 (en) * | 2024-02-02 | 2025-08-07 | 华为技术有限公司 | Performance analysis method, application method, device, readable medium and program product |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN106681811B (en) | Multithreading scheduling method and device based on thread pool | |
| CN103458527B (en) | Preamble detection task processing and dispatching method and device | |
| US20090319835A1 (en) | Processor system optimization supporting apparatus and supporting method | |
| Ouyang et al. | Straggler detection in parallel computing systems through dynamic threshold calculation | |
| CN110941553A (en) | A code detection method, apparatus, device and readable storage medium | |
| CN112749013A (en) | Thread load detection method and device, electronic equipment and storage medium | |
| CN114860534A (en) | Electronic device and method for obtaining power consumption of processor thereof, and computer-readable storage medium | |
| CN113157411A (en) | Reliable configurable task system and device based on Celery | |
| US7490269B2 (en) | Noise accommodation in hardware and software testing | |
| CN112035839A (en) | Detection method and device for race condition vulnerability exploitation | |
| CN107656849B (en) | Method and device for positioning performance problem of software system | |
| CN111679899B (en) | Task scheduling method, device, platform equipment and storage medium | |
| CN112257065A (en) | Process event processing method and device | |
| CN107958414B (en) | Method and system for eliminating long transactions of CICS (common integrated circuit chip) system | |
| US10311032B2 (en) | Recording medium, log management method, and log management apparatus | |
| CN116702668A (en) | Regression testing method and device, electronic equipment and storage medium | |
| CN112540886B (en) | CPU load value detection method and device | |
| CN114237728A (en) | Control method and operating system of electronic equipment | |
| CN103455408B (en) | A kind of method and device of assessing file system input and output Treatment Stability | |
| CN113590300A (en) | Timed task execution method and device, storage medium and equipment | |
| CN112948214B (en) | Software overload warning method and device | |
| CN114036024A (en) | Application power consumption monitoring method and device, electronic equipment and storage medium | |
| CN112540885B (en) | CPU load value detection method and device based on user space | |
| CN119292760B (en) | Cloud computing system based on distributed multi-task request | |
| CN113064832B (en) | Application program energy consumption detection method and device |
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 |