B2G/Debugging OpenGL
This page describes how to use the apitrace tool to debug OpenGL calls when using Boot2Gecko.
Special thanks goes out to gw280 who wrote the following: http://www.hackermusings.com/2012/03/debugging-opengl-on-android-without-losing-your-sanity/ which is what most of this is based on.
Contents
Get a copy of apitrace
You'll need to follow this step if you want to build the qapitrace graphical tool for analyzing traces. If your distribution already provides such tool or if you're content with the command-line based apitrace tool you can skip the steps needed for building the host version.
The first thing to do is to grab a copy of apitrace.
git clone https://github.com/apitrace/apitrace.git
The INSTALL.markdown file contains instructions for building. I'll summarize what I did (I was running Linux Mint 13 at the time).
Install cmake and needed Qt packages
You will need cmake to build apitrace, additional packages may be required to inspect the traces later. This example should work on most Debian-based distributions
sudo apt-get install cmake libqjson-dev libqtwebkit-dev
Build for the host (linux)
cmake -H. -Bbuild make -C build
Rebuild B2G
apitrace is now integrated in the B2G build-system so the only thing you need to do is to re-build your B2G checkout after having installed cmake and then push everything to the phone
cd /where/you/keep/B2G ./build.sh ./flash.sh
Run b2g
I used the following run-apitrace.sh script, which places the trace in /data/egl.trace. If you don't specify TRACE_FILE then it will be called firefox.trace and will be placed in the same directory as the executable, so /system/b2g/firefox.trace
#!/bin/bash #set -x . load-config.sh ADB=adb B2G_DIR=/system/b2g B2G_BIN=/system/b2g/b2g B2G_PID=`$ADB shell toolbox ps b2g | grep "b2g" | awk '{ print \$2; }'` $ADB shell kill $B2G_PID $ADB shell stop b2g $ADB shell TRACE_FILE=/data/egl.trace \ GRE_HOME=\"${B2G_DIR}\" \ LD_PRELOAD=\"/system/b2g/libmozglue.so /system/lib/apitrace/wrappers/egltrace.so\" \ LD_LIBRARY_PATH=\"/vendor/lib:/system/lib:${B2G_DIR}\" \ ${B2G_BIN}
Analyze the captured trace
export EGL_SOFTWARE=true qapitrace
If you choose Trace->Replay then you should see the capture replay the captured trace, and it will then show a thumbnail next to each frame.
Before running Trace->Replay
After running Trace->Replay
Troubleshooting Replay
If the Trace-Replay doesn't work, then you may be missing some libraries. Try to run:
eglretrace egl.trace
I found that libEGL.so.1 was missing and was able to install it using
sudo apt-get install mesa-utils-extra