Analyzing Android UI Performance

Integrating UI Performance into your testing practices guarantees interaction with your applications satisfies users’ demands.

An important step in app testing is measuring UI performance, but it is sometimes eclipsed by testing application functionality. Once you are done with functional tests, you may want to ensure that user interactions with your app are smooth, and they run at a consistent 60 frames per second mark. Not delaying or dropping frames, which is very noticeable and have a great impact on the perceived quality of your app.

The official page Testing UI Performance shows how to measure UI performance and how to obtain precise frame timing info using adb shell dumpsys command. However, it is very tedious to do all the steps manually and finally get extremely raw data presented as a series of frame timings. You should parse the raw output to locate the timings, then extract them and finally, copy and paste into a spreadsheet or some other software with the ability to create charts.

0,27965466202353,27965466202353,27965449758000,27965461202353,27965467153286,27965471442505,27965471925682,27965474025318,27965474588547,27965474860786,27965475078599,27965479796151,27965480589068,
0,27965482993342,27965482993342,27965465835000,27965477993342,27965483807401,27965486875630,27965487288443,27965489520682,27965490184380,27965490568703,27965491408078,27965496119641,27965496619641,
0,27965499784331,27965499784331,27965481404000,27965494784331,27965500785318,27965503736099,27965504201151,27965506776568,27965507298443,27965507515005,27965508405474,27965513495318,27965514061984,
0,27965516575320,27965516575320,27965497155000,27965511575320,27965517697349,27965521276151,27965521734797,27965524350474,27965524884536,27965525160578,27965526020891,27965531371203,27965532114484,

Wouldn’t it be great if you can just run a command a obtain the chart without all the tedious work?

AndroidViewClient/culebra, which its main purpose is to automate Android testing, can also help in this case simplifying the steps that usually require manual interaction. In such way, you can measure UI performance, and produce charts that will help you understand and locate the problems.

Latest AndroidViewClient/culebra versions have introduced the ability to plot some metrics from your device or emulator directly. The Dumpsys module obtains and parses dumpsys information to greatly facilitate its usage converting it to objects.

The following python script shows how we can use it to obtain FRAMESTATS from dumpsys output.

Firstly, it opens the connection to the device that should already be present when you run adb devices. If the connection fails the script will exit with an error message.

Then, the Dumpsys object is obtained, stating that we are interested in FRAMESTATS for the pkg package that is specified in the command line. This object is appended to the Plot and later the plot obtained.

Before you could obtain this data from the device you should enable it in Developer options

After this, you should start playing with your app so the relevant timing data is collected. We will cover this in future articles but automating this step is also a great candidate for AndroidViewClient/culebra or CulebraTester.

For example, using the sample performance testing app with package com.google.android.perftesting, when we run

./gfxinfo-plot.py com.google.android.perftesting

we obtain a histogram plot similar to this one.

The cyan and red vertical lines indicate 60fps and 30fps respectively. You can easily verify, in this case, that most of the frames are under the 60fps mark, indicating a fluid UI.

Enjoy it!