diff options
-rw-r--r-- | boilerplate/cairo-boilerplate.h | 1 | ||||
-rw-r--r-- | perf/Makefile.am | 9 | ||||
-rw-r--r-- | perf/cairo-bench.h | 110 | ||||
-rw-r--r-- | perf/cairo-perf.h | 6 | ||||
-rw-r--r-- | perf/paint.c | 9 | ||||
-rw-r--r-- | perf/timer-alarm-posix.c | 70 | ||||
-rw-r--r-- | perf/timer-alarm-win32.c | 79 | ||||
-rw-r--r-- | perf/timer-alarm.h | 65 | ||||
-rw-r--r-- | perf/timing.c | 56 | ||||
-rw-r--r-- | perf/timing.h | 68 | ||||
-rw-r--r-- | perf/util.c | 12 |
11 files changed, 364 insertions, 121 deletions
diff --git a/boilerplate/cairo-boilerplate.h b/boilerplate/cairo-boilerplate.h index 7f8f0ed7..48103533 100644 --- a/boilerplate/cairo-boilerplate.h +++ b/boilerplate/cairo-boilerplate.h @@ -31,6 +31,7 @@ #endif #include <stdio.h> +#include <stdlib.h> #include <math.h> #include <cairo.h> #include <string.h> diff --git a/perf/Makefile.am b/perf/Makefile.am index 08223caf..f9124c58 100644 --- a/perf/Makefile.am +++ b/perf/Makefile.am @@ -16,8 +16,17 @@ noinst_PROGRAMS = cairo-perf cairo_perf_SOURCES = \ cairo-perf.c \ cairo-perf.h \ + timing.c \ + timing.h \ + timer-alarm.h \ paint.c +if CAIRO_HAS_WIN32_SURFACE +cairo_perf_SOURCES += timer-alarm-win32.c +else +cairo_perf_SOURCES += timer-alarm-posix.c +endif + LDADD = $(top_builddir)/boilerplate/libcairoboilerplate.la \ $(top_builddir)/src/libcairo.la diff --git a/perf/cairo-bench.h b/perf/cairo-bench.h deleted file mode 100644 index 076b7c15..00000000 --- a/perf/cairo-bench.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright © 2006 Mozilla Corporation - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without - * fee, provided that the above copyright notice appear in all copies - * and that both that copyright notice and this permission notice - * appear in supporting documentation, and that the name of - * Mozilla Corporation not be used in advertising or publicity pertaining to - * distribution of the software without specific, written prior - * permission. Mozilla Corporation makes no representations about the - * suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * MOZILLA CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL MOZILLA CORPORATION BE LIABLE FOR ANY SPECIAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR - * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Vladimir Vukicevic <vladimir@pobox.com> - */ - -#ifndef CAIRO_BENCH_H_ -#define CAIRO_BENCH_H_ - -#ifndef USE_WINAPI -#include <sys/time.h> -#endif - -#include <cairo.h> - -#include "surface-boilerplate.h" - -extern int num_benchmarks; - -char *content_name (cairo_content_t content); -cairo_content_t content_for_name (const char *content); - -/* results */ - -typedef struct _bench_result_t bench_result_t; - -struct _bench_result_t { - cairo_test_target_t *target; - double *results; - - bench_result_t *next; -}; - -/* timers */ - -typedef struct { -#ifdef USE_WINAPI - LARGE_INTEGER start; - LARGE_INTEGER stop; -#else - struct timeval start; - struct timeval stop; -#endif - long count; -} bench_timer_t; - -extern int alarm_expired; - -void timer_start (bench_timer_t *tr); -void timer_stop (bench_timer_t *tr); -double timer_elapsed (bench_timer_t *tr); - -void set_alarm (int seconds); -void start_timing (bench_timer_t *tr, long *count); -void stop_timing (bench_timer_t *tr, long count); -double timing_result (bench_timer_t *tr); - -#ifdef USE_WINAPI -// Windows needs a SleepEx to put the thread into an alertable state, -// such that the timer expiration callback can fire. I can't figure -// out how to do an async timer. On a quiet system, this doesn't -// seem to significantly affect the results. -#define BEGIN_TIMING_LOOP(timervar,countvar) do { \ - countvar = 0; \ - start_timing(&(timervar), &(countvar)); \ - while (!alarm_expired) { \ - SleepEx(0, TRUE); - -#else - -#define BEGIN_TIMING_LOOP(timervar,countvar) do { \ - countvar = 0; \ - start_timing(&(timervar), &(countvar)); \ - while (!alarm_expired) { - -#endif - -#define END_TIMING_LOOP(timervar,countvar) \ - (countvar)++; \ - } \ - stop_timing (&(timervar), (countvar)); \ - } while (0); - -/* arg parsing */ -int parse_args (int argc, char **argv, int **tests, cairo_test_target_t ***targets); - -#ifndef CAIRO_HAS_PNG_FUNCTIONS -cairo_status_t cairo_surface_write_to_png (cairo_surface_t *surface, const char *filename); -#endif - -#endif /* CAIRO_BENCH_H_ */ diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h index b5d9b7ed..3fc235fa 100644 --- a/perf/cairo-perf.h +++ b/perf/cairo-perf.h @@ -28,6 +28,8 @@ #include "cairo-boilerplate.h" +#include "timing.h" + extern unsigned int iterations; typedef void (*cairo_perf_func_t) (cairo_t *cr, int width, int height); @@ -38,8 +40,4 @@ DECL_PERF_FUNC (paint_setup); DECL_PERF_FUNC (paint_alpha_setup); DECL_PERF_FUNC (paint); -/* XXX: Obviously bogus as we bring up the infrastructure. */ -#define PERF_LOOP_INIT do { -#define PERF_LOOP_FINI } while (0); - #endif diff --git a/perf/paint.c b/perf/paint.c index 5c00e5c0..c4233df4 100644 --- a/perf/paint.c +++ b/perf/paint.c @@ -40,10 +40,15 @@ paint_alpha_setup (cairo_t *cr, int width, int height) void paint (cairo_t *cr, int width, int height) { - PERF_LOOP_INIT; + bench_timer_t timer; + long count; + + PERF_LOOP_INIT (timer, count); { cairo_paint (cr); iterations++; } - PERF_LOOP_FINI; + PERF_LOOP_FINI (timer, count); + + printf ("Rate: %g\n", timing_result (&timer)); } diff --git a/perf/timer-alarm-posix.c b/perf/timer-alarm-posix.c new file mode 100644 index 00000000..161d1be5 --- /dev/null +++ b/perf/timer-alarm-posix.c @@ -0,0 +1,70 @@ +/* + * Copyright © 2006 Mozilla Corporation + * Copyright © 2006 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * the authors not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. The authors make no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Authors: Vladimir Vukicevic <vladimir@pobox.com> + * Carl Worth <cworth@cworth.org> + */ + +#include <signal.h> +#include <sys/time.h> +#include <unistd.h> + +#include "timing.h" + +/* timers */ + +void +timer_start (bench_timer_t *tr) { + gettimeofday (&tr->start, NULL); +} + +void +timer_stop (bench_timer_t *tr) { + gettimeofday (&tr->stop, NULL); +} + +double +timer_elapsed (bench_timer_t *tr) { + double d; + + d = tr->stop.tv_sec - tr->start.tv_sec; + d += (tr->stop.tv_usec - tr->start.tv_usec) / 1000000.0; + + return d; +} + +/* alarms */ + +void +alarm_handler (int signal) { + if (signal == SIGALRM) { + alarm_expired = 1; + } +} + +void +set_alarm (int seconds) { + alarm_expired = 0; + signal (SIGALRM, alarm_handler); + alarm (seconds); +} diff --git a/perf/timer-alarm-win32.c b/perf/timer-alarm-win32.c new file mode 100644 index 00000000..70fc8a9e --- /dev/null +++ b/perf/timer-alarm-win32.c @@ -0,0 +1,79 @@ +/* + * Copyright © 2006 Mozilla Corporation + * Copyright © 2006 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * the authors not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. The authors make no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Authors: Vladimir Vukicevic <vladimir@pobox.com> + * Carl Worth <cworth@cworth.org> + */ + +#define USE_WINAPI + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +#include "cairo-perf.h" + +/* timers */ + +void +timer_start (bench_timer_t *tr) { + QueryPerformanceCounter(&tr->start); +} + +void +timer_stop (bench_timer_t *tr) { + QueryPerformanceCounter(&tr->stop); +} + +double +timer_elapsed (bench_timer_t *tr) { + double d; + LARGE_INTEGER freq; + + QueryPerformanceFrequency(&freq); + + d = (tr->stop.QuadPart - tr->start.QuadPart) / (double) freq.QuadPart; + return d; +} + +/* alarms */ +int test_seconds = -1; + +int alarm_expired = 0; + +void CALLBACK +alarm_handler (void *closure, DWORD dwTimerLowValue, DWORD dwTimerHighValue) { + alarm_expired = 1; +} + +HANDLE hTimer = NULL; +void +set_alarm (int seconds) { + if (hTimer == NULL) + hTimer = CreateWaitableTimer(NULL, TRUE, NULL); + alarm_expired = 0; + + LARGE_INTEGER expTime; + expTime.QuadPart = - (seconds * 10000000); + if (!SetWaitableTimer (hTimer, &expTime, 0, alarm_handler, &alarm_expired, FALSE)) + fprintf (stderr, "SetWaitableTimer failed!\n"); +} diff --git a/perf/timer-alarm.h b/perf/timer-alarm.h new file mode 100644 index 00000000..942bc282 --- /dev/null +++ b/perf/timer-alarm.h @@ -0,0 +1,65 @@ +/* + * Copyright © 2006 Mozilla Corporation + * Copyright © 2006 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * the authors not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. The authors make no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Authors: Vladimir Vukicevic <vladimir@pobox.com> + * Carl Worth <cworth@cworth.org> + */ + +#ifndef _TIMER_ALARM_H_ +#define _TIMER_ALARM_H_ + +#include "cairo-perf.h" + +/* timers */ + +typedef struct { +#ifdef USE_WINAPI + LARGE_INTEGER start; + LARGE_INTEGER stop; +#else + struct timeval start; + struct timeval stop; +#endif + long count; +} bench_timer_t; + +extern int alarm_expired; + +void +timer_start (bench_timer_t *tr); + +void +timer_stop (bench_timer_t *tr); + +double +timer_elapsed (bench_timer_t *tr); + +/* alarms */ + +void +alarm_handler (int signal); + +void +set_alarm (int seconds); + +#endif diff --git a/perf/timing.c b/perf/timing.c new file mode 100644 index 00000000..20318d8e --- /dev/null +++ b/perf/timing.c @@ -0,0 +1,56 @@ +/* + * Copyright © 2006 Mozilla Corporation + * Copyright © 2006 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * the authors not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. The authors make no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Authors: Vladimir Vukicevic <vladimir@pobox.com> + * Carl Worth <cworth@cworth.org> + */ + +#include "timing.h" + +int cairo_perf_duration = -1; + +int alarm_expired = 0; + +void +start_timing (bench_timer_t *tr, long *count) { + if (cairo_perf_duration == -1) { + if (getenv("CAIRO_PERF_DURATION")) + cairo_perf_duration = strtol(getenv("CAIRO_PERF_DURATION"), NULL, 0); + else + cairo_perf_duration = 5; + } + *count = 0; + timer_start (tr); + set_alarm (cairo_perf_duration); +} + +void +stop_timing (bench_timer_t *tr, long count) { + timer_stop (tr); + tr->count = count; +} + +double +timing_result (bench_timer_t *tr) { + return tr->count / timer_elapsed (tr); +} diff --git a/perf/timing.h b/perf/timing.h new file mode 100644 index 00000000..9b73438b --- /dev/null +++ b/perf/timing.h @@ -0,0 +1,68 @@ +/* + * Copyright © 2006 Mozilla Corporation + * Copyright © 2006 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * the authors not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. The authors make no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Authors: Vladimir Vukicevic <vladimir@pobox.com> + * Carl Worth <cworth@cworth.org> + */ + +#ifndef _TIMING_H_ +#define _TIMING_H_ + +#include "timer-alarm.h" + +extern int cairo_perf_duration; +extern int alarm_expired; + +void +start_timing (bench_timer_t *tr, long *count); + +void +stop_timing (bench_timer_t *tr, long count); + +double +timing_result (bench_timer_t *tr); + +#if CAIRO_HAS_WIN32_SURFACE +// Windows needs a SleepEx to put the thread into an alertable state, +// such that the timer expiration callback can fire. I can't figure +// out how to do an async timer. On a quiet system, this doesn't +// seem to significantly affect the results. +# define PERF_LOOP_INIT(timervar,countvar) do { \ + countvar = 0; \ + start_timing(&(timervar), &(countvar)); \ + while (!alarm_expired) { \ + SleepEx(0, TRUE); +#else +# define PERF_LOOP_INIT(timervar,countvar) do { \ + countvar = 0; \ + start_timing(&(timervar), &(countvar)); \ + while (!alarm_expired) { +#endif + +#define PERF_LOOP_FINI(timervar,countvar) \ + (countvar)++; \ + } \ + stop_timing (&(timervar), (countvar)); \ + } while (0); + +#endif diff --git a/perf/util.c b/perf/util.c index a786df7b..af1a2ef8 100644 --- a/perf/util.c +++ b/perf/util.c @@ -1,26 +1,28 @@ /* * Copyright © 2006 Mozilla Corporation + * Copyright © 2006 Red Hat, Inc. * * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose is hereby granted without * fee, provided that the above copyright notice appear in all copies * and that both that copyright notice and this permission notice * appear in supporting documentation, and that the name of - * Mozilla Corporation not be used in advertising or publicity pertaining to + * the authors not be used in advertising or publicity pertaining to * distribution of the software without specific, written prior - * permission. Mozilla Corporation makes no representations about the + * permission. The authors make no representations about the * suitability of this software for any purpose. It is provided "as * is" without express or implied warranty. * - * MOZILLA CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL MOZILLA CORPORATION BE LIABLE FOR ANY SPECIAL, + * FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * Author: Vladimir Vukicevic <vladimir@pobox.com> + * Authors: Vladimir Vukicevic <vladimir@pobox.com> + * Carl Worth <cworth@cworth.org> */ #define _GNU_SOURCE |