From 13bcba68ae6f0d29b82def09e7a6e356266dc2e7 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Thu, 31 Aug 2006 10:39:24 -0700 Subject: [PATCH] perf: Collapse timing.[ch] down into cairo-perf.[ch] --- perf/Makefile.am | 2 -- perf/cairo-perf.c | 40 +++++++++++++++++++---- perf/cairo-perf.h | 49 ++++++++++++++++++++++++----- perf/paint.c | 1 - perf/timer-alarm-posix.c | 2 +- perf/timer-alarm-win32.c | 3 -- perf/timing.c | 56 --------------------------------- perf/timing.h | 68 ---------------------------------------- 8 files changed, 77 insertions(+), 144 deletions(-) delete mode 100644 perf/timing.c delete mode 100644 perf/timing.h diff --git a/perf/Makefile.am b/perf/Makefile.am index f9124c585..d5412aa3e 100644 --- a/perf/Makefile.am +++ b/perf/Makefile.am @@ -16,8 +16,6 @@ noinst_PROGRAMS = cairo-perf cairo_perf_SOURCES = \ cairo-perf.c \ cairo-perf.h \ - timing.c \ - timing.h \ timer-alarm.h \ paint.c diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c index 14f2d5795..e69bb2bf6 100644 --- a/perf/cairo-perf.c +++ b/perf/cairo-perf.c @@ -1,4 +1,5 @@ /* + * Copyright © 2006 Mozilla Corporation * Copyright © 2006 Red Hat, Inc. * * Permission to use, copy, modify, distribute, and sell this software @@ -6,26 +7,29 @@ * 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 - * Red Hat, Inc. 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. Red Hat, Inc. 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. * - * RED HAT, INC. 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 RED HAT, INC. 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: Carl D. Worth + * Authors: Vladimir Vukicevic + * Carl Worth */ #include "cairo-perf.h" -unsigned int iterations = 0; +int cairo_perf_duration = -1; + +int alarm_expired = 0; typedef struct _cairo_perf { const char *name; @@ -76,6 +80,30 @@ target_is_measurable (cairo_test_target_t *target) } } +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); +} + int main (int argc, char *argv[]) { diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h index 3fc235fa3..75ab975b0 100644 --- a/perf/cairo-perf.h +++ b/perf/cairo-perf.h @@ -1,4 +1,5 @@ /* + * Copyright © 2006 Mozilla Corporation * Copyright © 2006 Red Hat, Inc. * * Permission to use, copy, modify, distribute, and sell this software @@ -6,21 +7,22 @@ * 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 - * Red Hat, Inc. 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. Red Hat, Inc. 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. * - * RED HAT, INC. 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 RED HAT, INC. 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: Carl D. Worth + * Authors: Vladimir Vukicevic + * Carl Worth */ #ifndef _CAIRO_PERF_H_ @@ -28,9 +30,42 @@ #include "cairo-boilerplate.h" -#include "timing.h" +#include "timer-alarm.h" -extern unsigned int iterations; +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); typedef void (*cairo_perf_func_t) (cairo_t *cr, int width, int height); diff --git a/perf/paint.c b/perf/paint.c index c4233df46..41983da7a 100644 --- a/perf/paint.c +++ b/perf/paint.c @@ -46,7 +46,6 @@ paint (cairo_t *cr, int width, int height) PERF_LOOP_INIT (timer, count); { cairo_paint (cr); - iterations++; } PERF_LOOP_FINI (timer, count); diff --git a/perf/timer-alarm-posix.c b/perf/timer-alarm-posix.c index 161d1be55..7fe04517a 100644 --- a/perf/timer-alarm-posix.c +++ b/perf/timer-alarm-posix.c @@ -29,7 +29,7 @@ #include #include -#include "timing.h" +#include "cairo-perf.h" /* timers */ diff --git a/perf/timer-alarm-win32.c b/perf/timer-alarm-win32.c index 70fc8a9ef..fc1ad90c4 100644 --- a/perf/timer-alarm-win32.c +++ b/perf/timer-alarm-win32.c @@ -56,9 +56,6 @@ timer_elapsed (bench_timer_t *tr) { } /* alarms */ -int test_seconds = -1; - -int alarm_expired = 0; void CALLBACK alarm_handler (void *closure, DWORD dwTimerLowValue, DWORD dwTimerHighValue) { diff --git a/perf/timing.c b/perf/timing.c deleted file mode 100644 index 20318d8e9..000000000 --- a/perf/timing.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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 - * Carl Worth - */ - -#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 deleted file mode 100644 index 9b73438bf..000000000 --- a/perf/timing.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 - * Carl Worth - */ - -#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