4 **apitrace** consists of a set of tools to:
6 * trace OpenGL, D3D9, D3D8, D3D7, and DDRAW APIs calls to a file;
8 * retrace OpenGL calls from a file;
10 * visualize trace files, and inspect state.
20 Run the application you want to trace as
22 LD_PRELOAD=/path/to/glxtrace.so /path/to/application
24 and it will generate a trace named `application.trace` in the current
25 directory. You can specify the written trace filename by setting the
26 `TRACE_FILE` environment variable before running.
30 /path/to/tracedump application.trace | less -R
34 /path/to/glretrace application.trace
36 Pass the `-sb` option to use a single buffered visual. Pass `--help` to
37 glretrace for more options.
41 /path/to/qapitrace application.trace
44 The `LD_PRELOAD` mechanism should work with most applications. There are some
45 applications, e.g., Unigine Heaven, which global function pointers with the
46 same name as GL entrypoints, living in a shared object that wasn't linked with
47 `-Bsymbolic` flag, so relocations to those globals function pointers get
48 overwritten with the address to our wrapper library, and the application will
49 segfault when trying to write to them. For these applications it is possible
50 to trace by using `glxtrace.so` as an ordinary `libGL.so` and injecting into
53 ln -s glxtrace.so libGL.so
54 ln -s glxtrace.so libGL.so.1
55 ln -s glxtrace.so libGL.so.1.2
56 export LD_LIBRARY_PATH=/path/to/directory/where/glxtrace/is:$LD_LIBRARY_PATH
57 export TRACE_LIBGL=/path/to/real/libGL.so.1
60 See the `ld.so` man page for more information about `LD_PRELOAD` and
61 `LD_LIBRARY_PATH` environment flags.
68 Usage on Mac OS X is similar to Linux above, except for the tracing procedure,
71 DYLD_LIBRARY_PATH=/path/to/apitrace/wrappers /path/to/application
73 Note that although Mac OS X has an `LD_PRELOAD` equivalent,
74 `DYLD_INSERT_LIBRARIES`, it is mostly useless because it only works with
75 `DYLD_FORCE_FLAT_NAMESPACE=1` which breaks most applications. See the `dyld` man
76 page for more details about these environment flags.
82 * Copy `opengl32.dll`, `d3d8.dll`, or `d3d9.dll` from build/wrappers directory
83 to the directory with the application you want to trace.
85 * Run the application.
89 \path\to\tracedump application.trace
91 * Replay the trace with
93 \path\to\glretrace application.trace
96 Advanced command line usage
97 ===========================
100 Dump GL state at a particular call
101 ----------------------------------
103 You can get a dump of the bound GL state at call 12345 by doing:
105 /path/to/glretrace -D 12345 application.trace > 12345.json
107 This is precisely the mechanism the GUI obtains its own state.
109 You can compare two state dumps with the jsondiff.py script:
111 ./scripts/jsondiff.py 12345.json 67890.json
114 Comparing two traces side by side
115 ---------------------------------
117 ./scripts/tracediff.sh trace1.trace trace2.trace
119 This works only on Unices, and it will truncate the traces due to performance
123 Recording a video with FFmpeg
124 -----------------------------
126 You can make a video of the output by doing
128 /path/to/glretrace -s - application.trace \
129 | ffmpeg -r 30 -f image2pipe -vcodec ppm -i pipe: -vcodec mpeg4 -y output.mp4
132 Advanced usage for OpenGL implementors
133 ======================================
135 There are several avanced usage examples meant for OpenGL implementors.
141 These are the steps to create a regression testsuite around apitrace:
145 * obtain reference snapshots, by doing:
147 mkdir /path/to/snapshots/
148 /path/to/glretrace -s /path/to/reference/snapshots/ application.trace
152 * prune the snapshots which are not interesting
154 * to do a regression test, do:
156 /path/to/glretrace -c /path/to/reference/snapshots/ application.trace
158 Alternatively, for a HTML summary, use the snapdiff script:
160 /path/to/glretrace -s /path/to/current/snapshots/ application.trace
161 ./scripts/snapdiff.py --output summary.html /path/to/reference/snapshots/ /path/to/current/snapshots/
164 Automated git-bisection
165 -----------------------
167 With tracecheck.py it is possible to automate git bisect and pinpoint the
168 commit responsible for a regression.
170 Below is an example of using tracecheck.py to bisect a regression in the
171 Mesa-based Intel 965 driver. But the procedure could be applied to any GL
172 driver hosted on a git repository.
174 First, create a build script, named build-script.sh, containing:
178 export PATH=/usr/lib/ccache:$PATH
181 ./autogen.sh --disable-egl --disable-gallium --disable-glut --disable-glu --disable-glw --with-dri-drivers=i965
185 It is important that builds are both robust, and efficient. Due to broken
186 dependency discovery in Mesa's makefile system, it was necessary invoke `make
187 clean` in every iteration step. `ccache` should be installed to avoid
188 recompiling unchanged source files.
193 export LIBGL_DEBUG=verbose
194 export LD_LIBRARY_PATH=$PWD/lib
195 export LIBGL_DRIVERS_DIR=$PWD/lib
197 6491e9593d5cbc5644eb02593a2f562447efdcbb 71acbb54f49089b03d3498b6f88c1681d3f649ac \
198 -- src/mesa/drivers/dri/intel src/mesa/drivers/dri/i965/
199 git bisect run /path/to/tracecheck.py \
200 --precision-threshold 8.0 \
201 --build /path/to/build-script.sh \
202 --gl-renderer '.*Mesa.*Intel.*' \
203 --retrace=/path/to/glretrace \
204 -c /path/to/reference/snapshots/ \
205 topogun-1.06-orc-84k.trace
207 The trace-check.py script will skip automatically when there are build
210 The `--gl-renderer` option will also cause a commit to be skipped if the
211 `GL_RENDERER` is unexpected (e.g., when a software renderer or another GL
212 driver is unintentianlly loaded due to missing symbol in the DRI driver, or
213 another runtime fault).
216 Side by side retracing
217 ----------------------
219 In order to determine which draw call a regression first manifests one could
220 generate snapshots for every draw call, using the -S option. That is, however,
221 very inefficient for big traces with many draw calls.
223 A faster approach is to run both the bad and a good GL driver side-by-side.
224 The latter can be either a preivously known good build of the GL driver, or a
225 reference software renderer.
227 This can be achieved with retracediff.py script, which invokes glretrace with
228 different environments, allowing to choose the desired GL driver by
229 manipulating variables such as `LD_LIBRARY_PATH` or `LIBGL_DRIVERS_DIR`.
233 ./scripts/retracediff.py \
234 --ref-env LD_LIBRARY_PATH=/path/to/reference/GL/implementation \
236 --diff-prefix=/path/to/output/diffs \
246 * [Official mailing list](http://lists.freedesktop.org/mailman/listinfo/apitrace)
248 * [Zack Rusin's blog introducing the GUI](http://zrusin.blogspot.com/2011/04/apitrace.html)
250 * [Jose's Fonseca blog introducing the tool](http://jrfonseca.blogspot.com/2008/07/tracing-d3d-applications.html)
258 * [Proxy DLL](http://www.mikoweb.eu/index.php?node=21)
260 * [Intercept Calls to DirectX with a Proxy DLL](http://www.codeguru.com/cpp/g-m/directx/directx8/article.php/c11453/)
262 * [Direct3D 9 API Interceptor](http://graphics.stanford.edu/~mdfisher/D3D9Interceptor.html)
266 * [Microsoft PIX](http://msdn.microsoft.com/en-us/library/ee417062.aspx)
268 * [D3DSpy](http://doc.51windows.net/Directx9_SDK/?url=/directx9_sdk/graphics/programmingguide/TutorialsAndSamplesAndToolsAndTips/Tools/D3DSpy.htm): the predecessor of PIX
270 * [AMD GPU PerfStudio](http://developer.amd.com/gpu/PerfStudio/pages/APITraceWindow.aspx)
278 * [BuGLe](http://www.opengl.org/sdk/tools/BuGLe/)
280 * [GLIntercept](http://code.google.com/p/glintercept/)
282 * [tracy](https://gitorious.org/tracy): OpenGL ES and OpenVG trace, retrace, and state inspection
286 * [gDEBugger](http://www.gremedy.com/products.php)
288 * [glslDevil](http://cumbia.informatik.uni-stuttgart.de/glsldevil/index.html)
290 * [AMD GPU PerfStudio](http://developer.amd.com/gpu/PerfStudio/pages/APITraceWindow.aspx)