How to analyze the performance of C/C++ and debugging OpenGL ES frames on ARM and x86 Android devices

Published Date
06 - Feb - 2015
| Last Updated
23 - Apr - 2015
 
How to analyze the performance of C/C++ and debugging OpenGL ES f...

When developing an Android* application, you usually need to test, optimize, and debug on many different platforms. While basically every hardware and chip manufacturer provides a set of custom tools for this, developers can find it cumbersome to install and learn how to use all of them.

Since their latest releases (2014 R2 as of now), Intel® Graphics Performance Analyzers (Intel® GPA), Intel® Frame Debugger, and Intel® VTune™  Amplifier are able to support most mainstream Android 4.x devices, regardless of their architecture (ARM* or x86).

We have tested these Intel tools and successfully used them on the ARM Android devices listed here, but basically any Android 4.x device is probably compatible.

Summary:

Getting a high-level view of how your app is performing using Intel® GPA System Analyzer.

Intel GPA System Analyzer can run on: Windows* 7/8.x, Mac* OS X*, and Linux* and can be used to analyze apps running on almost any Android 4.x device connected over ADB.

It's a free tool, part of the Intel GPA suite you can get from this dedicated page or INDE.

If your device is rooted, this tool can analyze any application installed on the device. Otherwise, it can only analyze apps with Internet permission and the debuggable flag set to true.

Setting the debuggable flag to true in the AndroidManifest is done automatically when you're doing a debug build with gradle or ant / Android Studio or Eclipse*. But when it comes to analyzing the real performance of an application, you want to run a version that has been optimized for release!

You can manually set this flag to true in your manifest, but lint will complain about it and cause your build to abort. You can easily overcome that.

In Eclipse: disable "HardcodedDebugMode" in Lint Error checking inside Android Preferences. In Android Studio: set inside your build.gradle

01android {
02lintOptions {
03disable 'HardcodedDebugMode'
04}
05}

Now, when running Intel GPA System Analyzer, you first get a list of applications running on the device you've chosen:

Selecting one will trigger its launch on the device, along with its real-time analysis:

From there, you can drag&drop any metric from the left side to see its value evolve in real time.

You may not get hardware-specific metrics on every device as their support varies, but you'll have at least: Target App CPU Load, RAM usage, Device and Network IOs, OpenGL* metrics (draw calls, vertex count, frame time).

In addition to these real-time values, you have the ability to trigger "state overrides" from the bottom left of the window. This will help you determine the current bottleneck in your application:

 

Normal scene:

with all the textures set to a simple 2x2 one:

with disabled alpha-blending:

showing wireframe:

 

You can also disable all the Draw calls. Then no graphics will be rendered, but if the FPS improves, the bottleneck isn't on the OpenGL* side.

A more in-depth article on Intel GPA along with a sample code is available here: https://software.intel.com/en-us/android/articles/using-the-intel-gpa-system-analyzer-to-improve-android-apps

Debugging an OpenGL rendered view using Intel® Frame Debugger

Intel Frame Debugger is used to capture and fully debug OpenGL frames. It's once again a free tool you can get from this dedicated page or INDE and fully works on most Android devices.

As of now, it can be run on Windows 7/8.x platforms only.

First add a frame from a device by clicking "Add":

This will show you a list of applications that you may, or may not, have the right to analyze. Just like previously with Intel GPA System Analyzer, you may analyze any application on a rooted device. Otherwise, only the ones with Internet permission and the debuggable flags set to true:

Double-click to launch one and click on "capture" to get a frame. Once it's done, go back to the previous view and select the captured frame:

You can see all the draw calls that have been made on the left side and the associated simulated OpenGL ES framebuffer on the right side.

A double click on one of these draw calls will allow you to inspect all steps of the OpenGL ES pipeline associated with the draw call, among these:

The primitives and the associated Vertex Buffer Objects

The vertex and fragment shaders

You can see and modify these shaders and even modify the values they're receiving. This will modify the simulated frame as well as the rendered frame on your device if it's still connected!

Analyzing the performance of C/C++ code from Android applications using Intel® VTune™ Amplifier

Intel VTune Amplifier is part of Intel® System Studio suite. Contrary to the previous tools, this suite isn't free unless it's for non-commercial software development. As of now, this tool can be run from Windows and Linux hosts.

To begin with VTune Amplifier, create a new project:

In its properties, choose your device and "Launch Android Package" as type, then you can enter your package name or click on "browse" to look for it:

Once this is done, you can launch a "basic hotspot" analysis. Starting the analysis will launch the app on your device:

Click on Stop to stop the collection (and automatically close the application).

The trace will be collected and displayed:

From there you can, for example, start looking at the results with the "Bottom-up" view and group data by Module / Function / Call Stack:

To associate full library symbols and sources to your results, you can add their paths to your project properties (usually ./obj/local/ABI/ for the non-stripped libs and ./jni for the sources).

More information on performance analysis using VTune can be found here: https://software.intel.com/en-us/node/471808

On supported x86 Android Devices (Intel® reference designs and Dell Venue* 8 with developer image), VTune Amplifier can be used to analyze Java* workloads, get CPU and GPU metrics, and do power analysis!

For more such Android resources and tools from Intel, please visit the Intel® Developer Zone

Source: https://software.intel.com/en-us/android/articles/services-to-test-your-android-apps-on-intel-devices