mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-01-06 05:00:17 +01:00
perf: Collapse timing.[ch] down into cairo-perf.[ch]
This commit is contained in:
parent
a60ed68dae
commit
13bcba68ae
8 changed files with 77 additions and 144 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <cworth@cworth.org>
|
||||
* Authors: Vladimir Vukicevic <vladimir@pobox.com>
|
||||
* Carl Worth <cworth@cworth.org>
|
||||
*/
|
||||
|
||||
#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[])
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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 <cworth@cworth.org>
|
||||
* Authors: Vladimir Vukicevic <vladimir@pobox.com>
|
||||
* Carl Worth <cworth@cworth.org>
|
||||
*/
|
||||
|
||||
#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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "timing.h"
|
||||
#include "cairo-perf.h"
|
||||
|
||||
/* timers */
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 <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);
|
||||
}
|
||||
|
|
@ -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 <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
|
||||
Loading…
Add table
Reference in a new issue