diff options
author | Vito Caputo <vcaputo@gnugeneration.com> | 2016-12-13 08:20:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-13 08:20:24 -0800 |
commit | 2e292bd40f67e6e2612ad93fd77cdcd3449e4892 (patch) | |
tree | 4600607eb8c12af034b2bf29eec4f8207f9413c4 /fps.c | |
parent | 3ea61db55a9c21f7621f8a64d91153cb1955b2ff (diff) | |
parent | 173cac2fe990496fca2403aa3a4bfcbd6007e7e6 (diff) |
Merge pull request #2 from vcaputo/moar
More candy
Diffstat (limited to 'fps.c')
-rw-r--r-- | fps.c | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -0,0 +1,46 @@ +#include <signal.h> +#include <stdio.h> +#include <sys/time.h> + +#include "fb.h" +#include "util.h" + + +static int print_fps; + + +static void sigalrm_handler(int signum) +{ + print_fps = 1; +} + + +int fps_setup(void) +{ + struct itimerval interval = { + .it_interval = { .tv_sec = 1, .tv_usec = 0 }, + .it_value = { .tv_sec = 1, .tv_usec = 0 }, + }; + + if (signal(SIGALRM, sigalrm_handler) == SIG_ERR) + return 0; + + if (setitimer(ITIMER_REAL, &interval, NULL) < 0) + return 0; + + return 1; +} + + +void fps_print(fb_t *fb) +{ + unsigned n; + + if (!print_fps) + return; + + fb_get_put_pages_count(fb, &n); + printf("FPS: %u\n", n); + + print_fps = 0; +} |