如何分析和优化android应用的电池使用情况? [英] How to analyise battery usage of android application and optimize it?
问题描述
我想分析应用程序的电池使用情况,我指的是应用程序的各个部分,例如 广播接收器,侦听器,服务等.使用多少电池.我需要一个详细的列表,从列表中,我想优化电池使用量.
I would like to analyze battery usage of my application, I mean the parts of the app, such as broadcastreceivers, listeners, services, etc.., how much battery uses. I need a detailed list, and from the list, I would like to optimize battery usage.
方法与使用内存分析器( http ://android-developers.blogspot.hu/2011/03/memory-analysis-for-android.html ) 有什么工具吗?我使用了PlayStore的一些电池跟踪应用程序,但该应用程序的全球电池使用量还不够.
Method would be similar than using Memory Analyzer (http://android-developers.blogspot.hu/2011/03/memory-analysis-for-android.html) Is there any tool for it? I used some battery tracking app from PlayStore, but global battery usage of application is not enough.
推荐答案
这个问题已经很老了,但是我想仍然很重要.
This question is quite old, but, i guess is still relevant.
电池消耗是一个非常大的问题,到目前为止还没有解决,因此只有辛苦"的工作和学习才能为您提供帮助.没有公共的API可以使您对电池有所帮助,也没有付费的" SDK可以使您对电池进行分析,但是,您可以通过运行
Battery consumption is a really big issue, thats left unresolved so far, so that only 'hard' work and learning might help you. There's no public API which gives you a helpful look of the battery, and no 'paying' sdk which gives you analytics on the battery, BUT, you can learn a lot from running a battery stats command from the ADB.
从终端运行此命令:adb shell dumpsys batterystats > results.txt
results.txt
文件中没什么可观察的:
Few things to observe in the results.txt
file :
-
结果是从您从充电器上拔下手机的时间开始计算的(如果达到100%)
The results are taken from the beginning of the time you unplugged your phone from the charger(if it reached 100%)
如果已充满电(或几乎充满电),则电池电量统计信息将被清除,因此,如果您遇到问题,并且无法处理这些统计数据,请在设备可以充电之前不要对设备充满电从计算机运行此命令.
If you're fully (or almost) charged, the battery stats will be erased, so if you have an issue, and you can't process the stats, don't fully charge your device until you can run this command from a computer.
Wifi锁-您还可以检查wifi是否使设备保持运行状态,并且如果看到这些线路且定时较高,则它应该可疑.
Wifi Lock - you can also check if the wifi keeps your device running, and if you see these lines, with high timing, it should appear suspicious.
Wifi Running: 3h 23m (87.0%)
Full Wifi Lock: 2h 3m (91.0%)
Wifi Scan: 1h 54m (79.0%) 44x
Wifi Running: 3h 23m (87.0%)
Full Wifi Lock: 2h 3m (91.0%)
Wifi Scan: 1h 54m (79.0%) 44x
检查您的CPU时间:例如:
Check your CPU time : for example :
Proc com.android.phone:
CPU: 3h 34m 12s 910ms usr + 7s 250ms krn ; 0ms fg
Proc com.android.phone:
CPU: 3h 34m 12s 910ms usr + 7s 250ms krn ; 0ms fg
这意味着电话应用程序工作了3个多小时,这是很多事情(除非用户一直在通话)
This means, that the phone app worked for more than 3 hours, which is a lot(unless the user was talking all this time)
查看您的蓝牙
1002:
Wake lock bluedroid_timer: 3m 29s 892ms partial (158 times) realtime
Foreground for: 8h 1m 2s 834ms
Active for: 8h 1m 3s 546ms
Total cpu time: u=48m 38s 350ms s=29s 752ms p=204mAh
Proc com.android.bluetooth:
CPU: 23m 25s 230ms usr + 22s 520ms krn ; 0ms fg
211 starts
Proc *wakelock*:
CPU: 0ms usr + 2ms krn ; 0ms fg
Apk com.android.bluetooth:
Service com.android.bluetooth.gatt.GattService:
Created for: 1h 13m 52s 667ms upt
1002:
Wake lock bluedroid_timer: 3m 29s 892ms partial (158 times) realtime
Foreground for: 8h 1m 2s 834ms
Active for: 8h 1m 3s 546ms
Total cpu time: u=48m 38s 350ms s=29s 752ms p=204mAh
Proc com.android.bluetooth:
CPU: 23m 25s 230ms usr + 22s 520ms krn ; 0ms fg
211 starts
Proc *wakelock*:
CPU: 0ms usr + 2ms krn ; 0ms fg
Apk com.android.bluetooth:
Service com.android.bluetooth.gatt.GattService:
Created for: 1h 13m 52s 667ms upt
8小时是很多蓝牙的时间.
您的服务运行了多少时间?
How much time did your services run for ?
Service com.google.location.nearby.direct.service.NearbyDirectService:
Created for: 17m 50s 232ms uptime
Starts: 212, launches: 212
Service com.google.location.nearby.direct.service.NearbyDirectService:
Created for: 17m 50s 232ms uptime
Starts: 212, launches: 212
在此文件的结尾,您可以摘要查看设备上正在运行的所有应用程序.它非常不错,可让您了解每个apk消耗多少时间/cpu/wifi/网络/服务. 例如
In the end of this file, you have a summary of all the applications running on your device. Its pretty nice, and gives you an idea of how much time/cpu/wifi/network/service each apk consumed. For example,
u0a1091:
Mobile network: 14.96KB received, 17.10KB sent (packets 120 received, 183 sent)
Mobile radio active: 4m 30s 136ms (10.5%) 18x @ 892 mspp
Active for: 8h 1m 3s 546ms
Total cpu time: u=520ms s=210ms p=0.0653mAh
Proc org.telegram.messenger:
CPU: 670ms usr + 260ms krn ; 0ms fg
u0a1091:
Mobile network: 14.96KB received, 17.10KB sent (packets 120 received, 183 sent)
Mobile radio active: 4m 30s 136ms (10.5%) 18x @ 892 mspp
Active for: 8h 1m 3s 546ms
Total cpu time: u=520ms s=210ms p=0.0653mAh
Proc org.telegram.messenger:
CPU: 670ms usr + 260ms krn ; 0ms fg
此文件中还有很多其他选项,需要花一些时间才能弄清楚,这是我从研究中学到的.
There are a lot more options to go through in this file, and it takes a while to figure out more, this is what i've learned from my researches.
这篇关于如何分析和优化android应用的电池使用情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!