Tizen 2.0 Release
[framework/graphics/cairo.git] / perf / cairo-perf-graph
1 #!/bin/sh
2 set -e
3
4 ###
5 ### XXX Source common functions from cairo-perf-diff
6 ###
7
8 usage() {
9     argv0=`basename $0`
10
11     cat >&2 << END
12 Usage:
13 As opposed to its sibling, cairo-perf-diff, cairo-perf-graph targets
14 reviewing changes between series by graphically comparing the performance
15 at each commit.
16
17 The two revisions can be any revision accepted by git. For example:
18
19         $argv0 1.2.0 1.2.4      # Compare performance of 1.2.0 to 1.2.4
20
21 Options:
22
23 -f, --force
24         Forces cairo-perf-diff to re-run performance tests
25         even if cached performance data is available.
26
27 -h, --html
28         With this option performance changes are summarized
29         as HTML table.
30
31 Additional options can be passed the child cairo-perf process
32 by separating them with a double hyphen (--). For example, to
33 examine what the impact of the latest change is on the stroke
34 test you might use:
35
36         $argv0 HEAD -- stroke
37
38 The performance results are cached in .perf next to the .git directory.
39
40 Set CAIRO_AUTOGEN_OPTIONS to pass options to autogen for both
41 builds.
42 END
43
44     exit 1
45 }
46
47 # First, pull off any known options
48 while true; do
49     case $1 in
50         -f|--force) force_cairo_perf="true";;
51         -h|--html) html_output="true";;
52         -s|--show) show_only="true";;
53         *) break;;
54     esac
55
56     shift
57 done
58
59 # Then if anything is left that still looks like an option, (begins
60 # with a dash), give usage to catch --help or any other -garbage
61 if [ $# -eq 0 ] || [ "`echo "$1" | sed 's/^-//'`" != "$1" ]; then
62     usage
63 fi
64
65 # Finally, pick up the actual revision arguments
66 old="$1"
67 new="$2"
68 shift 2
69
70 # And post-finally, pass anything after -- on to cairo-perf
71 CAIRO_PERF_OPTIONS="-r -i 25"
72 if [ $# -gt 0 ]; then
73     if [ "$1" = "--" ]; then
74         shift 1
75         CAIRO_PERF_OPTIONS="$CAIRO_PERF_OPTIONS $@"
76     else
77         usage
78     fi
79 fi
80
81 git_setup() {
82     SUBDIRECTORY_OK='Yes'
83     . "$(git --exec-path)/git-sh-setup"
84     CAIRO_DIR=`dirname $GIT_DIR`
85     if [ "$CAIRO_DIR" = "." ]; then
86         CAIRO_DIR=`pwd`
87     fi
88     CAIRO_PERF_DIR=$CAIRO_DIR/.perf
89 }
90
91 rev2sha() {
92     rev=$1
93     git rev-parse --verify $rev || ( echo "Cannot resolve $rev as a git object" && exit 1 )
94 }
95
96 cpu_count() {
97     test -f /proc/cpuinfo &&
98     grep -c '^processor[[:blank:]]\+:' /proc/cpuinfo ||
99     echo 1
100 }
101
102 # We cache performance output based on a two-part name capturing the
103 # current performance test suite and the library being tested. We
104 # capture these as the tree object of the perf directory in HEAD and
105 # the tree object of the src directory of the revision being tested.
106 #
107 # This way, whenever the performance suite is updated, cached output
108 # from old versions of the suite are automatically invalidated. Also,
109 # if a commit just changes things outside of the src tree, (say it
110 # changes the "test" test suite, or README or configure.in, or
111 # whatever), cairo-perf-diff will be smart enough to still use cached
112 # results from a run with an equivalent src tree.
113 rev2perf() {
114     rev=$1
115     sha=`rev2sha $rev`
116     src_tree_sha=`rev2sha $rev:src`
117     perf_tree_sha=`rev2sha HEAD:perf`
118     echo "$CAIRO_PERF_DIR/${sha}-${perf_tree_sha}-${src_tree_sha}.perf"
119 }
120 rev2perf_glob() {
121     rev=$1
122     src_tree_sha=`rev2sha $rev:src`
123     perf_tree_sha=`rev2sha HEAD:perf`
124     echo "$CAIRO_PERF_DIR/*-${perf_tree_sha}-${src_tree_sha}.perf"
125 }
126
127 # Usage: run_cairo_perf_if_not_cached <rev> <suffix>
128 # The <rev> argument must be a valid git ref-spec that can
129 # be resolved to a commit. The suffix is just something
130 # unique so that build directories can be separated for
131 # multiple calls to this function.
132 run_cairo_perf_if_not_cached() {
133     rev=$1
134     build_dir="build-$2"
135
136     owd=`pwd`
137     sha=`rev2sha $rev`
138     perf=`rev2perf $rev`
139     glob=`rev2perf_glob $rev`
140     if [ -e $glob ] && [ "$force_cairo_perf" != "true" ]  || [ -n "$show_only" ]; then
141         return 0
142     fi
143     if [ ! -d $CAIRO_PERF_DIR ]; then
144         echo "Creating new perf cache in $CAIRO_PERF_DIR"
145         mkdir $CAIRO_PERF_DIR
146     fi
147
148     cd $CAIRO_DIR
149     boilerplate_files=`git ls-tree --name-only HEAD boilerplate/*`
150     perf_files=`git ls-tree --name-only HEAD perf/*`
151     cd $CAIRO_PERF_DIR
152
153     if [ ! -d $build_dir ]; then
154         git clone -s $CAIRO_DIR $build_dir
155         (cd $build_dir; git checkout -b tmp-cairo-perf-diff $sha)
156     fi
157     cd $build_dir
158
159     git checkout tmp-cairo-perf-diff
160     git reset --hard $sha
161
162     if [ -z "$MAKEFLAGS" ]; then
163         CPU_COUNT=`cpu_count`
164         export MAKEFLAGS="-j`expr $CPU_COUNT + 1`"
165     fi
166
167     if [ ! -e Makefile ]; then
168         CFLAGS="-O2" ./autogen.sh $CAIRO_AUTOGEN_OPTIONS
169     fi
170     make CFLAGS="-O2" || (rm config.cache && make CFLAGS="-O2")
171     for file in $boilerplate_files; do
172         rsync $CAIRO_DIR/$file boilerplate
173     done
174     (cd boilerplate; make)
175     for file in $perf_files; do
176         rsync $CAIRO_DIR/$file perf
177     done
178     cd perf;
179     make cairo-perf || exit 1
180     echo "Running \"cairo-perf $CAIRO_PERF_OPTIONS\" against $rev. Results will be cached in:"
181     echo "$perf"
182     (./cairo-perf $CAIRO_PERF_OPTIONS || echo "*** Performance test crashed") >> $perf
183     cd $owd
184 }
185
186 git_setup
187
188 # Build cairo-perf-graph-files if not available
189 if [ ! -e $CAIRO_DIR/perf/cairo-perf-graph-files ]; then
190     echo "Building cairo-perf-graph-files"
191     if [ "x$OS" = "xWindows_NT" ]; then
192         make -f Makefile.win32 -C $CAIRO_DIR/perf/ cairo-perf-graph-files CFG=debug
193     else
194         make -C $CAIRO_DIR/perf/ cairo-perf-graph-files
195     fi
196 fi
197
198 revs=""
199 for rev in `git rev-list --reverse $old..$new`; do
200     run_cairo_perf_if_not_cached $rev rev
201     perf=`rev2perf $rev`
202     [ -e "$perf" ] && revs="$revs $perf"
203 done
204
205 exec $CAIRO_DIR/perf/cairo-perf-graph-files $revs
206 #exec $CAIRO_DIR/libtool --mode=execute gdb --args $CAIRO_DIR/perf/cairo-perf-graph-files $revs