summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Clark <robdclark@chromium.org>2020-03-01 10:09:11 -0800
committerRob Clark <robdclark@chromium.org>2020-03-07 09:22:17 -0800
commit301a556b8ece755bbf4f8ec3657e66e0a1dd327f (patch)
tree85271ae1f76ef74bced2b25f49ad511f2e6077ea
parent163a0b061d3672bc5e0338b16fa11eaa53f63c77 (diff)
add fps reporting
-rw-r--r--common.c8
-rw-r--r--common.h6
-rw-r--r--drm-atomic.c20
-rw-r--r--drm-legacy.c20
4 files changed, 54 insertions, 0 deletions
diff --git a/common.c b/common.c
index b60b833..32fe46a 100644
--- a/common.c
+++ b/common.c
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include "common.h"
@@ -357,3 +358,10 @@ int link_program(unsigned program)
return 0;
}
+
+int64_t get_time_ns(void)
+{
+ struct timespec tv;
+ clock_gettime(CLOCK_MONOTONIC, &tv);
+ return tv.tv_nsec + tv.tv_sec * NSEC_PER_SEC;
+}
diff --git a/common.h b/common.h
index d7c3e50..d2216e0 100644
--- a/common.h
+++ b/common.h
@@ -174,4 +174,10 @@ init_cube_video(const struct gbm *gbm, const char *video, int samples)
}
#endif
+#define NSEC_PER_SEC (INT64_C(1000) * USEC_PER_SEC)
+#define USEC_PER_SEC (INT64_C(1000) * MSEC_PER_SEC)
+#define MSEC_PER_SEC INT64_C(1000)
+
+int64_t get_time_ns(void);
+
#endif /* _COMMON_H */
diff --git a/drm-atomic.c b/drm-atomic.c
index 0f04268..d84dcfc 100644
--- a/drm-atomic.c
+++ b/drm-atomic.c
@@ -180,6 +180,7 @@ static int atomic_run(const struct gbm *gbm, const struct egl *egl)
struct drm_fb *fb;
uint32_t i = 0;
uint32_t flags = DRM_MODE_ATOMIC_NONBLOCK;
+ int64_t start_time, report_time, cur_time;
int ret;
if (egl_check(egl, eglDupNativeFenceFDANDROID) ||
@@ -192,6 +193,8 @@ static int atomic_run(const struct gbm *gbm, const struct egl *egl)
/* Allow a modeset change for the first commit only. */
flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
+ start_time = report_time = get_time_ns();
+
while (1) {
struct gbm_bo *next_bo;
EGLSyncKHR gpu_fence = NULL; /* out-fence from gpu, in-fence to kms */
@@ -212,6 +215,13 @@ static int atomic_run(const struct gbm *gbm, const struct egl *egl)
egl->eglWaitSyncKHR(egl->display, kms_fence, 0);
}
+ /* Start fps measuring on second frame, to remove the time spent
+ * compiling shader, etc, from the fps:
+ */
+ if (i == 1) {
+ start_time = report_time = get_time_ns();
+ }
+
egl->draw(i++);
/* insert fence to be singled in cmdstream.. this fence will be
@@ -258,6 +268,16 @@ static int atomic_run(const struct gbm *gbm, const struct egl *egl)
egl->eglDestroySyncKHR(egl->display, kms_fence);
}
+ cur_time = get_time_ns();
+ if (cur_time > (report_time + 2 * NSEC_PER_SEC)) {
+ double elapsed_time = cur_time - start_time;
+ double secs = elapsed_time / (double)NSEC_PER_SEC;
+ unsigned frames = i - 1; /* first frame ignored */
+ printf("Rendered %u frames in %f sec (%f fps)\n",
+ frames, secs, (double)frames/secs);
+ report_time = cur_time;
+ }
+
/* Check for user input: */
struct pollfd fdset[] = { {
.fd = STDIN_FILENO,
diff --git a/drm-legacy.c b/drm-legacy.c
index 56a0fed..e136c8a 100644
--- a/drm-legacy.c
+++ b/drm-legacy.c
@@ -51,6 +51,7 @@ static int legacy_run(const struct gbm *gbm, const struct egl *egl)
struct gbm_bo *bo;
struct drm_fb *fb;
uint32_t i = 0;
+ int64_t start_time, report_time, cur_time;
int ret;
eglSwapBuffers(egl->display, egl->surface);
@@ -69,10 +70,19 @@ static int legacy_run(const struct gbm *gbm, const struct egl *egl)
return ret;
}
+ start_time = report_time = get_time_ns();
+
while (1) {
struct gbm_bo *next_bo;
int waiting_for_flip = 1;
+ /* Start fps measuring on second frame, to remove the time spent
+ * compiling shader, etc, from the fps:
+ */
+ if (i == 1) {
+ start_time = report_time = get_time_ns();
+ }
+
egl->draw(i++);
eglSwapBuffers(egl->display, egl->surface);
@@ -114,6 +124,16 @@ static int legacy_run(const struct gbm *gbm, const struct egl *egl)
drmHandleEvent(drm.fd, &evctx);
}
+ cur_time = get_time_ns();
+ if (cur_time > (report_time + 2 * NSEC_PER_SEC)) {
+ double elapsed_time = cur_time - start_time;
+ double secs = elapsed_time / (double)NSEC_PER_SEC;
+ unsigned frames = i - 1; /* first frame ignored */
+ printf("Rendered %u frames in %f sec (%f fps)\n",
+ frames, secs, (double)frames/secs);
+ report_time = cur_time;
+ }
+
/* release last buffer to render on again: */
gbm_surface_release_buffer(gbm->surface, bo);
bo = next_bo;