Skip to content Skip to sidebar Skip to footer

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 detail

Solution 1:

This question is quite old, but, i guess is still relevant.

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.

Run this command from your terminal : adb shell dumpsys batterystats > results.txt

Few things to observe in the results.txt file :

  1. The results are taken from the beginning of the time you unplugged your phone from the charger(if it reached 100%)

  2. 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.

  3. We found that using wakelock is a huge battery consumption. You can check on the results how much time an application has a wakelock. So, for example, if i see this line : Wake lock *sync*/com.android.contacts/com.whatsapp/WhatsApp: 128ms partial (4 times) realtime i can understand from it that WhatsApp is running a wakelock for 128 milliseconds, which is ok, however, if the running time was hours, this will be bad, and will kill my battery.
  4. 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

  5. Check your CPU time : for example :

    Proc com.android.phone: CPU: 3h 34m 12s 910ms usr + 7s 250ms krn ; 0ms fg

    This means, that the phone app worked for more than 3 hours, which is a lot(unless the user was talking all this time)

  6. Check out your bluetooth

    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 hours is A LOT for bluetooth.

  7. 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

  8. 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

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.

Solution 2:

Have you tried ATT ARO? It is a pretty neat tool that gives you some more visual diagnostics on your app.

enter image description here

Post a Comment for "How To Analyise Battery Usage Of Android Application And Optimize It?"