Performance Optimization 05-Commonly used power saving optimization techniques

Performance optimization 05-power saving optimization

1. Electricity measurement

The power consumption of each hardware module of a mobile phone is different. Some modules consume a lot of power, such as mobile cellular network and GPS, while some modules consume much less power.

Power test is a test method to test the power consumption of mobile devices. The average current is generally used to measure the rate of power consumption. The lower the average current, the longer the device has been used. But there is no unified standard for how much the average current is to indicate that it does not consume power. Divided into hardware test and software test:

  1. Hardware test: Use hardware equipment to test the current of the device under test, and count the average current value over a period of time (using a certain function module).
  2. Software testing: Use system tools to export analysis reports, and then use specific analysis tools (such as BatteryHistorian) to analyze power consumption.

Second, Battery Historic

BatteryHistorian is Google's open source battery historical data analysis tool. github address: https://github.com/google/battery-historian . Steps for usage:

1. Install BatteryHistorian

See official description.

You can also use the web version of BatteryHistorian: http://47.52.175.85:9999/ to analyze. This is a platform built by a friend and needs to be over the wall to use.

2. Export analysis data

  1. reset:adb shell dumpsys batterystats --reset
  2. Get complete wakelock information:adb shell dumpsys batterystats --enable full-wake-history
  3. Get report: used above Android7.0, used adb bugreport bugreport.zipbelow 7.0adb bugreport > bugreport.txt

3. Analyze data

First, open the exported report with BatteryHistorian.

Then, check the trend of the overall power, and analyze which hardware is turned on when the power is rapidly consumed;

Finally, select the process and analyze its power trend separately.

3. Optimization suggestions

Power saving optimization

Power saving optimization can start from the following aspects:

  1. Turn off functions that are no longer needed in time, such as GPS, network request timeout settings;
  2. Perform certain tasks while using wifi/charging;
  3. Optimize background tasks. Background tasks need to follow 3 principles:
    1. Reduce: we need to reduce background processing;
    2. Delay: execute when the device is charging;
    3. Merge: Combine multiple processing tasks together.
  4. Replace WakeLock with FLAG. The usage method is, in Activity: getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); Add this attribute in the layout of Activity: android:keepScreenOn=”true”.
  5. Use Jobscheduler/Alarm to replace WakeLock according to the situation;

Doze

Doze is a power saving strategy for Android 6.0. If the user leaves the phone uncharged and sits for a while and the save screen goes off, the device goes into Doze mode. In DOZE mode, the phone system will try to save power by restricting APP access to the network and intensive CPU services. At the same time it also blocks the network the app is accessing and delays the work, sync and standard alarm of those apps.

App Standby

App Standby is a power saving policy for applications, which allows the system to decide whether an APP is idle when the user is not actively using it. The system makes this decision when the user does not trigger the APP for a certain period of time, and when the user plugs in the device for charging, the system is released from the standby state, allowing them to freely access the network and execute any suspended jobs and syncs. . If the device is idle for a long time, the system allows the idle APP to access the network once a day.

Previous: Performance Optimization 04-Image Optimization

Next: Performance Optimization 06-Multi-dex Encryption

Guess you like

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