Tizen 2.0 Release
[framework/graphics/cairo.git] / util / cairo-trace / cairo-trace.in
1 #!/bin/sh
2
3 prefix=@prefix@
4 exec_prefix=@exec_prefix@
5
6 nofile=
7 flush=
8 nocallers=
9 nomarkdirty=
10 compress=
11
12 usage() {
13 cat << EOF
14 usage: cairo-trace [--no-file] command
15 cairo-trace will generate a log of all calls made by command to
16 cairo. This log will be stored in a file in the local directory
17 called command.pid.trace.
18 Whatever else happens is driven by its argument:
19   --flush         - Flush the output trace after every call.
20   --no-file       - Disable the creation of an output file. Outputs to the
21                     terminal instead.
22   --no-callers    - Do not lookup the caller address/symbol/line whilst tracing.
23   --mark-dirty    - Record image data for cairo_mark_dirty() [default]
24   --no-mark-dirty - Do not record image data for cairo_mark_dirty()
25   --compress      - Compress the output with LZMA
26   --profile       - Combine --no-callers and --no-mark-dirty and --compress
27
28 Environment variables understood by cairo-trace:
29   CAIRO_TRACE_FLUSH - flush the output after every function call.
30   CAIRO_TRACE_LINE_INFO - emit line information for most function calls.
31 EOF
32 exit
33 }
34
35 skip=1
36 while test $skip -eq 1; do
37     skip=0
38     case $1 in
39     --flush)
40         skip=1
41         flush=1
42         ;;
43     --no-file)
44         skip=1
45         nofile=1
46         ;;
47     --no-callers)
48         skip=1
49         nocallers=1
50         ;;
51     --mark-dirty)
52         skip=1
53         nomarkdirty=
54         ;;
55     --no-mark-dirty)
56         skip=1
57         nomarkdirty=1
58         ;;
59     --compress)
60         skip=1
61         compress=1
62         nofile=1
63         ;;
64     --profile)
65         skip=1
66         compress=1
67         nomarkdirty=1
68         nocallers=1
69         nofile=1
70         ;;
71     --version)
72         echo "cairo-trace, version @CAIRO_VERSION_MAJOR@.@CAIRO_VERSION_MINOR@.@CAIRO_VERSION_MICRO@."
73         exit
74         ;;
75     --help)
76         usage
77         ;;
78     esac
79     if test $skip -eq 1; then
80         shift
81     fi
82 done
83
84 if test $# -eq 0; then
85     usage
86 fi
87
88 CAIRO_TRACE_PROG_NAME="$1"
89 export CAIRO_TRACE_PROG_NAME
90
91 if test "x$CAIRO_TRACE_SO" = "x"; then
92     CAIRO_TRACE_SO=""
93     for lib in @libdir@/cairo/libcairo-trace.@SHLIB_EXT@ @libdir@/cairo/libcairo-trace.@SHLIB_EXT@* @libdir@/cairo/libcairo-trace.*.@SHLIB_EXT@ ; do
94         if test -h "$lib" -o -f "$lib"; then
95             CAIRO_TRACE_SO="$lib"
96             break
97         fi
98     done
99 fi
100 if test "x$CAIRO_TRACE_SO" = "x"; then
101     echo "Could not find the cairo-trace shared library in @libdir@/cairo/." >&2
102     echo "Set the CAIRO_TRACE_SO environment variable to the full path of the library." >&2
103     exit 15
104 fi
105
106 LD_PRELOAD="$CAIRO_TRACE_SO"
107 DYLD_INSERT_LIBRARIES="$CAIRO_TRACE_SO"
108 DYLD_FORCE_FLAT_NAMESPACE=1
109 export LD_PRELOAD
110 export DYLD_INSERT_LIBRARIES
111 export DYLD_FORCE_FLAT_NAMESPACE
112
113 if test -n "$nocallers"; then
114     CAIRO_TRACE_LINE_INFO=0
115     export CAIRO_TRACE_LINE_INFO
116 fi
117
118 if test -n "$nomarkdirty"; then
119     CAIRO_TRACE_MARK_DIRTY=0
120     export CAIRO_TRACE_MARK_DIRTY
121 fi
122
123 if test -n "$flush"; then
124     CAIRO_TRACE_FLUSH=1
125     export CAIRO_TRACE_FLUSH
126 fi
127
128 if test -z "$nofile"; then
129     CAIRO_TRACE_OUTDIR=`pwd` "$@"
130 elif test -n "$compress"; then
131     name=`basename $1`
132     echo Generating compressed trace file $name.$$.lzma
133     CAIRO_TRACE_FD=3 "$@" 3>&1 >/dev/null | lzma -cz9 > $name.$$.lzma
134 else
135     CAIRO_TRACE_FD=3 "$@" 3>&1 >/dev/null
136 fi