APP special test power consumption test

This article has 5266 words and takes about 7 minutes to read

Hi, everyone. As the application market continues to introduce new ones, users pay more attention to power issues when using APPs. If your app accidentally appears in the Top 10 power consumption list, the probability of users uninstalling it will be very high. For APP耗电量the test, I will share it with you here.

one

Power Consumption Test Analysis

Compared with the PC side, the battery power of mobile devices is very limited, and it is particularly important to maintain a long-lasting battery life. Many features of Android consume more power (such as screen, GPS, sensor, wake-up mechanism, CPU, network connection, etc.), we must carefully check the power usage of the APP, so as not to cause the user's mobile phone to consume power and heat up, causing bad experience.

1

Power consumption scene

The main power consumption scenarios are:

  • cpu: complex operation logic, infinite loop, etc. will directly lead to high CPU load, which will lead to power consumption;
  • wakelock: As long as an application gets the wakelock lock, the system cannot enter the sleep state. Frequent wakelocks or applied wakelocks are not released, which will lead to power consumption;
  • wifiscan and wifilock: wifiscan and wifilock will also cause the wifi module of the mobile phone to be activated. Frequent wifiscan or wifilock will not be released, which will cause power consumption;
  • sensor: After the sensor is turned on, the system will continue to monitor the data changes in the peripheral environment of the device. If it is not turned off in time after use, it will cause power consumption;
  • network: A large amount of data transmission, or long-term mobile network data transmission causes the radio to be active for a long time, which will cause power consumption;
  • GPS: GPS is also a sensor, if it is not turned off in time during positioning, it will consume power;

At the business level, the most core basic modules for users:

  • For the newly added basic logic, if the entry is obvious and the access is potentially large, the performance must be guaranteed;
  • The activity needs, because of the new logic of the activity, there is a large number of user visits, and we need to try our best to improve the user experience;
  • Modules with bad feedback experience.

2

Power consumption test

When obtaining the test results, we should pay attention to the validity of the data, avoid data errors, and let the data explain the problem more effectively. The following two methods are provided to improve the validity of the obtained data.

  • Horizontal comparison method: the test is divided into two steps, the first step is to measure the power consumption of mobile phone hardware operation; the second step is to test the comprehensive power consumption of mobile phone hardware and software operation. Finally, compare the power consumption of the two times to get the power consumption of the software;
  • Longitudinal comparison method: carry out two mobile phones at the same time, one of which does not run the software, and the other runs the software; obtain the power consumption of the two mobile phones respectively, compare the difference in power consumption between the two mobile phones, and obtain the power consumption of the software size.

These two methods have certain differences in testing. Many applications require the support of mobile networks, and the network signals received by mobile phones will change with time.

  • The error of the first method mainly comes from the change of the working state of the mobile phone under different base station networks.
  • The difference in the second method is reflected in the fact that the power consumption of the hardware of the two mobile phones may be different, so it is necessary to use the same model and batch of mobile phones as much as possible.

two

IOS power consumption test

1

conventional test method

(1) Test method

①Select test scenarios and duration;

②The mobile phone is charged and discharged, and the power of the mobile phone reaches the preset value. Before the start of each scene, the power is kept at this level, and the mobile phone is at room temperature;

③ Mobile phone system settings, generally focus on Bluetooth, positioning, notification messages, volume, background applications, etc., all set to the predetermined state;

④Record the remaining power, start the test, and record the remaining power after the test is completed. The power difference is the power consumption within this period.

(2) Accuracy of test results

With this test method, obvious power consumption problems can be found, such as a 10% power loss in one test, but some less obvious problems cannot be found with this method. In addition, this test method has no specific data and is not practical.

2

Energy Impact

(1) Test method

During the development process, run the debug mode to view Energy Impact directly in Xcode. There are 3 areas on the power dashboard, if you often go to the red area, you should review your code. The histogram below will tell you the components of power consumption: CPU, Network, Location, GPU , where Overhead means power consumption not caused by App. If there is a problem, you can further open the Time Profile, Network Profile, and Location Profile through the quick entry to further troubleshoot the problem in detail.

(2) Accuracy of test results

It is very simple to use Energy Impact to measure power, but the disadvantage is that it must be connected to a real device, which is only suitable for developers; and it can only give qualitative information on power consumption, without quantitative display.

3

Sysdiagnose power consumption test

Sysdiagnose is Apple's log system. Sysdiagnose is huge and records all the running conditions of the battery, third-party APP, various system functions and applications. Through Sysdiagnose, we can obtain detailed data on power consumption, voltage, current, temperature, and even power consumption of the system's CPU, GPU, etc. And not only our own app, but also other apps installed in the mobile phone can also obtain data, which greatly facilitates us to make detailed comparison test data.

(1) Test method

①Sysdiagnose needs a developer account, and download the certificate BatteryLife.mobileconfig from the Apple developer official website Profiles and Logs.

传送门:https://developer.apple.com/bug-reporting/profiles-and-logs/

copy

As follows:

②Send the certificate to the mobile phone (such as airdrop method), install the certificate on the mobile phone, after installation, the mobile phone can obtain data without jailbreaking.

③ Execute the test on the mobile phone

Before the test, charge the mobile phone to more than 80%. After the charging is complete, unplug the charging cable, and wait for 10 minutes without any operation before starting to execute the scene. During the test, the screen brightness should be the lowest, Bluetooth should be turned off, push notifications should be turned off, and positioning should be turned on ( Turn it on in System Settings-Privacy), the volume is the lowest, the personal hotspot is turned off, and all background processes are turned off;

Enter the APP and test according to the test scenario designed by the test case;

⚠️Notes:

  • If the power test is a comparative test, the initial power of the two versions should be kept as consistent as possible;
  • When each scene starts and ends, record the start and end time, and the interval between each scene is 1 minute (currently, a scene operation is 10 minutes);
  • Do not charge halfway during the test;
  • Synchronize data and export power data files

After operating all the scenarios in the previous step, after the test is completed, the mobile phone stands still for about half an hour (because there will be a delay in database writing), and then the mobile phone is connected to the computer to synchronize the data;

After the synchronization is complete, export the required power log and import the log address as follows:

Mac:

Open Finder, press CMD+SHIFT+G, and enter:

Win:

C:\Users[Your_User_Name]\AppData\Roaming\Apple Computer\Logs\CrashReporter\MobileDevice\[Your_Device_Name]\

copy

④ Find the corresponding power consumption data in the folder of the specified path. The power consumption data generally starts with powerlog and ends with .PLSQL or .PLSQL.gz, as shown in the figure below:

⑤ Use DB Browser for SQLite to view data, open the powerlog database, switch to the "Browse Data" tab, you can see that there are many tables in this database, as shown below:

⑥ Analysis of test results

Among these tables, the names and functions of several important tables related to electricity are as follows:

The most important table is the PLBatteryAgent_EventBackward_Battery power information of the whole machine, which is collected every 20s. When other apps are closed, it can be approximately regarded as the power consumption of the measured app. The contents of the table are as follows:

There is a timestamp at the top of each row in the PLBtteryAgent_EventBackward_Battery table, which is used to record the time point of each row of battery status records (in UnixTime format, which can be converted by a time conversion tool to obtain the specific time), so it can be performed according to the recorded timestamp Extraction of power consumption data, the table records the remaining power, voltage, and current of the mobile phone corresponding to the time stamp (positive numbers are charging, negative numbers are power consumption), and there are temperature data in the table, which can reflect the temperature changes of the mobile phone during the test .

The second column in the table is the timestamp timestamp, and the fourth column Rawlevel is the power value at the corresponding time point. When counting power, the test can be calculated by finding the difference between the corresponding Rawlevel at the specific time points at the beginning and end of the test scene. Accurate power consumption data of the scene.

three

Android power consumption test

1

Battery Historian power consumption

(1) Battery-historian service construction

①Clone the installation package

git clone https://github.com/google/battery-historian.git

copy

②Download the code and dependencies of battery-historian

③ Modify the parameters of the setup.go file

The value is changed to:

Because the version is different, the compilation will fail, so upgrade to the stable version.

④ Switch to the directory where setup.go is located and compile

⑤Start the battery-historian service

go run cmd/battery-historian/battery-historian.go

copy

As follows:

⑥Verify whether the installation is successful

http://localhost:9999/, if it appears as follows, then ok!

(2) Collection of power consumption data

① Clean up power consumption data

②Run test cases/manual operation

Use monkey or appium to operate the Android application you want to be tested, preferably continuous testing.

③Collect data

Commands used by Android 7.0 and above:

Commands used on Android 6.0 or below:

As follows:

(3) Upload test data and analyze test results

The meaning of each parameter:

  • battery_level: battery level, you can see the change of battery level
  • plugged: charging status, this column shows whether charging is performed, and the charging time range.
  • Screen: Whether the screen is lit, which can take into account the power usage information in the sleep state and the lit state.
  • Top: This column shows which app is at the top at the current moment, which is the app currently running on the mobile phone. It is used to judge the impact of an app on the power of the mobile phone, so that the power consumption information of the app can also be judged. This column records the startup time of the application at a certain moment, and the running time, which is very helpful for us to compare the impact of different applications on performance.
  • wake_lock*: wake_lock This attribute records the working time of the wake_lock module. Is there a time to stop and wait.
  • running: The state of the interface, mainly to judge whether it is in the state of idle. It is used to judge the power consumption in the no-operation state.
  • wake_lock_in: wake_lock has different components. This place records which components start working at a certain moment and when they work.
  • Gps: Whether GPS is enabled.
  • phone_in_call: Whether to make a call.
  • Sync: Whether to synchronize with the background. You can hover the mouse over an item. You can see when sync is started and how long it lasts. The battery capacity will not display the specific power consumed by a single behavior. Here it can only display the frequency and duration of using the battery. You can see the remaining power by time period to know how much power is consumed.
  • Job: Background work, such as the running of the service service.
  • data_conn: The change of the data connection method, the above edge is to explain the gprs method used to connect to the network. This data shows whether the mobile phone uses 2g, 3g, 4g or wifi for data exchange. This column shows the impact of different connection methods on power usage.
  • Status: Battery status information, including charging, discharging, not charging, fully charged, unknown, etc. This column records the change information of the battery status.
  • phone_signal_strength: The change in phone signal strength. This column records the strength and weakness of the mobile phone signal, and then judges the impact of the mobile phone signal on the power.
  • Health: Information about the health status of the battery, which to some extent reflects how long the battery has been used. This column records when the battery status changes, and the battery status in the above figure is always in the good state.
  • Plug: Charging method, usb or socket, and display connection time. This column shows how different charging methods affect power usage.

(4) Test result characteristics

Advantages: Intuitive results, detailed power consumption data;

Disadvantages: does not support android system below 5.0;

2

Power consumption test

①Restart adb;

②Use adb devices to check whether the mobile phone is connected to the computer;

③Reset battery data

④ Unplug the data cable and start the test;

⑤ After the test is completed, use the data cable to connect to the computer;

⑥ Collect power data;

⑦ Find the corresponding UID according to the package name of the test;

⑧Query power consumption according to uid;

that's all

That‘s all

More series of articles

stay tuned

Guess you like

Origin blog.csdn.net/zh6526157/article/details/132223983