2 * Copyright © 2006 Red Hat, Inc.
3 * Copyright © 2009 Chris Wilson
5 * Permission to use, copy, modify, distribute, and sell this software
6 * and its documentation for any purpose is hereby granted without
7 * fee, provided that the above copyright notice appear in all copies
8 * and that both that copyright notice and this permission notice
9 * appear in supporting documentation, and that the name of the
10 * copyright holders not be used in advertising or publicity
11 * pertaining to distribution of the software without specific,
12 * written prior permission. The copyright holders make no
13 * representations about the suitability of this software for any
14 * purpose. It is provided "as is" without express or implied
17 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
18 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
22 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
23 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
26 * Authors: Carl Worth <cworth@cworth.org>
27 * Chris Wilson <chris@chris-wilson.co.uk>
30 #include "cairo-perf.h"
40 typedef struct _cairo_perf_report_options {
43 int print_change_bars;
44 } cairo_perf_report_options_t;
46 typedef struct _cairo_perf_diff_files_args {
47 const char **filenames;
49 cairo_perf_report_options_t options;
50 } cairo_perf_diff_files_args_t;
53 test_diff_cmp (const void *a,
56 const test_diff_t *a_diff = a;
57 const test_diff_t *b_diff = b;
59 /* Reverse sort by magnitude of change so larger changes come
61 if (a_diff->change > b_diff->change)
64 if (a_diff->change < b_diff->change)
70 #define CHANGE_BAR_WIDTH 70
72 print_change_bar (double change,
76 int units_per_cell = ceil (max_change / CHANGE_BAR_WIDTH);
77 static char const *ascii_boxes[8] = {
78 "****","***" ,"***", "**",
81 static char const *utf_boxes[8] = {
85 char const **boxes = use_utf ? utf_boxes : ascii_boxes;
87 /* For a 1.0x speedup we want a zero-size bar to show "no
91 while (change > units_per_cell) {
92 printf ("%s", boxes[0]);
93 change -= units_per_cell;
96 change /= units_per_cell;
99 printf ("%s", boxes[0]);
100 else if (change > 6.5/8.0)
101 printf ("%s", boxes[1]);
102 else if (change > 5.5/8.0)
103 printf ("%s", boxes[2]);
104 else if (change > 4.5/8.0)
105 printf ("%s", boxes[3]);
106 else if (change > 3.5/8.0)
107 printf ("%s", boxes[4]);
108 else if (change > 2.5/8.0)
109 printf ("%s", boxes[5]);
110 else if (change > 1.5/8.0)
111 printf ("%s", boxes[6]);
112 else if (change > 0.5/8.0)
113 printf ("%s", boxes[7]);
117 test_diff_print (test_diff_t *diff,
119 cairo_perf_report_options_t *options)
125 if (diff->tests[0]->size != 0) {
126 printf ("(%s, size: %d)\n",
127 diff->tests[0]->name,
128 diff->tests[0]->size);
130 printf ("(%s)\n", diff->tests[0]->name);
133 for (i = 0; i < diff->num_tests; i++) {
134 test_time = diff->tests[i]->stats.min_ticks;
135 test_time /= diff->tests[i]->stats.ticks_per_ms;
136 change = diff->max / test_time;
137 printf ("%8s-%s-%s\t%6.2f: %5.2fx ",
138 diff->tests[i]->backend,
139 diff->tests[i]->content,
140 diff->tests[i]->configuration,
141 diff->tests[i]->stats.min_ticks / diff->tests[i]->stats.ticks_per_ms,
144 if (options->print_change_bars)
145 print_change_bar (change, max_change, options->use_utf);
152 #define MAX(a,b) ((a) > (b) ? (a) : (b))
154 cairo_perf_reports_compare (cairo_perf_report_t *reports,
156 cairo_perf_report_options_t *options)
159 test_report_t **tests, *min_test;
160 test_diff_t *diff, *diffs;
161 int num_diffs, max_diffs;
166 tests = xmalloc (num_reports * sizeof (test_report_t *));
168 max_diffs = reports[0].tests_count;
169 for (i = 0; i < num_reports; i++) {
170 tests[i] = reports[i].tests;
171 if (reports[i].tests_count > max_diffs)
172 max_diffs = reports[i].tests_count;
175 diff = diffs = xmalloc (max_diffs * sizeof (test_diff_t));
181 /* We expect iterations values of 0 when multiple raw reports
182 * for the same test have been condensed into the stats of the
183 * first. So we just skip these later reports that have no
186 for (i = 0; i < num_reports; i++) {
187 while (tests[i]->name && tests[i]->stats.iterations == 0)
195 /* Find the minimum of all current tests, (we have to do this
196 * in case some reports don't have a particular test). */
197 for (i = 0; i < num_reports; i++) {
198 if (tests[i]->name) {
203 for (++i; i < num_reports; i++) {
204 if (tests[i]->name && test_report_cmp_name (tests[i], min_test) < 0)
209 for (i = 0; i < num_reports; i++) {
214 while (test[n].name &&
215 test_report_cmp_name (&test[n], min_test) == 0)
223 /* For each report that has the current test, record it into
224 * the diff structure. */
226 diff->tests = xmalloc (num_tests * sizeof (test_diff_t));
227 for (i = 0; i < num_reports; i++) {
228 while (tests[i]->name &&
229 test_report_cmp_name (tests[i], min_test) == 0)
231 test_time = tests[i]->stats.min_ticks;
233 test_time /= tests[i]->stats.ticks_per_ms;
234 if (diff->num_tests == 0) {
235 diff->min = test_time;
236 diff->max = test_time;
238 if (test_time < diff->min)
239 diff->min = test_time;
240 if (test_time > diff->max)
241 diff->max = test_time;
243 diff->tests[diff->num_tests++] = tests[i];
248 diff->change = diff->max / diff->min;
256 qsort (diffs, num_diffs, sizeof (test_diff_t), test_diff_cmp);
259 for (i = 0; i < num_diffs; i++) {
260 if (fabs (diffs[i].change) > max_change)
261 max_change = fabs (diffs[i].change);
264 for (i = 0; i < num_diffs; i++) {
267 /* Discard as uninteresting a change which is less than the
268 * minimum change required, (default may be overridden on
270 if (fabs (diff->change) - 1.0 < options->min_change)
273 test_diff_print (diff, max_change, options);
276 for (i = 0; i < num_diffs; i++)
277 free (diffs[i].tests);
284 usage (const char *argv0)
286 char const *basename = strrchr(argv0, '/');
287 basename = basename ? basename+1 : argv0;
289 "Usage: %s [options] file [...]\n\n",
292 "Computes significant performance differences for cairo performance reports.\n"
293 "Each file should be the output of the cairo-perf program (or \"make perf\").\n"
294 "The following options are available:\n"
296 "--no-utf Use ascii stars instead of utf-8 change bars.\n"
297 " Four stars are printed per factor of speedup.\n"
299 "--no-bars Don't display change bars at all.\n\n"
301 "--use-ms Use milliseconds to calculate differences.\n"
302 " (instead of ticks which are hardware dependent)\n"
304 "--min-change threshold[%%]\n"
305 " Suppress all changes below the given threshold.\n"
306 " The default threshold of 0.05 or 5%% ignores any\n"
307 " speedup or slowdown of 1.05 or less. A threshold\n"
308 " of 0 will cause all output to be reported.\n"
314 parse_args (int argc,
316 cairo_perf_diff_files_args_t *args)
320 for (i = 1; i < argc; i++) {
321 if (strcmp (argv[i], "--no-utf") == 0) {
322 args->options.use_utf = 0;
324 else if (strcmp (argv[i], "--no-bars") == 0) {
325 args->options.print_change_bars = 0;
327 else if (strcmp (argv[i], "--min-change") == 0) {
332 args->options.min_change = strtod (argv[i], &end);
335 args->options.min_change /= 100;
342 args->num_filenames++;
343 args->filenames = xrealloc (args->filenames,
344 args->num_filenames * sizeof (char *));
345 args->filenames[args->num_filenames - 1] = argv[i];
354 cairo_perf_diff_files_args_t args = {
355 NULL, /* filenames */
356 0, /* num_filenames */
358 0.05, /* min change */
360 1, /* display change bars? */
363 cairo_perf_report_t *reports;
367 parse_args (argc, argv, &args);
369 if (args.num_filenames) {
370 reports = xcalloc (args.num_filenames, sizeof (cairo_perf_report_t));
371 for (i = 0; i < args.num_filenames; i++) {
372 cairo_perf_report_load (&reports[i], args.filenames[i], i,
373 test_report_cmp_name);
374 printf ("loaded: %s, %d tests\n",
375 args.filenames[i], reports[i].tests_count);
378 args.num_filenames = 1;
379 reports = xcalloc (args.num_filenames, sizeof (cairo_perf_report_t));
380 cairo_perf_report_load (&reports[0], NULL, 0, test_report_cmp_name);
383 cairo_perf_reports_compare (reports, args.num_filenames, &args.options);
385 /* Pointless memory cleanup, (would be a great place for talloc) */
386 free (args.filenames);
387 for (i = 0; i < args.num_filenames; i++) {
388 for (t = reports[i].tests; t->name; t++) {
393 free (reports[i].tests);
394 free (reports[i].configuration);