Pre fix INTENSITY [Copy]TexImage problem (we must use red...)
[cairo/gpu.git] / perf / cairo-perf-diff
blobe695cfccfc35fd0c2a623cfff950fc73a902d908
1 #!/bin/sh
2 set -e
4 usage() {
5 argv0=`basename $0`
7 cat >&2 << END
8 Usage:
9 For comparing files created my cairo-perf:
11 $argv0 old.perf new.perf
13 For comparing (cached) performance of revisions:
15 $argv0 [OPTIONS] <revision> [-- cairo-perf options]
16 $argv0 [OPTIONS] <rev1> <rev2> [-- cairo-perf-options]
18 If given a single revision, compares its results to that of its
19 (first-parent) predecessor. Otherwise compares the two given revisions.
20 The revisions can be any revision accepted by git. For example:
22 $argv0 HEAD # Show impact of latest commit
23 $argv0 1.2.0 1.2.4 # Compare performance of 1.2.0 to 1.2.4
25 Options:
27 -f, --force
28 Forces cairo-perf-diff to re-run performance tests
29 even if cached performance data is available.
31 -h, --html
32 With this option performance changes are summarized
33 as HTML table.
35 -t, --trace
36 Compare performance using trace replays instead of
37 microbenchmarks.
39 Additional options can be passed the child cairo-perf process
40 by separating them with a double hyphen (--). For example, to
41 examine what the impact of the latest change is on the stroke
42 test you might use:
44 $argv0 HEAD -- stroke
46 The performance results are cached in .perf next to the .git directory.
48 Set CAIRO_AUTOGEN_OPTIONS to pass options to autogen for both
49 builds.
50 END
52 exit 1
55 # First, pull off any known options
56 while true; do
57 case $1 in
58 -f|--force) force_cairo_perf="true";;
59 -h|--html) html_output="true";;
60 -t|--trace) use_traces="true";;
61 *) break;;
62 esac
64 shift
65 done
67 # Then if anything is left that still looks like an option, (begins
68 # with a dash), give usage to catch --help or any other -garbage
69 if [ $# -eq 0 ] || [ "`echo "$1" | sed 's/^-//'`" != "$1" ]; then
70 usage
73 # Finally, pick up the actual revision arguments
74 if [ $# -eq 1 ] || [ "$2" = "--" ]; then
75 old="$1^"
76 new="$1"
77 shift 1
78 else
79 old="$1"
80 new="$2"
81 shift 2
84 # And post-finally, pass anything after -- on to cairo-perf
85 CAIRO_PERF_OPTIONS="-r -i 10"
86 if [ $# -gt 0 ]; then
87 if [ "$1" = "--" ]; then
88 shift 1
89 CAIRO_PERF_OPTIONS="$CAIRO_PERF_OPTIONS $@"
90 else
91 usage
95 git_setup() {
96 SUBDIRECTORY_OK='Yes'
97 . "$(git --exec-path)/git-sh-setup"
98 CAIRO_DIR=`dirname $GIT_DIR`
99 if [ "$CAIRO_DIR" = "." ]; then
100 CAIRO_DIR=`pwd`
102 CAIRO_PERF_DIR=$CAIRO_DIR/.perf
103 export CAIRO_TRACE_DIR=$CAIRO_DIR/perf/cairo-traces
106 rev2sha() {
107 rev=$1
108 git rev-parse --verify $rev || ( echo "Cannot resolve $rev as a git object" && exit 1 )
111 cpu_count() {
112 test -f /proc/cpuinfo &&
113 grep -c '^processor[[:blank:]]\+:' /proc/cpuinfo ||
114 echo 1
117 # We cache performance output based on a two-part name capturing the
118 # current performance test suite and the library being tested. We
119 # capture these as the tree object of the perf directory in HEAD and
120 # the tree object of the src directory of the revision being tested.
122 # This way, whenever the performance suite is updated, cached output
123 # from old versions of the suite are automatically invalidated. Also,
124 # if a commit just changes things outside of the src tree, (say it
125 # changes the "test" test suite, or README or configure.in, or
126 # whatever), cairo-perf-diff will be smart enough to still use cached
127 # results from a run with an equivalent src tree.
128 rev2perf() {
129 rev=$1
130 sha=`rev2sha $rev`
131 src_tree_sha=`rev2sha $rev:src`
132 perf_tree_sha=`rev2sha HEAD:perf`
133 script_tree_sha=`rev2sha HEAD:util/cairo-script`
134 echo "$CAIRO_PERF_DIR/${sha}-${perf_tree_sha}-${script_tree_sha}-${src_tree_sha}.perf"
136 rev2perf_glob() {
137 rev=$1
138 src_tree_sha=`rev2sha $rev:src`
139 perf_tree_sha=`rev2sha HEAD:perf`
140 script_tree_sha=`rev2sha HEAD:util/cairo-script`
141 echo "$CAIRO_PERF_DIR/*-${perf_tree_sha}-${script_tree_sha}-${src_tree_sha}.perf"
144 build() {
145 build_dir=$1
146 sha=$2
148 if [ ! -d $build_dir ]; then
149 git clone -s $CAIRO_DIR $build_dir
150 (cd $build_dir; git checkout -b tmp-cairo-perf-diff $sha)
152 cd $build_dir
154 git checkout tmp-cairo-perf-diff
155 git reset --hard $sha
157 if [ -z "$MAKEFLAGS" ]; then
158 CPU_COUNT=`cpu_count`
159 export MAKEFLAGS="-j`expr $CPU_COUNT + 1`"
162 if [ ! -e Makefile ]; then
163 ./autogen.sh $CAIRO_AUTOGEN_OPTIONS
166 for file in $boilerplate_files; do
167 rsync $CAIRO_DIR/$file boilerplate
168 done
169 for file in $perf_files; do
170 rsync $CAIRO_DIR/$file perf
171 done
172 for file in $script_files; do
173 rsync $CAIRO_DIR/$file util/cairo-script
174 done
176 make || (rm config.cache && make)
177 (cd boilerplate && make libcairoboilerplate.la)
179 cd perf
180 make cairo-perf cairo-perf-trace
183 # Usage: run_cairo_perf_if_not_cached <rev> <suffix>
184 # The <rev> argument must be a valid git ref-spec that can
185 # be resolved to a commit. The suffix is just something
186 # unique so that build directories can be separated for
187 # multiple calls to this function.
188 run_cairo_perf_if_not_cached() {
189 rev=$1
190 build_dir="build-$2"
192 owd=`pwd`
193 sha=`rev2sha $rev`
194 perf=`rev2perf $rev`
195 glob=`rev2perf_glob $rev`
196 if [ -e $glob ] && [ "$force_cairo_perf" != "true" ]; then
197 return 0
199 if [ ! -d $CAIRO_PERF_DIR ]; then
200 echo "Creating new perf cache in $CAIRO_PERF_DIR"
201 mkdir $CAIRO_PERF_DIR
204 cd $CAIRO_DIR
205 boilerplate_files=`git ls-tree --name-only HEAD boilerplate/*`
206 perf_files=`git ls-tree --name-only HEAD perf/*`
207 script_files=`git ls-tree --name-only HEAD util/cairo-script/*`
208 cd $CAIRO_PERF_DIR
210 build $build_dir $sha || {
211 rm -rf $build_dir
212 build $build_dir $sha || exit 1
215 if [ "$use_traces" = "true" ]; then
216 cmd="cairo-perf-trace"
217 else
218 cmd="cairo-perf"
220 echo "Running \"$cmd $CAIRO_PERF_OPTIONS\" against $rev. Results will be cached in:"
221 echo "$perf"
223 (./$cmd $CAIRO_PERF_OPTIONS || echo "*** Performance test crashed") >> $perf
225 cd $owd
228 git_setup
230 # Build cairo-perf-diff-files if not available
231 if [ ! -e $CAIRO_DIR/perf/cairo-perf-diff-files ]; then
232 echo "Building cairo-perf-diff-files"
233 if [ "x$OS" = "xWindows_NT" ]; then
234 make -f Makefile.win32 -C $CAIRO_DIR/perf/ cairo-perf-diff-files CFG=debug
235 else
236 make -C $CAIRO_DIR/perf/ cairo-perf-diff-files
240 if [ ! -e $old ]; then
241 run_cairo_perf_if_not_cached $old old
242 old=`rev2perf $old`
245 if [ ! -e $new ]; then
246 run_cairo_perf_if_not_cached $new new
247 new=`rev2perf $new`
250 if [ "$html_output" != "true" ]; then
251 $CAIRO_DIR/perf/cairo-perf-diff-files $old $new
252 else
253 $CAIRO_DIR/perf/cairo-perf-diff-files $old $new |
254 $CAIRO_DIR/perf/make-html.py