Upload Tizen2.0 source
[framework/graphics/cairo.git] / perf / README
1 This is cairo's performance test suite.
2
3 One of the simplest ways to run the performance suite is:
4
5     make perf
6
7 which will give a report of the speed of each individual test. See
8 more details on other options for running the suite below.
9
10 Running the cairo performance suite
11 -----------------------------------
12 The performance suite is composed of two types of tests, micro- and
13 macro-benchmarks. The micro-benchmarks are a series of hand-written,
14 short, synthetic tests that measure the speed of doing a simple
15 operation such as painting a surface or showing glyphs. These aim to
16 give very good feedback on whether a performance related patch is
17 successful without causing any performance degradations elsewhere. The
18 second type of benchmark consists of replaying a cairo-trace from a
19 large application during typical usage. These aim to give an overall
20 feel as to whether cairo is faster for everyday use.
21
22 Running the micro-benchmarks
23 ----------------------------
24 The micro-benchmarks are compiled into a single executable called
25 cairo-perf-micro, which is what "make perf" executes. Some
26 examples of running it:
27
28     # Report on all tests with default number of iterations:
29     ./cairo-perf-micro
30
31     # Report on 100 iterations of all gradient tests:
32     ./cairo-perf-micro -i 100 gradient
33
34     # Generate raw results for 10 iterations into cairo.perf
35     ./cairo-perf-micro -r -i 10 > cairo.perf
36     # Append 10 more iterations of the paint test
37     ./cairo-perf-micro -r -i 10 paint >> cairo.perf
38
39 Raw results aren't useful for reading directly, but are quite useful
40 when using cairo-perf-diff to compare separate runs (see more
41 below). The advantage of using the raw mode is that test runs can be
42 generated incrementally and appended to existing reports.
43
44 Running the macro-benchmarks
45 ----------------------------
46 The macro-benchmarks are run by a single program called
47 cairo-perf-trace, which is also executed by "make perf".
48 cairo-perf-trace loops over the series of traces stored beneath
49 cairo-traces/. cairo-perf-trace produces the same output and takes the
50 same arguments as cairo-perf-micro.  Some examples of running it:
51
52     # Report on all tests with default number of iterations:
53     ./cairo-perf-trace
54
55     # Report on 100 iterations of all firefox tests:
56     ./cairo-perf-trace -i 100 firefox
57
58     # Generate raw results for 10 iterations into cairo.perf
59     ./cairo-perf-trace -r -i 10 > cairo.perf
60     # Append 10 more iterations of the poppler tests
61     ./cairo-perf-trace -r -i 10 poppler >> cairo.perf
62
63 Generating comparisons of separate runs
64 ---------------------------------------
65 It's often useful to generate a chart showing the comparison of two
66 separate runs of the cairo performance suite, (for example, after
67 applying a patch intended to improve cairo's performance). The
68 cairo-perf-diff script can be used to compare two report files
69 generated by cairo-perf.
70
71 Again, by way of example:
72
73     # Show performance changes from cairo-orig.perf to cairo-patched.perf
74     ./cairo-perf-diff cairo-orig.perf cairo-patched.perf
75
76 This will work whether the data files were generate in raw mode (with
77 cairo-perf -r) or cooked, (cairo-perf without -r).
78
79 Finally, in its most powerful mode, cairo-perf-diff accepts two git
80 revisions and will do all the work of checking each revision out,
81 building it, running cairo-perf for each revision, and finally
82 generating the report. Obviously, this mode only works if you are
83 using cairo within a git repository, (and not from a tar file). Using
84 this mode is as simple as passing the git revisions to be compared to
85 cairo-perf-diff:
86
87     # Compare cairo 1.2.6 to cairo 1.4.0
88     ./cairo-perf-diff 1.2.6 1.4.0
89
90     # Measure the impact of the latest commit
91     ./cairo-perf-diff HEAD~1 HEAD
92
93 As a convenience, this common desire to measure a single commit is
94 supported by passing a single revision to cairo-perf-diff, in which
95 case it will compare it to the immediately preceding commit. So for
96 example:
97
98     # Measure the impact of the latest commit
99     ./cairo-perf-diff HEAD
100
101     # Measure the impact of an arbitrary commit by SHA-1
102     ./cairo-perf-diff aa883123d2af90
103
104 Also, when passing git revisions to cairo-perf-diff like this, it will
105 automatically cache results and re-use them rather than re-running
106 cairo-perf over and over on the same versions. This means that if you
107 ask for a report that you've generated in the past, cairo-perf-diff
108 should return it immediately.
109
110 Now, sometimes it is desirable to generate more iterations rather than
111 re-using cached results. In this case, the -f flag can be used to
112 force cairo-perf-diff to generate additional results in addition to
113 what has been cached:
114
115     # Measure the impact of latest commit (force more measurement)
116     ./cairo-perf-diff -f
117
118 And finally, the -f mode is most useful in conjunction with the --
119 option to cairo-perf-diff which allows you to pass options to the
120 underlying cairo-perf runs. This allows you to restrict the additional
121 test runs to a limited subset of the tests.
122
123 For example, a frequently used trick is to first generate a chart with
124 a very small number of iterations for all tests:
125
126     ./cairo-perf-diff HEAD
127
128 Then, if any of the results look suspicious, (say there's a slowdown
129 reported in the text tests, but you think the text test shouldn't be
130 affected), then you can force more iterations to be tested for only
131 those tests:
132
133     ./cairo-perf-diff -f HEAD -- text
134
135 Generating comparisons of different backends
136 --------------------------------------------
137 An alternate question that is often asked is, "how does the speed of one
138 backend compare to another?". cairo-perf-compare-backends can read files
139 generated by cairo-perf and produces a comparison of the backends for every
140 test.
141
142 Again, by way of example:
143
144     # Show relative performance of the backends
145     ./cairo-perf-compare-backends cairo.perf
146
147 This will work whether the data files were generate in raw mode (with
148 cairo-perf -r) or cooked, (cairo-perf without -r).
149
150
151 Creating a new performance test
152 -------------------------------
153 This is where we could use everybody's help. If you have encountered a
154 sequence of cairo operations that are slower than you would like, then
155 please provide a performance test. Writing a test is very simple, it
156 requires you to write only a small C file with a couple of functions,
157 one of which exercises the cairo calls of interest.
158
159 Here is the basic structure of a performance test file:
160
161     /* Copyright © 2006 Kind Cairo User
162      *
163      * ... Licensing information here ...
164      * Please copy the MIT blurb as in other tests
165      */
166
167     #include "cairo-perf.h"
168
169     static cairo_time_t
170     do_my_new_test (cairo_t *cr, int width, int height)
171     {
172         cairo_perf_timer_start ();
173
174         /* Make the cairo calls to be measured */
175
176         cairo_perf_timer_stop ();
177
178         return cairo_perf_timer_elapsed ();
179     }
180
181     void
182     my_new_test (cairo_perf_t *perf, cairo_t *cr, int width, int height)
183     {
184         /* First do any setup for which the execution time should not
185          * be measured. For example, this might include loading
186          * images from disk, creating patterns, etc. */
187
188         /* Then launch the actual performance testing. */
189         cairo_perf_run (perf, "my_new_test", do_my_new_test);
190
191         /* Finally, perform any cleanup from the setup above. */
192     }
193
194 That's really all there is to writing a new test. The first function
195 above is the one that does the real work and returns a timing
196 number. The second function is the one that will be called by the
197 performance test rig (see below for how to accomplish that), and
198 allows for multiple performance cases to be written in one file,
199 (simply call cairo_perf_run once for each case, passing the
200 appropriate callback function to each).
201
202 We go through this dance of indirectly calling your own function
203 through cairo_perf_run so that cairo_perf_run can call your function
204 many times and measure statistical properties over the many runs.
205
206 Finally, to fully integrate your new test case you just need to add
207 your new test to three different lists. (TODO: We should set this up
208 better so that the lists are maintained automatically---computed from
209 the list of files in cairo/perf, for example). Here's what needs to be
210 added:
211
212  1. Makefile.am: Add the new file name to the cairo_perf_SOURCES list
213
214  2. cairo-perf.h: Add a new CAIRO_PERF_DECL line with the name of your
215     function, (my_new_test in the example above)
216
217  3. cairo-perf-micro.c: Add a new row to the list at the end of the
218     file. A typical entry would look like:
219
220         { my_new_test, 16, 64 }
221
222     The last two numbers are a minimum and a maximum image size at
223     which your test should be exercised. If these values are the same,
224     then only that size will be used. If they are different, then
225     intermediate sizes will be used by doubling. So in the example
226     above, three tests would be performed at sizes of 16x16, 32x32 and
227     64x64.
228
229
230 How to record new traces
231 -----------------------
232 Using cairo-trace you can record the exact sequence of graphic operations
233 made by an application and replay them later. These traces can then be
234 used by cairo-perf-trace to benchmark the various backends and patches.
235
236 To record a trace:
237 $ cairo-trace --no-mark-dirty --no-callers $APPLICATION [$ARGV]
238
239 --no-mark-dirty is useful for applications that are paranoid about
240 surfaces being modified by external plugins outside of their control, the
241 prime example here is firefox.
242 --no-callers disables the symbolic caller lookup and so speeds tracing
243 (dramatically for large c++ programs) and similarly speeds up the replay
244 as the files are much smaller.
245
246 The output file will be called $APPLICATION.$PID.trace, the actual path
247 written to will be displayed on the terminal.
248
249 Alternatively you can use:
250 $ cairo-trace --profile $APPLICATION [$ARGV]
251 which automatically passes --no-mark-dirty and --no-callers and compresses
252 the resultant trace using LZMA. To use the trace with cairo-perf-trace you
253 will first need to decompress it.
254
255 Then to use cairo-perf-trace:
256 $ ./cairo-perf-trace $APPLICATION.$PID.trace
257
258 Alternatively you can put the trace into perf/cairo-traces, or set
259 CAIRO_TRACE_DIR to point to your trace directory, and the trace will be
260 included in the performance tests.
261
262 If you record an interesting trace, please consider sharing it by compressing
263 it, LZMA preferred, and posting a link to cairo@cairographics.org, or by
264 uploading it to git.cairographics.org/cairo-traces.
265
266
267 How to run cairo-perf-diff on WINDOWS
268 -------------------------------------
269 This section explains the specifics of running cairo-perf-diff under
270 win32 plateforms. It assumes that you have installed a UNIX-like shell
271 environment such as MSYS (distributed as part of MinGW).
272
273  1. From your Mingw32 window, be sure to have all of your MSVC environ-
274     ment variables set up for proper compilation using 'make'
275
276  2. Add the %GitBaseDir%/Git/bin path to your environment, replacing the 
277     %GitBaseDir% by whatever directory your Git version is installed to.
278
279  3. Comment out the "UNSET CDPATH" line in the git-sh-setup script 
280     (located inside the ...Git/bin directory) by putting a "#" at the 
281     beginning of the line.
282
283 you should be ready to go !
284
285 From your mingw32 window, go to your cairo/perf directory and run the 
286 cairo-perf-diff script with the right arguments.
287
288 Thanks for your contributions and have fun with cairo!