Skip to content

Commit

Permalink
[util] Add cairo-trace.
Browse files Browse the repository at this point in the history
This tool can be used to trace all the cairo function calls made by an
applications.  This is useful for either extracting a test case triggering
a bug from an application, or simply to get a general idea of how an
application is using cairo.

After make install, cairo-trace program arguments, will print out all the
cairo calls to the terminal and also capture theme in ./program.$pid.trace

The format of the output is CairoScript, watch this space for more
cairo-script tools!
  • Loading branch information
Chris Wilson committed Oct 31, 2008
1 parent 992f74d commit c554f18
Show file tree
Hide file tree
Showing 9 changed files with 3,763 additions and 8 deletions.
2 changes: 2 additions & 0 deletions build/configure.ac.system
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ AM_CONDITIONAL(CROSS_COMPILING, test "x$cross_compiling" = "xyes")
CAIRO_BIGENDIAN
CAIRO_CHECK_NATIVE_ATOMIC_PRIMITIVES
CAIRO_CHECK_ATOMIC_OP_NEEDS_MEMORY_BARRIER
AC_CHECK_SIZEOF(void *)
AC_CHECK_SIZEOF(size_t)

AC_MSG_CHECKING([for native Win32])
case "$host" in
Expand Down
17 changes: 17 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,21 @@ AM_CONDITIONAL(BUILD_ANY2PPM,
-o "x$any2ppm_pdf" = "xyes" \
-o "x$any2ppm_ps" = "xyes")

dnl ===========================================================================
dnl The tracing utility requires LD_PRELOAD, so only build it for systems
dnl that are known to work.

case $host in
*-linux*|*-*bsd*)
have_ld_preload="yes"
;;
*)
have_ld_preload="no"
;;
esac

AM_CONDITIONAL(BUILD_TRACE, test "x$have_ld_preload" = "xyes")

dnl ===========================================================================

AC_ARG_ENABLE(some-floating-point,
Expand Down Expand Up @@ -516,6 +531,8 @@ test/Makefile
test/pdiff/Makefile
perf/Makefile
util/Makefile
util/cairo-trace/Makefile
util/cairo-trace/cairo-trace
doc/Makefile
doc/public/Makefile
])
Expand Down
6 changes: 6 additions & 0 deletions util/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
include $(top_srcdir)/build/Makefile.am.common

SUBDIRS = .

if BUILD_TRACE
SUBDIRS += cairo-trace
endif

util: malloc-stats.so backtrace-symbols.so

.la.so:
Expand Down
8 changes: 0 additions & 8 deletions util/README
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ applications. This is useful for either extracting a test case triggering
a bug from an application, or simply to get a general idea of how an
application is using cairo.

This tool lives outside the cairo source distribution right now and can
be found in a git repository at:

http://cgit.freedesktop.org/~ickle/cairo-trace/

There are plans to move it to this directory in the future, and possibly
install it on the system.


cairo-api-update and xr2cairo
-----------------------------
Expand Down
21 changes: 21 additions & 0 deletions util/cairo-trace/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
bin_SCRIPTS = cairo-trace
lib_LTLIBRARIES = cairo-trace.la

AM_CPPFLAGS = -I$(top_srcdir)/src \
-I$(top_builddir)/src

cairo_trace_la_SOURCES = \
lookup-symbol.c \
lookup-symbol.h \
trace.c
cairo_trace_la_CFLAGS = @FREETYPE_CFLAGS@ @CAIRO_CFLAGS@
cairo_trace_la_LDFLAGS = -module -no-undefined
cairo_trace_la_LIBADD = -ldl -lz -lbfd

system-install:
grep -sq @libdir@/cairo-trace.so /etc/ld.so.preload || echo @libdir@/cairo-trace.so >> /etc/ld.so.preload

system-uninstall:
sed -e '/\/usr\/local\/lib\/cairo-trace.so/d' < /etc/ld.so.preload > /tmp/ld.so.preload && mv /tmp/ld.so.preload /etc/ld.so.preload;

EXTRA_DIST = cairo-trace.in
58 changes: 58 additions & 0 deletions util/cairo-trace/cairo-trace.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/sh

prefix=@prefix@
exec_prefix=@exec_prefix@

nofile=
silent=

skip=1
while test $skip -eq 1; do
skip=0
case $1 in
--silent)
skip=1
silent=1
;;
--no-file)
skip=1
nofile=1
;;
esac
if test $skip -eq 1; then
shift
fi
done

if test $# -eq 0; then
cat << EOF
usage: cairo-trace [--no-file|--silent] command
cairo-trace will generate a log of all calls made by command to
cairo. This log will be stored in a file in the local directory
called command.pid.trace.
Whatever else happens is driven by its argument:
--silent - disables the overriding of stdout by cairo-trace.
The trace file is still generated, but your application
is free to continue to use stdout.
--no-file - disables the generation of an output file
Enviroment variables understood by cairo-trace:
CAIRO_TRACE_FLUSH - flush the output after every function call.
EOF
exit
fi

#echo $*

filename=""
if test -z "$nofile"; then
filename=`basename $1`.$$.trace
fi

if test -z "$filename"; then
LD_PRELOAD=@libdir@/cairo-trace.so CAIRO_TRACE_FD=3 LC_ALL=C $* 3>&1 >/dev/null
elif test -n "$silent"; then
LD_PRELOAD=@libdir@/cairo-trace.so LC_ALL=C CAIRO_TRACE_OUTFILE_EXACT=$filename $*
else
LD_PRELOAD=@libdir@/cairo-trace.so CAIRO_TRACE_FD=3 LC_ALL=C $* 3>&1 >/dev/null | tee $filename
fi
Loading

0 comments on commit c554f18

Please sign in to comment.