B2G/Debugging OpenGL: Difference between revisions

From MozillaWiki
< B2G
Jump to navigation Jump to search
(bug 849276, reflect the fact tha apitrace was integrated in the build system)
 
(4 intermediate revisions by 3 users not shown)
Line 4: Line 4:


===Get a copy of apitrace===
===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.
The first thing to do is to grab a copy of apitrace.
Line 9: Line 11:
git clone https://github.com/apitrace/apitrace.git
git clone https://github.com/apitrace/apitrace.git
</pre>
</pre>
 
The INSTALL.markdown file contains instructions for building. I'll summarize what I did (I was running Linux Mint 13 at the time).  
The INSTALL.markdown file contains instructions for building. I'll summarize what I did (I was running Linux Mint 13 at the time).
 
===Install the Android NDK===
<pre>
cd /home/work
wget http://dl.google.com/android/ndk/android-ndk-r8-linux-x86.tar.bz2
tar xf android-ndk-r8-linux-x86.tar.bz2
</pre>


===Install cmake and needed Qt packages===
===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
<pre>
<pre>
sudo apt-get install cmake libqjson-dev libqtwebkit-dev
sudo apt-get install cmake libqjson-dev libqtwebkit-dev
Line 30: Line 25:
</pre>
</pre>


===Build for the phone===
===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
<pre>
<pre>
export ANDROID_NDK=/home/work/android-ndk-r8
cd /where/you/keep/B2G
cmake -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/android.toolchain.cmake -DANDROID_API_LEVEL=9 -H. -Bbuild-b2g
./build.sh
make -C build-b2g
./flash.sh
</pre>
 
The egltrace.so for the ARM will be found in <tt>libs/armeabi-v7a/egltrace.so</tt>
 
===Install egltrace.so onto the phone===
<pre>
adb push libs/armeabi-v7a/egltrace.so /data
</pre>
</pre>


===Run b2g===
===Run b2g===
I used the following run-apitrace.sh script, which places the trace in /data/egl.trace. If you don't specify <tt>TRACE_FILE</tt> then it wioll be called <tt>firefox.trace</tt> and will be placed in the same directory as the executable, so <tt>/system/b2g/firefox.trace</tt>
I used the following run-apitrace.sh script, which places the trace in /data/egl.trace. If you don't specify <tt>TRACE_FILE</tt> then it will be called <tt>firefox.trace</tt> and will be placed in the same directory as the executable, so <tt>/system/b2g/firefox.trace</tt>
<pre>
<pre>
#!/bin/bash
#!/bin/bash
Line 53: Line 42:


ADB=adb
ADB=adb
B2G_DIR=/system/b2g
B2G_BIN=/system/b2g/b2g
B2G_BIN=/system/b2g/b2g


B2G_PID=`$ADB shell toolbox ps |
B2G_PID=`$ADB shell toolbox ps b2g |
         grep "b2g" | awk '{ print \$2; }'`
         grep "b2g" | awk '{ print \$2; }'`


$ADB shell kill $B2G_PID
$ADB shell kill $B2G_PID
$ADB shell stop b2g
$ADB shell stop b2g
$ADB shell TRACE_FILE=/data/egl.trace LD_PRELOAD=/data/egltrace.so LD_LIBRARY_PATH=/system/b2g ${B2G_BIN}
$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}
</pre>
</pre>


Line 76: Line 70:
====After running Trace->Replay====
====After running Trace->Replay====
[[File:qapitrace-after-replay.png]]
[[File:qapitrace-after-replay.png]]
===Troubleshooting Replay===
If the Trace-Replay doesn't work, then you may be missing some libraries. Try to run:
<pre>
eglretrace egl.trace
</pre>
I found that libEGL.so.1 was missing and was able to install it using
<pre>
sudo apt-get install mesa-utils-extra
</pre>

Latest revision as of 15:20, 6 November 2013

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.

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

Qapitrace-before-replay.png

After running Trace->Replay

Qapitrace-after-replay.png

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