[configure.in] Build fails on Solaris due to non-POSIX ctime_r()
[cairo/haiku.git] / perf / cairo-perf-diff
blob3795456f89319e0fa0ee1b7916ca25831e0dcdf4
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 Additional options can be passed the child cairo-perf process
36 by separating them with a double hyphen (--). For example, to
37 examine what the impact of the latest change is on the stroke
38 test you might use:
40 $argv0 HEAD -- stroke
42 The performance results are cached in .perf next to the .git directory.
44 Set CAIRO_AUTOGEN_OPTIONS to pass options to autogen for both
45 builds.
46 END
48 exit 1
51 # First, pull off any known options
52 while true; do
53 case $1 in
54 -f|--force) force_cairo_perf="true";;
55 -h|--html) html_output="true";;
56 *) break;;
57 esac
59 shift
60 done
62 # Then if anything is left that still looks like an option, (begins
63 # with a dash), give usage to catch --help or any other -garbage
64 if [ $# -eq 0 ] || [ "`echo "$1" | sed 's/^-//'`" != "$1" ]; then
65 usage
68 # Finally, pick up the actual revision arguments
69 if [ $# -eq 1 ] || [ "$2" = "--" ]; then
70 old="$1^"
71 new="$1"
72 shift 1
73 else
74 old="$1"
75 new="$2"
76 shift 2
79 # And post-finally, pass anything after -- on to cairo-perf
80 CAIRO_PERF_OPTIONS="-r -i 10"
81 if [ $# -gt 0 ]; then
82 if [ "$1" = "--" ]; then
83 shift 1
84 CAIRO_PERF_OPTIONS="$CAIRO_PERF_OPTIONS $@"
85 else
86 usage
90 git_setup() {
91 SUBDIRECTORY_OK='Yes'
92 . git-sh-setup
93 CAIRO_DIR=`dirname $GIT_DIR`
94 if [ "$CAIRO_DIR" = "." ]; then
95 CAIRO_DIR=`pwd`
97 CAIRO_PERF_DIR=$CAIRO_DIR/.perf
100 rev2sha() {
101 rev=$1
102 git rev-parse --verify $rev || ( echo "Cannot resolve $rev as a git object" && exit 1 )
105 cpu_count() {
106 test -f /proc/cpuinfo &&
107 grep -c '^processor[[:blank:]]\+:' /proc/cpuinfo ||
108 echo 1
111 # We cache performance output based on a two-part name capturing the
112 # current performance test suite and the library being tested. We
113 # capture these as the tree object of the perf directory in HEAD and
114 # the tree object of the src directory of the revision being tested.
116 # This way, whenever the performance suite is updated, cached output
117 # from old versions of the suite are automatically invalidated. Also,
118 # if a commit just changes things outside of the src tree, (say it
119 # changes the "test" test suite, or README or configure.in, or
120 # whatever), cairo-perf-diff will be smart enough to still use cached
121 # results from a run with an equivalent src tree.
122 rev2perf() {
123 rev=$1
124 src_tree_sha=`rev2sha $rev:src`
125 perf_tree_sha=`rev2sha HEAD:perf`
126 echo "$CAIRO_PERF_DIR/${perf_tree_sha}-${src_tree_sha}.perf"
129 # Usage: run_cairo_perf_if_not_cached <rev> <suffix>
130 # The <rev> argument must be a valid git ref-spec that can
131 # be resolved to a commit. The suffix is just something
132 # unique so that build directories can be separated for
133 # multiple calls to this function.
134 run_cairo_perf_if_not_cached() {
135 rev=$1
136 build_dir="build-$2"
138 owd=`pwd`
139 sha=`rev2sha $rev`
140 perf=`rev2perf $rev`
141 if [ -e $perf ] && [ "$force_cairo_perf" != "true" ]; then
142 return 0
144 if [ ! -d $CAIRO_PERF_DIR ]; then
145 echo "Creating new perf cache in $CAIRO_PERF_DIR"
146 mkdir $CAIRO_PERF_DIR
149 cd $CAIRO_DIR
150 boilerplate_files=`git ls-tree --name-only HEAD boilerplate/*`
151 perf_files=`git ls-tree --name-only HEAD perf/*`
152 cd $CAIRO_PERF_DIR
154 if [ ! -d $build_dir ]; then
155 git clone -s $CAIRO_DIR $build_dir
156 (cd $build_dir; git checkout -b tmp-cairo-perf-diff $sha)
158 cd $build_dir
160 git checkout tmp-cairo-perf-diff
161 git reset --hard $sha
163 if [ -z "$MAKEFLAGS" ]; then
164 CPU_COUNT=`cpu_count`
165 export MAKEFLAGS="-j`expr $CPU_COUNT + 1`"
168 if [ ! -e Makefile ]; then
169 CFLAGS="-O2" ./autogen.sh $CAIRO_AUTOGEN_OPTIONS
171 make CFLAGS="-O2" || (rm config.cache && make CFLAGS="-O2")
172 for file in $boilerplate_files; do
173 rsync $CAIRO_DIR/$file boilerplate
174 done
175 (cd boilerplate; make)
176 for file in $perf_files; do
177 rsync $CAIRO_DIR/$file perf
178 done
179 cd perf;
180 make cairo-perf || exit 1
181 echo "Running \"cairo-perf $CAIRO_PERF_OPTIONS\" against $rev. Results will be cached in:"
182 echo "$perf"
183 (./cairo-perf $CAIRO_PERF_OPTIONS || echo "*** Performance test crashed") >> $perf
184 cd $owd
187 git_setup
189 # Build cairo-perf-diff-files if not available
190 if [ ! -e $CAIRO_DIR/perf/cairo-perf-diff-files ]; then
191 echo "Building cairo-perf-diff-files"
192 make -C $CAIRO_DIR/perf/ cairo-perf-diff-files
195 if [ ! -e $old ]; then
196 run_cairo_perf_if_not_cached $old old
197 old=`rev2perf $old`
200 if [ ! -e $new ]; then
201 run_cairo_perf_if_not_cached $new new
202 new=`rev2perf $new`
205 if [ "$html_output" != "true" ]; then
206 $CAIRO_DIR/perf/cairo-perf-diff-files $old $new
207 else
208 $CAIRO_DIR/perf/cairo-perf-diff-files $old $new |
209 $CAIRO_DIR/perf/make-html.py