diff --git a/gfx/context/drm_egl_ctx.c b/gfx/context/drm_egl_ctx.c index 72a346b39a..07e160f5f1 100644 --- a/gfx/context/drm_egl_ctx.c +++ b/gfx/context/drm_egl_ctx.c @@ -101,14 +101,44 @@ void gfx_ctx_check_window(bool *quit, *quit = g_quit; } -static void page_flip_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, void *data) +static unsigned first_page_flip; +static unsigned last_page_flip; +static uint64_t first_usec; +static uint64_t last_usec; + +static unsigned missed_vblanks; +static unsigned hit_vblanks; + +static void page_flip_handler(int fd, unsigned frame, unsigned sec, unsigned usec, void *data) { (void)fd; (void)frame; (void)sec; (void)usec; - - //fprintf(stderr, "Frame: %u, Time (ms). %.3f\n", frame, sec * 1000.0 + usec / 1000.0); + + uint64_t current_usec = (uint64_t)sec * 1000000 + usec; + if (!first_page_flip) + { + first_page_flip = frame; + first_usec = current_usec; + } + + if (last_page_flip) + { + unsigned missed = frame - last_page_flip - 1; + if (!missed) + hit_vblanks++; + else + { + RARCH_LOG("[KMS/EGL]: Missed %u VBlank(s) (Frame: %u).\n", + missed, frame - first_page_flip); + missed_vblanks += missed; + } + } + + last_page_flip = frame; + last_usec = current_usec; + bool *waiting = (bool*)data; *waiting = false; @@ -516,6 +546,16 @@ void gfx_ctx_destroy(void) drmClose(g_drm_fd); g_drm_fd = -1; + unsigned frames = last_page_flip - first_page_flip; + if (frames) + { + uint64_t usec = last_usec - first_usec; + RARCH_WARN("[KMS/EGL]: Estimated monitor FPS: %.5f Hz\n", 1000000.0 * frames / usec); + } + + RARCH_WARN("[KMS/EGL]: Performance stats: Missed VBlanks: %u, Perfect VBlanks: %u\n", + missed_vblanks, hit_vblanks); + // Reinitialization fails for now ... //g_inited = false; }