android 应用耗电量测试工具,Android-APP-CPU 耗电测试的例子

说明:

对比测试 APP(v3.2.2) 弹幕硬解和软解的耗电量。

主要使用 CPU ,所以只考虑 CPU 的耗电。

因为耗时较长,用 UIautomator 自动修改设置和播放。

需要 Root。

数据来源:

/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state

记录了 CPU 从开机到读取文件时,在各个频率下的运行时间,单位:10 mS

说明

PowerProfile

获取 CPU 在各个频率下运行时的平均电流,单位 mA。

说明

第三方 ROM 一般是错的。

/proc/[pid]/stat

进程已运行时间 utime + stime + cutime + cstime,pid 是进程号 (adb shell ps)。

说明

ActivityManager

通过 PackageName 获得 APP 下的进程号。

说明

测试场景:

准备工作:离线下载好待测视频,开飞行模式,清理后台。

1、记录 APP 已经运行的时间 targetAppTimeBefor ,所有 APP 已经运行时间 totalTimeBefor ,CPU 在各个频率的运行时间 timeInStateBefor[1] 、timeInStateBefor[2] 、……

2、播放有弹幕的视频。

3、结束播放,记录 APP 已经运行的时间 targetAppTimeAfter ,所有 APP 已经运行时间 totalTimeAfter,CPU 在各个频率的运行时间 timeInStateAfter[1] 、 timeInStateAfter[2] 、……

4、读取 CPU 在各个频率下运行时的平均电流 powerUsedOnDiffSpeeds[1] 、powerUsedOnDiffSpeeds[2] 、……

计算公式:

目标 APP 占总 CPU 时间的比例:

ratio = (targetAppTimeAfter - targetAppTimeBefor) / (totalTimeAfter - totalTimeBefor)

CPU 总耗电:

totalPower = ((timeInStateAfter[1] - timeInStateBefor[1]) / 100 * powerUsedOnDiffSpeeds[1]) + ((timeInStateAfter[2] - timeInStateBefor[2]) / 100 * powerUsedOnDiffSpeeds[2]) + ……

目标 APP 的 CPU 耗电(单位:mAh):

appCpuTotalPower = cpuTotalPower * ratio / 3600

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值