summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@gnugeneration.com>2016-11-23 19:17:46 -0800
committerVito Caputo <vcaputo@gnugeneration.com>2016-11-23 19:18:20 -0800
commite3d3c06aa5b47648c0ed145279d7950df42ad80d (patch)
tree32753b863e6df291e62885f5dbe6add9f76ed916
parent46a41227ab8f10ecbcb3d960703986692b64b62d (diff)
fps: add rudimentary FPS counter
This is just the implementation, nothing leveraged yet.
-rw-r--r--fps.c46
-rw-r--r--fps.h9
2 files changed, 55 insertions, 0 deletions
diff --git a/fps.c b/fps.c
new file mode 100644
index 0000000..99a3f85
--- /dev/null
+++ b/fps.c
@@ -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;
+}
diff --git a/fps.h b/fps.h
new file mode 100644
index 0000000..1f986c7
--- /dev/null
+++ b/fps.h
@@ -0,0 +1,9 @@
+#ifndef _FPS_H
+#define _FPS_H
+
+#include "fb.h"
+
+int fps_setup(void);
+void fps_print(fb_t *fb);
+
+#endif
© All Rights Reserved