Grabbing OpenGL frames with Android Studio

An OpenGL Frame Grabber allows us to analyze all the OpenGL function calls that render a particular frame. With it, among other things, we can find performance issues and rendering bugs. A few months ago, OpenGL Frame grabbing capabilities were added into Android Studio.

Warning: Android Studio’s OpenGL Frame Grabber is currently tagged as experimental

This is how we use it for Cocos2d-x games.

Create a Cocos2d-x game and compile it for Android Studio + armeabi-v7a

Create a C++ game, but it could be a JS or Lua game as well:

We should add the armeabi-v7a support by adding “APP_ABI := armeabi-v7a" into the file (by default it will only compile it for armeabi).

After adding that line, it should look like this:

And we should add the following C++ code snippet. Just edit the mygame/ file and add the following lines:

After editing the file, it should look like this: main.cpp

After those changes, we are ready to compile it. Just do cocos compile -p android --android-studio

(pay attention to the "--android-studio" option). Example:

Install Android Studio + GPU Debugging tools

The OpenGL frame grabber only works within Android Studio, so we should download it and install it.

And we also need to install the GPU Debugging Tools, which are not installed by default:

  1. Open Android Studio
  2. Then click on Configure -> SDK Manager -> Android SDK. Then select the SDK Tools tab. Then select the “GPU Debugging Tools”.


Enable GPU Profiling in your Android device

We need to enable the Profile GPU rendering in our device, otherwise Android Studio won’t be able to fetch the GPU data from it. Open the Android device, and then go to: Settings -> Developer Options -> Profile GPU rendering. Then select: “in adb shell dumpsys glxinfo”


Of course, we have to do repeat this step for every device that we want to profile.

Adding the GPU trace library

We also need to include the trace library into our game project. The GPU trace library is located in:  <AndroidSdkDir>/extras/android/gapid/android/

So, in OS X, it should be located in: ~/Library/Android/sdk/extras/android/gapid/android/

As of today, this library is only compiled for for arm64-v8a (ARM 64-bit) and for armeabi-v7a (ARM 32-bit). We have to copy the armeabi-v7a one (unless we are using Cocos2d-x in arm64-v8 mode, which is not active by default).

As a double-check, these are the files that we should find in the armeabi-v7a directory:

Important: We should perform this step after each "cocos compile", since "cocos compile" will clean the app/libs/ directory.

Running the game

And now we are ready to trace the game. From Android Studio we should open our game:

  1. Open Android Studio
  2. Click on “Open Existing Android Studio project”
  3. We select the "mygame/" directory, and we click on Choose button. We should see:

Screen Shot 2016-01-28 at 7.15.31 PM

Click on run (the Green Play button). The game will start, but we should only see a black screen. This is because the frame grabber that is running on the device is waiting for the “record” button.

So we have to:

  1. Select the “Android Monitor” window
  2. Select the GPU tab
  3. Press the Red button, the one with the “Listen: start tracing” label.

Screen Shot 2016-01-29 at 3.58.42 PM


The frames will get “grabbed” until we press the Red button again. After that we should see all the grabbed frames with all the useful info:

Screen Shot 2016-01-29 at 4.06.27 PM

Further reading:

Posted in programming Tagged with: , ,