DS-5 Development Studio version 5.29 updates the Streamline performance analyzer to version 6.7 and greatly improves functionality when running Android applications without root access. This is a significant improvement for mobile developers building Android applications and testing them on a wide variety of devices. Android application developers typically don’t root devices for testing because it can be a tedious process and they have many devices to test with. Streamline 6.7 provides new sample-based profiling for applications as well as CPU hardware counter information.
Additional features in Streamline 6.7 include support for new Arm IP such as the Cortex-A76 and Mali-G76, support for up to 128 cores, and compare and merge capability. Full details can be found in the release notes on the Downloads page.
To demonstrate the new application profiling features let’s go through the steps to use Streamline on an Android application. SuperTuxKart, a popular Linux racing game which is now available for Android, is a representative application that can be built from source as an Android developer would do it. Let’s build it and use Steamline on non-rooted devices to understand the setup and profiling features.
To get started make sure DS-5 is installed. It’s important to configure DS-5 for the Ultimate Edition for Armv8 support. After the installation is done I recommend starting “Eclipse for DS-5”, or just run eclipse from the Linux command line, and make sure the selected toolkit is “DS-5 Ultimate Edition”. If this is not done Streamline may give a license error when connected to an Android device. To confirm the DS-5 configuration use the Help -> Arm License Manager dialog box. A 30-day trial is available on the Downloads page. More information on the installation process is available in the DS-5 Getting Started Guide.
For Android application profiling the Android SDK Platform Tools are needed for the Android Debug Bridge, adb. It is assumed Android developers will already have these tools and more. I installed the Android NDK and Android Studio to build and profile SuperTuxKart.
Let’s assume the SuperTuxKart Android application is already built from source and the apk is ready to install. Readers likely have their own applications to profile so the SuperTuxKart build details are included as an appendix.
Streamline uses a daemon, known as gatord, running on the target hardware to collect profiling information. Compiled versions of the daemon are included in the DS-5 release, so it’s not required to compile the daemon from source. The source code and instructions to build the gator daemon can be found on GitHub. Building from source is helpful if any problems occur and more information is needed. It is not necessary to install the gator Linux kernel driver to use Streamline for Android application profiling. It is also not recommended to install the Android apk which comes with Streamline because gatord needs specific options for Android application profiling.
The first step to profile an Android application is to setup the path to adb in Streamline. Start Streamline and use the Window -> Preferences and select External Tools to set the ADB Path. This allows Streamline to find adb and connect to a device. Streamline will do this automatically if adb is already installed and found in the search path.
Make sure Android devices enable developer options. Go to the Configuration settings on the device and find the About Phone section and then find the Build Number. The structure of the settings is a little different depending on the device but tap on the Build Number seven times to enable developer options. Confirm USB debugging is enabled to allow adb and Streamline to connect.
Plug in a device via USB and confirm adb can find it. A device should be listed. If the list is empty then no devices were found.
$ adb devices List of devices attached ZY224CVMNB device
Also, make sure it doesn't show "unauthorized". On the first connection a dialog may pop up on the device asking for authorization. Clicking OK on this dialog will change a device from "unauthorized" to "device".
Installing the gator daemon onto the device for profiling the Android application requires it to be placed in the home directory of the user id for the application. In Android, each application has its own Linux user id. For a non-rooted device gatord needs to be run by the user id of the application so it has permission to profile the application. To accomplish this the adb run-as command is used to run commands with the user id of the application. The package name of the application is needed to be able to use the run-as command. The package name can be found in the AndroidManifest.xml file for the application. For SuperTuxKart is it on the third line of the manifest file:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.supertuxkart.stk_dbg" android:versionCode="1" android:versionName="git" android:installLocation="auto">
Another way to find the user id is to run the application on the device, connect using adb shell, use the ps command and find the package name:
$ adb shell albus:/$ ps | grep tux u0_a296 27221 911 1191892 147780 SyS_epoll_ 00000000 S org.supertuxkart.stk_dbg
The uname command indicates which version of gatord to use from $DS5_HOME/sw/streamline. Below shows the uname output from different devices. The first device should use arm64/gatord and the second device must use arm/gatord.
# Use the arm64/gatord for aarch64 $ adb shell uname -a Linux localhost 4.9.65-13087505 #1 SMP PREEMPT Fri Jun 8 13:43:54 KST 2018 aarch64 # Use arm/gatord for armv7l $ adb shell uname -a Linux localhost 3.18.31-perf-gcc9017b-00143-g5f2fcb9 #1 SMP PREEMPT Thu Mar 29 02:29:30 CDT 2018 armv7l
To install gatord copy it from the DS-5 install area to a temp directory on the device and then copy it from temp to the home directory of the user account of the application. Change the arm/ directory to arm64/ to use the aarch64 gatord.
$ adb push $DS5_HOME/sw/streamline/bin/arm/gatord /data/local/tmp $ adb shell run-as org.supertuxkart.stk_dbg cp /data/local/tmp/gatord gatord
Now gatord is ready to use. Starting with Android Nougat, the kernel’s perf system must be enabled to allow Streamline to access the perf sub-system for performance analysis. This can be done using adb to set a property:
$ adb shell setprop security.perf_harden 0
The Android application can be started manually or using adb. To start SuperTuxKart manually use:
$ adb shell run-as org.supertuxkart.stk_dbg ./gatord --wait-process org.supertuxkart.stk_dbg
This will cause gatord to wait for the game to be started manually. If a Streamline capture is started and the game is not started it will eventually timeout.
It’s also possible to launch the game first, begin playing, and then start a Streamline capture.
For additional automation the application can be started using adb:
$ adb shell "am start -n org.supertuxkart.stk_dbg/android.app.NativeActivity"
Unlike previous versions of Streamline, the Android application is now sampled for profiling information and the CPU hardware counters are available.
The counter configuration dialog now has the CPU performance counters. Use the chip icon to access the available performance counters.
This device is an octa-core Cortex-A53. Up to six of the available performance counters can be selected at a time.
The timeline now shows only the processes which are created by SuperTuxKart, not a full system profile. The gator daemon was started as the user id of the application, so it can access all of the performance information about the application.
The Streamline Call Paths, Functions, and Code tabs also have profiling information related to the application. The application must be built with debug information to see the source code information. Make sure to use the Capture & Analysis Options dialog and click “Add ELF image” to navigate to a file which has debugging symbols.
Streamline is now able to profile Android applications without rooting devices. This is a significant improvement for Android application developers who can influence performance of an application by making changes to the source code.
Streamline is now capable of providing full application profiling for Android application development. Version 6.7 adds CPU counters and sample-based profiling without rooting the device. This gives Android application developers another tool to make applications as efficient as possible running on Arm devices. To give Streamline a try by downloading DS-5 using the button below and request a trial license.
[CTAToken URL = "https://developer.arm.com/products/software-development-tools/ds-5-development-studio" target="_blank" text="Get started with the DS-5 Development Studio" class ="green"]
For those who want to build SuperTuxKart and try it with Streamline the steps are listed here. The process was done using Ubuntu 18.04. Building on different versions of Linux are possible but will likely result in minor differences. Minor differences are also possible for different versions of Android Studio.
The SuperTuxKart source code is available on GitHub. The README.ANDROID file is the best place to start. Both git and subversion are needed to access all the files needed to build.
Install the needed tools and dependencies for Ubuntu 18.04:
$ sudo apt-get install git subversion $ sudo apt-get install build-essential cmake libbluetooth-dev \ libcurl4-openssl-dev libenet-dev libfreetype6-dev libfribidi-dev \ libgl1-mesa-dev libglew-dev libjpeg-dev libogg-dev libopenal-dev libpng-dev \ libssl-dev libvorbis-dev libxrandr-dev libx11-dev pkg-config zlib1g-dev \ autoconf pngquant
Get the source code and other files using:
$ cd ; mkdir kart ; cd kart $ git clone https://github.com/supertuxkart/stk-code stk-code $ svn co https://svn.code.sf.net/p/supertuxkart/code/stk-assets stk-assets
Install Java 8 to build the Android application.
$ sudo add-apt-repository ppa:webupd8team/java $ sudo apt-get update $ sudo apt-get install oracle-java8-installer
Install the Android NDK. A specific release, r12b, is recommend by the README.ANDROID file. There is a page for older releases, and a link to the r12b release.
$ cd ; unzip ~/Downloads/android-ndk-r12b-linux-x86_64.zip
Install Android Studio. No specific version is listed so I used the current version.
$ cd ; cp Downloads/android-studio-ide-173.4819257-linux.zip . $ unzip android-studio-ide-173.4819257-linux.zip
This creates the $HOME/android-studio directory.
Add the following to the .bashrc file and source the new environment.
# add these 3 lines to ~/.bashrc using a text editor export NDK_PATH=$HOME/android-ndk-r12b export SDK_PATH=$HOME/Android/Sdk export PATH=$PATH:$HOME/android-studio/bin $ . ~/.bashrc
After the setup is done, run studio.sh and go through wizard to install the Android SDK. This creates the $HOME/Android/Sdk directory.
The setup is now complete and the build process for SuperTuxKart can be started. The process is to run generate_assets.sh and then make.sh.
$ cd ~/kart/stk-code $ git clone https://github.com/supertuxkart/dependencies.git $ cd lib $ tar xvf ../dependencies/android/dependencies-android.tar.xz $ cd ../android $ ./generate_assets.sh
Edit Android.mk to enable -g so the source code is available for Streamline. This can be done using LOCAL_CFLAGS and add -g to the existing options for each of the components of the application.
LOCAL_CFLAGS := -g -I../lib/angelscript/include \
Now start the build:
$ ./make.sh -j 4
The native code will compile, but the build will fail when the Android part starts because gradle is not in the path. It’s possible to install gradle, but I found it easier to just load the project into Android Studio at this point and finish building the apk. Android studio will find all the needed tools to build.
The build will stop with the messages:
Building APK ./make.sh: 489: ./make.sh: gradle: not found Error ocurred.
Now start Android Studio and open the project.
$ studio.sh &
Select “Open and existing Android Studio project” and navigate to select the directory $HOME/kart/stk-code/android
Once the project opens I found I had to make two changes to get the apk to build. Results will vary based on the version of Android Studio.
First, edit the build.gradle file to set version values.
# The original code was: compileSdkVersion compile_sdk_version.toInteger() buildToolsVersion build_tools_ver # Because of an error I changed it to be: compileSdkVersion 28 buildToolsVersion "28.0.0"
Based on a message from Android Studio, I also downgraded the gradle version using File -> Project structure and then use the Project tab to set the gradle version to 3.5
Now use the Build -> Build APK(s) to build the apk file.
When the apk is ready copy it to the device using Android Studio or use adb from the command line.
$ adb install $HOME/kart/stk-code/android/build/outputs/apk/android-debug.apk Success
Now start “SuperTuxKart Debug” to run the game on the device!
To get the source code information in Streamline use the Capture & Analysis Options dialog “Add ELF image” and navigate to $HOME/kart/stk-code/android/obj/local/armeabi-v7a/libmain.so
The steps to build SuperTuxKart for profiling with Streamline are now complete. Although Android developers will have their own applications, an example of one application is useful information for those learning about Android development.