summaryrefslogtreecommitdiff
path: root/util/cairo-trace/cairo-trace.in
blob: 8a1e1b81a323a16b0c439aa987b480ae33a1af95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/sh

prefix=@prefix@
exec_prefix=@exec_prefix@

nofile=
flush=
nocallers=
nomarkdirty=
compress=

usage() {
cat << EOF
usage: cairo-trace [--no-file] 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:
  --flush         - Flush the output trace after every call.
  --no-file       - Disable the creation of an output file. Outputs to the
                    terminal instead.
  --no-callers    - Do not lookup the caller address/symbol/line whilst tracing.
  --no-mark-dirty - Do not record image data for cairo_mark_dirty()
  --compress      - Compress the output with LZMA
  --profile       - Combine --no-callers and --no-mark-dirty and --compress

Enviroment variables understood by cairo-trace:
  CAIRO_TRACE_FLUSH - flush the output after every function call.
  CAIRO_TRACE_LINE_INFO - emit line information for most function calls.
EOF
exit
}

skip=1
while test $skip -eq 1; do
    skip=0
    case $1 in
    --flush)
	skip=1
	flush=1
	;;
    --no-file)
	skip=1
	nofile=1
	;;
    --no-callers)
	skip=1
	nocallers=1
	;;
    --no-mark-dirty)
	skip=1
	nomarkdirty=1
	;;
    --compress)
	skip=1
	compress=1
	nofile=1
	;;
    --profile)
	skip=1
	compress=1
	nomarkdirty=1
	nocallers=1
	nofile=1
	;;
    --version)
	echo "cairo-trace, version @CAIRO_VERSION_MAJOR@.@CAIRO_VERSION_MINOR@.@CAIRO_VERSION_MICRO@."
	exit
	;;
    --help)
	usage
	;;
    esac
    if test $skip -eq 1; then
	shift
    fi
done

if test $# -eq 0; then
    usage
fi

#echo $*

LD_PRELOAD=@libdir@/cairo/cairo-trace.so 
export LD_PRELOAD

if test -n "$nocallers"; then
    CAIRO_TRACE_LINE_INFO=0
    export CAIRO_TRACE_LINE_INFO
fi

if test -n "$nomarkdirty"; then
    CAIRO_TRACE_MARK_DIRTY=0
    export CAIRO_TRACE_MARK_DIRTY
fi

if test -n "$flush"; then
    CAIRO_TRACE_FLUSH=1
    export CAIRO_TRACE_FLUSH
fi

if test -z "$nofile"; then
    CAIRO_TRACE_OUTDIR=`pwd` "$@"
elif test -n "$compress"; then
    echo Generating compressed trace file $1.$$.lzma
    CAIRO_TRACE_FD=3 "$@" 3>&1 >/dev/null | lzma -cz9 > $1.$$.lzma
else
    CAIRO_TRACE_FD=3 "$@" 3>&1 >/dev/null
fi