diff --git a/perf/util.c b/perf/util.c deleted file mode 100644 index af1a2ef82..000000000 --- a/perf/util.c +++ /dev/null @@ -1,177 +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 - */ - -#define _GNU_SOURCE - -#ifdef USE_WINAPI -#define WIN32_LEAN_AND_MEAN -#include -#endif - -#include -#include -#include -#include -#include - -#ifndef USE_WINAPI -#include -#include -#endif - -#include "cairo-bench.h" - -/* helpers */ - -char * -content_name (cairo_content_t content) -{ - if (content == CAIRO_CONTENT_COLOR) return "rgb"; - if (content == CAIRO_CONTENT_COLOR_ALPHA) return "argb"; - if (content == CAIRO_CONTENT_ALPHA) return "a8"; - assert (0); - return NULL; -} - -cairo_content_t -content_for_name (const char *content) -{ - if (strcmp(content, "rgb") == 0) return CAIRO_CONTENT_COLOR; - if (strcmp(content, "argb") == 0) return CAIRO_CONTENT_COLOR_ALPHA; - if (strcmp(content, "a8") == 0) return CAIRO_CONTENT_ALPHA; - return (cairo_content_t) -1; -} - -/* timers */ - -#ifdef USE_WINAPI -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; -} -#else -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; -} -#endif - -/* alarms */ -int test_seconds = -1; - -int alarm_expired = 0; - -#ifdef USE_WINAPI -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"); -} -#else -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); -} -#endif - -/* timers + alarms! */ - -void -start_timing (bench_timer_t *tr, long *count) { - if (test_seconds == -1) { - if (getenv("TEST_SECONDS")) - test_seconds = strtol(getenv("TEST_SECONDS"), NULL, 0); - else - test_seconds = 5; - } - *count = 0; - timer_start (tr); - set_alarm (test_seconds); -} - -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); -}