电量监控和分析工具
Android 5.0开始 提供了电量获取和分析的方式
一、使用adb 命令 dumpsys batteryst 生成电池的使用情况
二、使用Battery Historian
分析耗电情况
当然上述方式是耗电相对测试,如果需要精确测量并且是测量政绩耗电,可以使用稳定的电源加上电流仪 进行精确测量,当然这种方式比较麻烦,而且条件比较苛刻,不适合应用开发人员使用。
下面给出 adb shell dumpsys batterystats
常用参数(由:adb shell dumpsys batterystats -h
命令生成)
Battery stats (batterystats) dump options:
[--checkin] [--proto] [--history] [--history-start] [--charged] [-c]
[--daily] [--reset] [--write] [--new-daily] [--read-daily] [-h] [<package.name>]
--checkin: generate output for a checkin report; will write (and clear) the
last old completed stats when they had been reset.
-c: write the current stats in checkin format.
--proto: write the current aggregate stats (without history) in proto format.
--history: show only history data.
--history-start <num>: show only history data starting at given time offset.
--history-create-events <num>: create <num> of battery history events.
--charged: only output data since last charged.
--daily: only output full daily data.
--reset: reset the stats, clearing all current data.
--write: force write current collected stats to disk.
--new-daily: immediately create and write new daily stats record.
--read-daily: read-load last written daily stats.
--settings: dump the settings key/values related to batterystats
--cpu: dump cpu stats for debugging purpose
<package.name>: optional name of package to filter output by.
-h: print this help text.
Battery stats (batterystats) commands:
enable|disable <option>
Enable or disable a running option. Option state is not saved across boots.
Options are:
full-history: include additional detailed events in battery history:
wake_lock_in, alarms and proc events
no-auto-reset: don't automatically reset stats when unplugged
pretend-screen-off: pretend the screen is off, even if screen state changes