From bc955e0d3b51745203cfcadcef9636390883da9b Mon Sep 17 00:00:00 2001 From: Aaron Plattner Date: Sun, 29 Nov 2009 15:05:41 -0800 Subject: Add a -time option to control the test time --- main.c | 17 ++++++++++++++++- utils.c | 14 +++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index d20aad0..870ca97 100644 --- a/main.c +++ b/main.c @@ -18,6 +18,7 @@ Display *disp = NULL; Window win; int test_type = AllTests; Bool useARGBWindow; +double test_time = 2.0; RenderOp all_render_ops[] = { {"Clear", PictOpClear, 1}, @@ -158,7 +159,9 @@ display_help() printf("\t -argb\t\tuses a 32-bit ARGB window\n"); printf("\t -ops ops\tconfigures which ops to test\n"); printf("\t -tests type\truns only specified tests\n"); - printf("\t\ttype can be: plain, alpha, mask, transformation, filter, and convolution\n"); + printf("\t\ttype can be: plain, alpha, mask, transformation, filter,\n"); + printf("\t\tand convolution\n"); + printf("\t -time sec\tcontrol the test time in seconds (default: 2 sec)\n"); printf("\t \n"); } @@ -223,6 +226,18 @@ process_args(int argc, char **argv) } else { fprintf(stderr, "Unrecognized test type: '%s'\n", arg); } + } else if (!strcmp("-time", arg)) { + ++i; + if (i == argc) { + fprintf(stderr, "Error: Must specify a time in seconds with the -time option\n"); + exit(1); + } + arg = argv[i]; + test_time = strtod(argv[i], &arg); + if (arg == argv[i] || *arg != '\0') { + fprintf(stderr, "'%s': unrecognized number\n", argv[i]); + exit(1); + } } else { display_help(); fprintf(stderr, "Unrecognized option: '%s'\n", arg); diff --git a/utils.c b/utils.c index 4a3a2b0..b0198bd 100644 --- a/utils.c +++ b/utils.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -18,6 +19,7 @@ extern int win_h; extern Display *disp; extern Window win; extern Bool useARGBWindow; +extern double test_time; static const char *const FILLER = "......................................................................"; @@ -39,11 +41,17 @@ time_test(char *description, void (*func) (int op, XRenderSurf *src, XRenderSurf RenderOp *op, XRenderSurf *src, XRenderSurf *mask, XRenderSurf *dst) { char buf[51]; + struct itimerval t; snprintf(buf, 50, "%s%s", description, FILLER); + t.it_interval.tv_sec = 0; + t.it_interval.tv_usec = 0; + t.it_value.tv_sec = floor(test_time); + t.it_value.tv_usec = (test_time - floor(test_time)) * 1000000; + printf("\t\t %s", buf); fflush(NULL); - alarm(2); + setitimer(ITIMER_REAL, &t, NULL); keep_running = 1; while (keep_running) { func(op->op, src, mask, dst); @@ -115,8 +123,8 @@ setup_window(void) void alarmhandler(int sig) { if (sig == SIGALRM) { - printf ("%d frames in 2.0 seconds = %.3f FPS\n", frame_cnt, - frame_cnt / 2.0); + printf ("%d frames in %g seconds = %.3f FPS\n", frame_cnt, test_time, + frame_cnt / test_time); frame_cnt = 0; keep_running = 0; } -- cgit v1.2.3