preface

The testing team of Meituan-Dianping is responsible for the quality assurance of the App. In addition to the functional test of the App, it also focuses on the performance test of the App. Now people are increasingly dependent on mobile phones, and the power consumption of the above apps directly affects the standby time of mobile phones, which is a point of great concern to users. This paper mainly introduces the battery test in App performance test through a typical case, and summarizes some thoughts caused by this.

I. Case analysis

Short video, as a new content transmission carrier that has been verified by the market, can effectively increase the user’s stay time. Dianping App launched short video-related content from version 9.3, and added a short video module in each page. In our short video test, we found that playing a video in the video list page quickly made the phone hot. In response to this phenomenon, we immediately pulled the data and analyzed it. The test data showed that the video list page consumes 11 times more power than the details page. What’s going on here? There are many ways to test Battery potency in the industry, but here we use Battery Historian, Google’s Battery Historian for Android devices 5.0(API 21) and above.

1. Test object

Short video mainly includes three core pages: video list page, video details page, author page, this test object is these three pages.

2. Test process

Test model: Huawei Mate 9 Android 7.0 Battery capacity: 4000mAh Video Duration: 1min15s Test scenario design: In WiFi environment, open the App, play the video, and click “Replay” to play the video for 10 consecutive times. Comparison scenario: Note: The test does not charge during the test, and the test environment is the same each time

3. Test results

Here is a snapshot of the test results from Battery Historian:

Video list page

Video Details page

Summarize the test result data:

As can be seen from the test results, the power consumption of the short video list page is particularly high, which is 11 times that of the video details page.

4. Locate the fault

The video list page consumes too much power. It can be clearly seen from the test data that the CPU consumption of the video list page is much higher. In terms of player layout, the list page and author page only have more animated notes than the video details page. Below, the note in the lower left corner of the video circled in red.

If the difference in battery consumption is so large, it has something to do with the animation notes. To eliminate this problem, an APK with the animated notes removed was recompiled for testing. Test results:

From the test results, the CPU and power consumption obviously dropped a lot, so it was definitely caused by the animation notes. Turn on the GPU view update switch to view the drawing status of the three pages. When you open the video list page, you can see that each time the animated note moves, the entire page is constantly drawn. Here’s how the video list page is drawn:

It can be clearly seen from the driven graph that the page drawing is very abnormal. Every fluctuation of the animation note will cause the whole page to be drawn again. So, the reason for the problem is that there is a problem with the way the animated notes are implemented on the page. When the animated notes fluctuate, the whole page will be constantly redrawn together. The repeated drawing of the page will make the CPU usage of the App much higher than normal, resulting in high power consumption.

5. Verify after repair

After the cause was located, the developer targeted the fix. Animation note bar chart implementation, the previous design is composed of a number of variable single column View, a single column View rewrite onMeasure & OnDraw method, from the external bar View initialization of the height of a single column, and then automatically according to a function to change the height. Each time, Measure and corresponding Layout need to be called layer by layer, resulting in multiple layouts of the outer control, thus increasing the CPU usage. After the fix, use another way to implement, just rewrite the View OnDraw method, use Canvas to draw all the bar graph each time, use ValueAnimator to calculate the height of the bar graph, and no longer affect the Layout of the parent control. Here is the core code before and after the fix:





Fixed drawing area after animation note wave:

After the restoration, Battery Historian was used again to verify the results:

From the above test results, it can be seen that the power consumption of the video list page and author page has been significantly optimized. To sum up, the problem of short video power consumption is due to the wrong drawing method, which leads to high CPU usage, which leads to high power consumption. The problem of abnormal power consumption due to animation notes is solved perfectly here. It is obvious that high CPU load leads to high power consumption. However, I would like to further explore how power consumption is calculated in the rankings of power consumption of various apps in the mobile phone system. What other factors affect electricity consumption? With these questions in mind, let’s take a look at how the system calculates power consumption.

Two, power consumption calculation principle

According to the knowledge of physics, work = voltage * current * time, but in a mobile phone, the voltage value U normally does not change, so it can be ignored, only current and time can represent the electric quantity. Module power (mAh)= Module current (mA) x Module time (h). The module time is easy to understand, but how to obtain the module current? Will the module current be affected by the difference of mobile phones and hardware from different manufacturers? Take a look at the interface provided by the system: . / frameworks/base/core/Java/com/Android/internal/OS/PowerProfile. Java class provides the public double getAveragePower (String type) interface, The value of type can be constant values defined in PowerProfile, including POWER_CPU_IDLE (when the CPU is idle), POWER_CPU_ACTIVE (when the CPU is active), POWER_WIFI_ON (when WiFi is on), and other states. And you can see from the interface that the current value of each module is taken from the power_profile.xml file. Powerprofile.java is simply an interface to read power_profile.xml, which is the core file for storage system power consumption information. Power_profile. XML file storage path is/system/framework/framework – res. Apk. Take Nexus 6P as an example, the framework-res.apk file is obtained in this path. Use apktool to reverse parse framework-res.apk and obtain the power_profile. XML file in the mobile phone, as shown below:

<? The XML version = "1.0" encoding = "utf-8"? > <device name="Android"> <item name=" None ">0</item> <item name="screen.on">169.4278765</item> <item Name ="screen.full">79.09344216</item> <item name="bluetooth.active">25.2</item> <item name="bluetooth.on">1.7</item> <item name="wifi.on">21.21733311</item> <item name="wifi.active">98.04989804</item> <item Name ="wifi.scan">129.8951166</item> <item name="dsp.audio">26.5</item> <item name="dsp.video">242.0</item> <item Name = "GPS. On" > 5.661105191 < / item > < item name = "radio. Active" > 64.8918361 < / item > < item Name ="radio.scanning">19.13559783</item> <array name="radio.on"> <value>17.52231575</value> <value>5.902211798</value> <value>6.454893079</value> <value>6.771166916</value> <value>6.725541238</value> </array> <array name="cpu.speeds.cluster0"> <value>384000</value> <value>460800</value> <value>600000</value> <value>672000</value> <value>768000</value> <value>864000</value> <value>960000</value> <value>1248000</value> <value>1344000</value> <value>1478400</value> <value>1555200</value> </array> <array name="cpu.speeds.cluster1"> <value>384000</value> <value>480000</value> <value>633600</value> <value>768000</value> <value>864000</value> <value>960000</value> <value>1248000</value> <value>1344000</value> <value>1440000</value> <value>1536000</value> <value>1632000</value> <value>1728000</value> <value>1824000</value> <value>1958400</value> </array> <item name=" CPU. Idle ">0.144925583</item> <item name="cpu.awake">9.488210416</item> <array name="cpu.active. Cluster0 "> <value>202.17</value> <value>211.34</value> <value>224.22</value> <value>238.72</value> <value>251.89</value> <value>263.07</value> <value>276.33</value> <value>314.40</value> <value>328.12</value> <value>369.63</value> <value>391.05</value> </array> <array Name =" CPU.active. Cluster1 "> <value>354.95</value> <value>387.15</value> <value>442.86</value> <value>510.20</value> <value>582.65</value> <value>631.99</value> <value>812.02</value> <value>858.84</value> <value>943.23</value> <value>992.45</value> <value>1086.32</value> <value>1151.96</value> <value>1253.80</value> <value>1397.67</value> </array> <array name="cpu.clusters.cores"> <value>4</value> <value>4</value> </array> <item name="battery.capacity">3450</item> <array name="wifi.batchedscan"> <value>.0003</value> <value>.003</value> <value>.03</value> <value>.3</value> <value>3</value> </array> </device>Copy the code

The power_profile.xml file defines modules that consume power. As shown below:

The file defines the current value of each power consumption module of the mobile phone in different states. As mentioned just now, the electric quantity is only related to the current value and time, so the electric quantity consumed by App can be calculated by combining this file with the time consumed by the module. The electric quantity of App =∑ ELECTRIC quantity of App module. Key points, mobile phone system inside the battery ranking, also based on this principle. Understanding the principle is of great help to the test of ordinary power consumption in App. Because of the phone power_profile.xml file, you can clearly know which modules on the phone will consume power, and which modules will consume the most power in what state. When testing, you should focus on where these modules are called. Such as where the App uses WiFi, Bluetooth, GPS and so on. For example, in a recent comparative test of other apps, it was found that in some specific scenarios, the App scanned WiFi 50 times within 20 minutes of being placed in the foreground, which would greatly increase the power consumption of the App. Conversely, when a case reports abnormal power consumption of the App, these points can also be considered to help locate the problem.

Iii. Summary of electric quantity test methods

Some of the commonly used power measurement methods are listed above. Taking the advantages and disadvantages of each approach together, Battery Historian is currently being used before customising a Battery Historian. At present, there are many schemes for App power consumption test in the industry. It is far from enough to locate problems if only an overall power value is tested. Battery Historian allows you to view summary statistics since the device was last fully charged, as well as selecting an App to view the details. Therefore, QA’s test result feedback changed from “this version of App power consumption is high” to “this version of CPU consumption is high” and “this version of WiFi scanning is abnormal”, which can help locate the cause of the problem and solve the problem more quickly. Of course, in addition to test methods and test tools, test scenario design is also very important. If you browse irregularly in the App, even if there is a problem on the page, it is difficult to locate the problem of which module. Therefore, we should design specific scenes and compare some scenes to find out the differences.

Four,

This paper mainly introduces some basic methods and ideas used in App electricity test through a case. Although Battery Historian can solve the problem initially, it still has many shortcomings in practical application scenarios. At present, the cloud measurement platform of Meituan-Dianping has integrated the electric quantity test method. Through automatic operation, the electric quantity test file can be obtained and analyzed, which greatly improves the test efficiency. At present, before the release of each version, we will carry out special power test to ensure the user experience. In terms of electricity test, meituan-Dianping test team is still in continuous practice and optimization.

Author’s brief introduction

Qian Yun, client test and development engineer of Meituan-Dianping, joined Meituan-Dianping in 2015, mainly responsible for basic App functions and Android special testing.

Recruitment information

Dianping Platform Technology Department-Platform Quality Center, Base Shanghai, mainly responsible for quality assurance of dianping platform entrance and basic functions. Platforms include DIANping App, Dianping wechat mini program, PC site: www.dianping.com, M site: m.dianping.com; The main business covers account number, POI, evaluation, video, article, member community, Q&A, operation activities, search recommendation, communication link, operation activities and other basic services. We warmly look forward to your TALENTS in QA, development and algorithm joining the technology department of review platform. Contact email: wanxia.wang#dianping.com








If you answer “thinking questions”, find mistakes in the article, or have questions about the content, you can leave a message to us at the background of wechat public account (Meituan-Dianping technical team). Each week, we will select one “excellent responder” and give a nice small gift. Scan the code to pay attention to us!