Skip to content

Commit c554f18

Browse files
committed
[util] Add cairo-trace.
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!
1 parent 992f74d commit c554f18

9 files changed

+3763
-8
lines changed

build/configure.ac.system

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ AM_CONDITIONAL(CROSS_COMPILING, test "x$cross_compiling" = "xyes")
1010
CAIRO_BIGENDIAN
1111
CAIRO_CHECK_NATIVE_ATOMIC_PRIMITIVES
1212
CAIRO_CHECK_ATOMIC_OP_NEEDS_MEMORY_BARRIER
13+
AC_CHECK_SIZEOF(void *)
14+
AC_CHECK_SIZEOF(size_t)
1315

1416
AC_MSG_CHECKING([for native Win32])
1517
case "$host" in

configure.ac

+17
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,21 @@ AM_CONDITIONAL(BUILD_ANY2PPM,
480480
-o "x$any2ppm_pdf" = "xyes" \
481481
-o "x$any2ppm_ps" = "xyes")
482482

483+
dnl ===========================================================================
484+
dnl The tracing utility requires LD_PRELOAD, so only build it for systems
485+
dnl that are known to work.
486+
487+
case $host in
488+
*-linux*|*-*bsd*)
489+
have_ld_preload="yes"
490+
;;
491+
*)
492+
have_ld_preload="no"
493+
;;
494+
esac
495+
496+
AM_CONDITIONAL(BUILD_TRACE, test "x$have_ld_preload" = "xyes")
497+
483498
dnl ===========================================================================
484499

485500
AC_ARG_ENABLE(some-floating-point,
@@ -516,6 +531,8 @@ test/Makefile
516531
test/pdiff/Makefile
517532
perf/Makefile
518533
util/Makefile
534+
util/cairo-trace/Makefile
535+
util/cairo-trace/cairo-trace
519536
doc/Makefile
520537
doc/public/Makefile
521538
])

util/Makefile.am

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
include $(top_srcdir)/build/Makefile.am.common
22

3+
SUBDIRS = .
4+
5+
if BUILD_TRACE
6+
SUBDIRS += cairo-trace
7+
endif
8+
39
util: malloc-stats.so backtrace-symbols.so
410

511
.la.so:

util/README

-8
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,6 @@ applications. This is useful for either extracting a test case triggering
5050
a bug from an application, or simply to get a general idea of how an
5151
application is using cairo.
5252

53-
This tool lives outside the cairo source distribution right now and can
54-
be found in a git repository at:
55-
56-
http://cgit.freedesktop.org/~ickle/cairo-trace/
57-
58-
There are plans to move it to this directory in the future, and possibly
59-
install it on the system.
60-
6153

6254
cairo-api-update and xr2cairo
6355
-----------------------------

util/cairo-trace/Makefile.am

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
bin_SCRIPTS = cairo-trace
2+
lib_LTLIBRARIES = cairo-trace.la
3+
4+
AM_CPPFLAGS = -I$(top_srcdir)/src \
5+
-I$(top_builddir)/src
6+
7+
cairo_trace_la_SOURCES = \
8+
lookup-symbol.c \
9+
lookup-symbol.h \
10+
trace.c
11+
cairo_trace_la_CFLAGS = @FREETYPE_CFLAGS@ @CAIRO_CFLAGS@
12+
cairo_trace_la_LDFLAGS = -module -no-undefined
13+
cairo_trace_la_LIBADD = -ldl -lz -lbfd
14+
15+
system-install:
16+
grep -sq @libdir@/cairo-trace.so /etc/ld.so.preload || echo @libdir@/cairo-trace.so >> /etc/ld.so.preload
17+
18+
system-uninstall:
19+
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;
20+
21+
EXTRA_DIST = cairo-trace.in

util/cairo-trace/cairo-trace.in

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/sh
2+
3+
prefix=@prefix@
4+
exec_prefix=@exec_prefix@
5+
6+
nofile=
7+
silent=
8+
9+
skip=1
10+
while test $skip -eq 1; do
11+
skip=0
12+
case $1 in
13+
--silent)
14+
skip=1
15+
silent=1
16+
;;
17+
--no-file)
18+
skip=1
19+
nofile=1
20+
;;
21+
esac
22+
if test $skip -eq 1; then
23+
shift
24+
fi
25+
done
26+
27+
if test $# -eq 0; then
28+
cat << EOF
29+
usage: cairo-trace [--no-file|--silent] command
30+
cairo-trace will generate a log of all calls made by command to
31+
cairo. This log will be stored in a file in the local directory
32+
called command.pid.trace.
33+
Whatever else happens is driven by its argument:
34+
--silent - disables the overriding of stdout by cairo-trace.
35+
The trace file is still generated, but your application
36+
is free to continue to use stdout.
37+
--no-file - disables the generation of an output file
38+
39+
Enviroment variables understood by cairo-trace:
40+
CAIRO_TRACE_FLUSH - flush the output after every function call.
41+
EOF
42+
exit
43+
fi
44+
45+
#echo $*
46+
47+
filename=""
48+
if test -z "$nofile"; then
49+
filename=`basename $1`.$$.trace
50+
fi
51+
52+
if test -z "$filename"; then
53+
LD_PRELOAD=@libdir@/cairo-trace.so CAIRO_TRACE_FD=3 LC_ALL=C $* 3>&1 >/dev/null
54+
elif test -n "$silent"; then
55+
LD_PRELOAD=@libdir@/cairo-trace.so LC_ALL=C CAIRO_TRACE_OUTFILE_EXACT=$filename $*
56+
else
57+
LD_PRELOAD=@libdir@/cairo-trace.so CAIRO_TRACE_FD=3 LC_ALL=C $* 3>&1 >/dev/null | tee $filename
58+
fi

0 commit comments

Comments
 (0)