How to conduct power consumption testing to be more effective

What are the pros and cons of applying power testing methods?

What kind of test environment is more favorable for application power consumption test?

Which method does Baidu use to reduce power consumption?

Wang Zhengyi

Senior Test Engineer of Baidu Search Company

Expert in the field of mobile terminal testing of Baidu Search Company

Now in charge of performance testing and AI testing of Baidu Maps

1. What is application power consumption

For the application, that is, the power consumption (power consumption) when the application is working, and for testing the power consumption of the application, what is actually tested is the power consumption of the application when it is working.

What factors affect application power consumption?

External factors: This part cannot be changed by the application. There are specific problems in the following aspects:

a. The manufacturing process of the hardware, the power of the hardware, and the specific design factors.

b. System version, according to different Android system versions, they have different characteristics, and there will be different influencing factors in terms of power consumption.

c. The strength of the wireless signal of the phone itself.

d. Phone working status. Such as displacement, altitude change and other factors.

e. Changes in ambient temperature will also affect the power consumption of the application when it is working.

For the power consumption test of our application, we need to fix the external influencing factors as much as possible to ensure that we can make the test data comparable between the two tests before and after or multiple tests.

Internal factors: This part is a number of factors that our application can control and are related to the application:

a. The computational intensity of the application. In some cases, applications process large amounts of data that can increase the intensity of the application's CPU usage. The performance is that the application CPU usage is high. It is also possible that the application has a large number of image renderings, such as games or some applications related to images, which will have a large image calculation intensity, which will also increase the value of GPU occupancy, which is also one of the internal factors. one.

b. Network transmission requirements, the time to transmit data, and the frequency of data transmission will affect the power consumption of the application.

c. Use of the device in the mobile phone. For example, sensors, GPS, microphone cameras can affect the power consumption of the application.

d. The application system sleeps or wakes up. These factors also affect the power consumption of the application.

For us, testing the power consumption of an application is actually to see the relationship between the internal causes of the application and the power consumption of the application. We can analyze from the test results, which part of the internal cause causes what kind of power consumption problem, so as to Find a way to solve it.

2. Several test methods for application power consumption

1. System power difference method

In fact, the meaning is very simple, it is to measure the power consumption of the application according to the change of the percentage of our system power before and after the application works.

Before the test, look at the current battery percentage of the system, and test it for a period of time, which may be manual, automatic, or other methods, and then look at the power of the system. The difference is the power consumption during this period.

Advantages: very intuitive and very easy to implement;

Disadvantage: It can only reflect the overall power consumption of the system, and cannot be accurate to how much power an application consumes.

The resulting data is also relatively rough, which is reflected in two aspects: one is because most systems are integer numbers from 1% to 100%, 1, 2, 3, 4, 5, 6 to 100;

The other one is that everyone may encounter such a situation. It is clear that the mobile phone still has 20% of the battery. After taking it out and using it for less than a few minutes, the screen suddenly goes black, no power, and it shuts down. This is because the power of the system has dropped. In many mobile phones is not linear. Just like the picture on the right side of the figure below, it is a discharge curve of a lithium battery. You can see that the first part is relatively gentle. From 100% to 20%, for example, the percentage of system power and the remaining power are proportional. But to the far right, you can see that the curve is going down sharply, that is to say, the percentage change of the system power will become faster in the last section. So this is actually a rough result for us to use it for power consumption testing.

1. Electricity recording method

In fact, a special current meter is used to record the instantaneous current change of our mobile phone. As shown on the right side of the figure below: This is a graph of the current measured by a current meter for a certain period of time, which may look similar to the CPU occupancy diagram, but is actually similar in principle, that is, we can use such a current change to reflect Figure out the trend of power consumption, and then calculate how much power the mobile phone consumes during this period of time through some calculation methods, and its unit is mAh.

advantage:

This method is much more accurate than the system power difference method.

shortcoming:

It can only reflect the overall power consumption of the system, and cannot be accurate to a single application.

The cost of purchasing, using and maintaining special equipment is relatively high. Baidu has also used current meter equipment before, including Baidu's MTC, and also uses such a current meter equipment to provide you with power consumption test

Use is limited by the environment. For example, for Baidu Maps, during the testing process, it is very likely that we need to do some actual road tests in an actual and real environment. We usually drive a car and use a mobile phone for testing, because the current meter is too It is bulky, inconvenient to put in the car, and inconvenient to find a power source.

3. Calculate the power consumption method

Every Android phone will have an XML file like the one on the right in the figure below. This file is compiled in the ROM when the ROM is compiled. It records the power consumption of each device in the phone under a certain state. amount, such as how much electricity is consumed per second. We can use the interface provided by the system to obtain information about the occupation of system equipment by an application in a certain period of time, such as the duration and frequency.

The duration is a key piece of information. By multiplying the duration by the unit power consumption value recorded in the XML on the right, the estimated power consumption value can be obtained.

advantage:

It is convenient to calculate the power consumption of an application.

shortcoming:

There is no control over the impact of the test environment. For example, the geographic location of the mobile phone, its altitude, the movement of the mobile phone, and the temperature of the surrounding environment will all affect the power consumption speed of the device.

If you only use the values ​​recorded in XML to perform calculations, the results obtained are definitely very inaccurate.

4. Equipment occupancy record method

This method is similar to the third method, but this method only records and compares the frequency, frequency and duration occupied by the design, and does not perform calculations. The specific method will be introduced below.

advantage:

Single application power consumption can be measured.

Since this data has not been calculated with a fixed value, it is relatively reliable.

shortcoming:

There are too many data items and it is not intuitive enough. On the one hand, there are many devices that consume power in the mobile phone, and each item needs to be compared in terms of frequency and duration, which will be more complicated. It may be a set of numbers, which is not complicated and not intuitive enough. After the introduction of these four methods, you can also see that none of the four methods we currently use for testing power consumption is perfect. This is also such a realistic problem that we are facing now. The method uses only one method to test the power consumption of the application. Therefore, in the actual use process, we can only say that according to our needs and the needs of the test, we should choose such a power consumption test method that is more suitable for our current test.

3. Interpretation of power consumption standards

At present, the industry's identification of power consumption standards is different. Let's analyze the content of the Android Green Alliance power consumption standards.

1. Test environment

The test environment is a very important factor that affects the power consumption of the application. For our application power consumption test, the external factors should be fixed as much as possible, so that the test data before and after can be sufficiently comparable.

We define a standard environment in the standard :

Use a Nexus series phone . This consideration is that usually some pre-installed applications in Nexus series mobile phones will not be affected by the interrelated startup or wake-up of the applications we tested, and the environment is relatively pure. And generally speaking, the Nexus series of mobile phones have a relatively good continuity, we can find the Nexus series of mobile phones in the future, and its update follow-up of the system version is also relatively timely, we can usually get the latest the system version for testing;

When not charging, the battery starts at 100% charge . This is also related to the linear curve of system power consumption. Remember the power consumption curve graph just now? The first part is relatively flat, so we usually choose the first part to start testing;

The network chooses Wi-Fi or 4G, and the signal strength is the strongest . In order to ensure that the data we test is not affected by network fluctuations, so that our test is relatively smooth, and the data obtained will not fluctuate too much;

The ambient temperature is around 25 degrees ;

General equipment.

Considering that power consumption is very related to the characteristics of hardware devices, Android's fragmentation is very serious and the update is fast, so in the formulation of the standard, we adopted the "pan-device" method - not describing a certain application in the standard. Power consumption measurement and judgment criteria on a specific mobile phone. That is to say, although we use the Nexus series of mobile phones to test, our standard does not describe the power consumption measurement and judgment standard on the Nexus mobile phone, but to measure the frequency and duration of the device on the mobile phone by the application. Such a power consumption of an application, such as measuring how much the application's CPU occupies, how many times the screen is occupied, how many times the GPS is occupied, how many times the network is used to transmit data, and how long is the transmission time... Use such frequencies and The duration is used to measure and judge the power consumption of the application.

In fact, it is more consistent with the equipment occupancy recording method in the test method. Although the data is more complicated, the numerical value is relatively reliable, and it is suitable for formulation and application as a standard. From the test data, the final result is to test the frequency and duration of a certain application on a certain mobile phone. The data has certain guiding significance for the optimization and improvement of the power consumption problem. So this is also an important reason why we adopt this method in the power consumption standard.

2. Demand

The standard divides the usage scenarios of application testing, and divides them into four categories according to the application's demand for devices in the mobile phone: high demand, medium demand, low demand and no demand.

In the current standard, we only have strict requirements for no-demand scenarios , and categorize it as an exception for high-demand, medium-demand, and low-demand scenarios. Take GPS as an example. In a scenario where there is no need for GPS, we require that all applications should not use GPS. For example, there is no reason to use GPS when playing videos, so we require that applications are not allowed to use GPS when there is no need for GPS. GPS, there will be some exceptions. For example, there is a strong demand for GPS in the process of navigation, so in our testing process, we list scenarios such as navigation as an exception for GPS devices.

Therefore, you can see that we will list the usage scenarios of some common applications as exceptions, and strictly limit some scenarios that are not required.

3. Front and back

Explain our current standard, which only limits the power consumption of applications in the background. We did some user research and found that users are actually more concerned about whether an application consumes power when it is in the background. Therefore, in the foreground, our current standards do not make mandatory specifications, but our current "Android Green Alliance" power consumption standards strictly regulate the application in the background, including regulating the use of this application on mobile phone power devices The frequency and duration of use also regulate the use of WakeLock and Alarm, and we also implement the background power consumption of the application in the standard environment as a reference standard.

4. Hardware equipment

We divided it into seven categories: processor, screen, wireless network, audio device, camera, position sensor and motion sensor, and made different measurement standards for these devices.

For example, the screen, when the application is in the background, we strictly prohibit the application to prevent the screen from being dimmed or turned off; we will also limit the number of times the application scans the wireless network in the background, including audio devices, cameras, location sensors, motion sensors, we will Strictly restrict apps from using these devices when they are in the background.

In addition to the exception scenarios we just mentioned, you can refer to the power consumption standard documentation for specific exception scenarios.

Fourth, the use of Battery Historian

The Battery Historian tool is used by many companies in the industry, including Baidu. This tool is actually the fourth of the four test methods we mentioned just now. This tool is an open source tool made by Android developers to parse diagnostic files and analyze power consumption. Everyone visit the link:

https://github.com/google/battery-historian, you can see the tool source code.

This tool actually allows the Android system to produce a bugreport file through some commands of the Android phone, and then parse it to generate the charts and data occupied by each application and each hardware device.

You can see an example on the right side of the figure below. The ordinate of the list is the device, and the abscissa is the timeline. Each colored point represents the occupancy of the device at a certain time . As you can see, some devices will be a dense point, and some devices will be a line. A line means that the device is continuously occupied, and a dot means that the device is intermittently occupied. From this, you can see the system. occupancy of each device.

There are several steps on how to use it:

Before starting the test, connect the mobile phone to the computer, and use such an adb shell command to clear and reset the battery history information, so that the data we obtain is limited to the data of this test, which is more convenient;

There is no need to connect to the computer during the testing process, and then the test can be carried out. It can be taken out for testing or tested in various houses for simulated testing, automated testing, etc.;

After the test is over, we go to connect the mobile phone to the computer, and then export the test information through a command such as adb bugreport. There are two commands above. The above command is the command supported by Android 7.0 and above, and the following is the command exported by Android 6.0 and below. The information exported by the two commands is actually the same. After exporting the power consumption information, we need to run Battery Historian. There are two methods:

(1) If we run it by ourselves, we need to install a docker, then run the Battery Historian, open a web page after running, and upload a file like the Battery Historian we just exported on the local web page. After uploading, it can be parsed out what we have just seen;

(2) If it is inconvenient to run docker, or it is inconvenient to install docker to run Battery Historian, you can do some searches on the Internet. Some websites will provide Battery Historian functions. You only need to upload your Battery Historian files. , its website will help you parse the contents of the file, which is also very convenient.

You can search for Battery Historian on Baidu, including some of its usage methods and its parsing capabilities, which can be found on the Internet. After uploading, we can see some data - including the timeline just introduced, the chart in the upper left corner, and the system statistics on the right. That is, at the system level, how many times the device of the mobile phone is occupied, how much time it takes, how much the CPU consumes, and how much data Wi-Fi transmits will all be included in this.

In the column on the left, we filter out the application, and we can see the following interface, which is the data analysis for an APP: including how much CPU, how many sensors, how long each time the APP occupies, and how much time it takes to use wireless How much data is transmitted by the network and how many times it is transmitted, such data has some statistics in the chart. You can carry out some tests with your own mobile phone or test machine and analyze it. This data is very detailed.

The above methods are suitable for different scenarios, and specific problems still need to be analyzed in detail.

The article is reproduced from WeChat public account: Android Green Alliance

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325211117&siteId=291194637