Posted by: admin September 19, 2023 No Comments

Why is it important to measure Battery and CPU utilization of your mobile app?

Everyday many applications are launched and everyone is using applications like shopping, games, utilities. People are using apps that are not compatible with their devices so it is important to measure the battery utilization of the application while testing it. When you get worried about more battery consumption, it’s fair to find out what is causing the drainage of the battery. So we always have to test the battery consumption when we develop the application.

CPU consumption of apps also plays a vital role in the performance of the application. If an application consumes more CPU then it degrades the performance of the phone while using the app. More the CPU consumed by the application the more the battery is consumed. CPU consumption simply tells you how much memory is used by your application.

How to measure Battery and CPU consumption of an Android application?

CPU consumption of Android application
It is much more important to find how much CPU your application is consuming as the more the CPU consumption the more the Battery is used by the application. Let’s start monitoring CPU consumption.
Setup required for this:

  • Windows 10 OS
  • Android debugger bridge (adb)
  • Android mobile

Configuring the CPU monitoring Environment
These are the steps below to monitor the CPU consumption of Android applications.

Download Android Debugger Bridge(adb)

  1. Download Android Debugger Bridge(adb) zip from the link below:
  2. Extract the zip folder into any folder. I Extracted it in “C:\adb\”
  3. Add this folder path in Environment variable.

Set up your mobile phone to monitor CPU consumption.

  1. Open developer option of your phone by clicking 5 times on build number.
    Go to settings → About phone → Build number.
  2. Now go to developer option
    Enable the developer option.
    Enable USB debugging.
    Click on Revoke USB debugging and press OK.

Let’s start monitoring the CPU consumption of Android application
As you are all set so we can start the monitoring of CPU consumption. It’s easy to monitor CPU consumption. You just need to connect your phone to the desktop or laptop and start to process.

  1. Connect your phone to a desktop or laptop.
  2. Open mobile application for which you want to monitor the battery.
  3. Run command
    adb shell “top -n 1”
    Then you will see a pop up on your mobile phone, Click Allow.
  4. Find your application with its appPackage name from the list of running applications and note down the PID of your application we will use it in the next step.
  5. Run the command below to calculate the CPU consumption of your application.
    adb shell “top -d 1 -p ‘PID of your app’ > /sdcard/performance.txt”
    Example :- adb shell “top -d 1 -p 19598 > /sdcard/performance.txt”
  6. The above command will create the performance.txt file in your device which consists of entries per second CPU consumption of the application.
  7. Run this command for 2 or 3 hours and calculate the average of CPU consumption from performance.txt file.

Let’s start with the battery consumption of the Android application
This is the main part of the application to test as if an application consumes more battery then it’s performance is low and it causes the drainage of battery so we have to test the battery consumption before releasing the app for the end-user.
Steps to test the battery consumption of Android application

  1. Charge your phone to 100% and let’s find out how much battery it is consuming.
  2. Open your application on your mobile and let it run for 2 hours in the background.
  3. After 2 hours check the percentage of battery consumption in Phone settings
  4. Settings → Battery → View detailed usage

Here you can find the percentage of battery used by your applications.

Thanks for reading this blog, if you have any doubts or query you can comment below.

Leave a Reply