diff options
author | Aaron Plattner <aplattner@nvidia.com> | 2009-12-01 16:56:13 -0800 |
---|---|---|
committer | Aaron Plattner <aplattner@nvidia.com> | 2009-12-22 16:12:06 -0800 |
commit | 8a18efed83ba8d14ce093d98f8f09bbf41d01809 (patch) | |
tree | 8aec78b0c276f6fbf2b4531de296042d08832642 /utils.c | |
parent | bc955e0d3b51745203cfcadcef9636390883da9b (diff) |
Time the tests more accurately.
Instead of just using XSync, which flushes X command processing but not GPU
rendering, read back a pixel when the test is done. Compute the actual elapsed
time instead of the SIGALRM time, because very slow rendering requests may take
a long time to finish after they've been queued by the X server.
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 31 |
1 files changed, 24 insertions, 7 deletions
@@ -34,7 +34,6 @@ get_time(void) } static int keep_running = 0; -static int frame_cnt = 0; void time_test(char *description, void (*func) (int op, XRenderSurf *src, XRenderSurf *mask, XRenderSurf *dst), @@ -42,6 +41,10 @@ time_test(char *description, void (*func) (int op, XRenderSurf *src, XRenderSurf { char buf[51]; struct itimerval t; + int frame_cnt = 0; + double elapsed_time; + struct timeval start, end; + XImage *img; snprintf(buf, 50, "%s%s", description, FILLER); t.it_interval.tv_sec = 0; @@ -51,13 +54,31 @@ time_test(char *description, void (*func) (int op, XRenderSurf *src, XRenderSurf printf("\t\t %s", buf); fflush(NULL); - setitimer(ITIMER_REAL, &t, NULL); keep_running = 1; + setitimer(ITIMER_REAL, &t, NULL); + + gettimeofday(&start, NULL); + while (keep_running) { func(op->op, src, mask, dst); - XSync(disp, 0); ++frame_cnt; + // Avoid queuing up way too many X requests in case rendering is really + // slow. Otherwise, we could overshoot the target time significantly. + if (frame_cnt % 50 == 0) + XSync(disp, 0); } + + // Read back a pixel to flush any queued GPU rendering. + img = XGetImage(disp, src->draw, 0, 0, 1, 1, AllPlanes, ZPixmap); + + gettimeofday(&end, NULL); + + XDestroyImage(img); + + elapsed_time = end.tv_sec - start.tv_sec + (end.tv_usec / 1000000.0 - start.tv_usec / 1000000.0); + + printf ("%d frames in %g seconds = %.3f FPS\n", frame_cnt, elapsed_time, + frame_cnt / elapsed_time); } void @@ -123,10 +144,6 @@ setup_window(void) void alarmhandler(int sig) { if (sig == SIGALRM) { - printf ("%d frames in %g seconds = %.3f FPS\n", frame_cnt, test_time, - frame_cnt / test_time); - frame_cnt = 0; keep_running = 0; } - signal(SIGALRM, alarmhandler); } |