Performance Testing Android Apps Part 1: System Performance

Sandeep Dinesh
2 min readMay 23, 2021

--

Performance Test Android App

So here we are with Part 1 of the Android Performance Testing Series where we will discuss System Performance on the Mobile Device/ Simulator. In the next Part, we will discuss the UI performance, specifically the GPU performance/ Frames per second (FPS).

Let’s dive straight to the code/ TLDR:


#!/bin/sh
adb shell ps -ef | grep <APP_PROCESS_NAME> | grep -v grep | awk '{print $2}' > process_id.txt
ID=`cat process_id.txt`
echo $ID
if [ -z $ID ]
then
echo "EROOR: Process not indenitfied"
exit 1
fi
if [[ -f stats.csv ]]
then
echo "Deleting Existing Stats File"
rm -rf stats.csv
fi
echo "Saving Stats to stats.csv file"
echo "VIRTUAL_MEMORY,MEMORY,SYSTEM_MEMORY,CPU_PERCENT,MEMORY_PERCENT,CPU_TIME" > stats.csv
while true;
do
adb shell top -p $ID -n 1 -q -b | awk '{OFS=","};{print $5, $6, $7, $9, $10, $11}' >> stats.csv
done

Explanation

  • The first thing to identify is the process name of the App running in the Mobile Device/ Emulator. This can be identified by looking into the build gradle file/ Activity Name of the Android App
  • Once your app is installed and booted into the device, the next step is to identify the dynamic process ID of the app.
  • Then, we feed the process ID into the top command of the underlying Android shell. Please ensure that the options -n 1, -q, and -b are passed for the following reasons.
  • -n 1 will ensure at a time only 1 snapshot of system usage will be recorded by the command
  • -q will ensure that the summary data are not printed, which will make data processing by the awk script to save the data in CSV format
  • -b will ensure results are batched, else data formating issues are encountered while streaming to the next pipe

Automation Strategy

  • I am running this script in the background while I am running my automation tests using Appium
  • You can create a step in your GitHub actions or CircleCI workflow and run this script in the background

That’s it. Once you have your system performance data in CSV format, You can create graphs using Excel or any spreadsheets. You may also store this data in any data store like RDBMS or others and employ charts using Grafana.

More details on top command and the output formats can be found here

Happy Test Automation!

--

--

Sandeep Dinesh
Sandeep Dinesh

Written by Sandeep Dinesh

Test Automation, CI/CD, DevOps & SRE

No responses yet