diff options
author | Aaron Plattner <aplattner@nvidia.com> | 2009-11-29 15:05:41 -0800 |
---|---|---|
committer | Aaron Plattner <aplattner@nvidia.com> | 2009-11-29 15:05:41 -0800 |
commit | bc955e0d3b51745203cfcadcef9636390883da9b (patch) | |
tree | 30f2f180a2cee480a87d1176606430224c3d5cfe | |
parent | 22eaa2e3cdb42fdb8dc391e786ae272212b90f20 (diff) |
Add a -time option to control the test time
-rw-r--r-- | main.c | 17 | ||||
-rw-r--r-- | utils.c | 14 |
2 files changed, 27 insertions, 4 deletions
@@ -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); @@ -6,6 +6,7 @@ #include <X11/Xlib.h> #include <X11/extensions/Xrender.h> +#include <math.h> #include <sys/time.h> #include <time.h> #include <signal.h> @@ -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; } |