From 4a2073b20c93036c9215d5ec33e3905246298ffc Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Mon, 18 Mar 2024 20:24:20 -0400 Subject: [PATCH] debug fps: log number of frames rendered in each second --- c_src/scenic/comms.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/c_src/scenic/comms.c b/c_src/scenic/comms.c index 62d804f..5321b83 100644 --- a/c_src/scenic/comms.c +++ b/c_src/scenic/comms.c @@ -399,6 +399,14 @@ void receive_crash() //--------------------------------------------------------- void render(driver_data_t* p_data) { + // Setup FPS calc + static int64_t start_real = 0; + static int64_t time_remaining = -1; + static clock_t render_fps = 0; + static uint32_t frames = 0; + + clock_t begin_frame = clock(); + // prep the id to the root scene sid_t id; id.p_data = "_root_"; @@ -420,6 +428,27 @@ void render(driver_data_t* p_data) } device_end_render(p_data); + clock_t end_frame = clock(); + clock_t delta_ticks = end_frame - begin_frame; + + if (delta_ticks > 0) { + render_fps = CLOCKS_PER_SEC / delta_ticks; + // log_debug("render_fps (cpu time): %d", render_fps); + } + + frames++; + + int64_t end_real = monotonic_time(); + int64_t delta_real = (end_real - start_real); + start_real = end_real; + time_remaining -= delta_real; + + if (time_remaining <= 0) { + log_debug("real_fps: %d", frames); + start_real = monotonic_time(); + time_remaining = 1000; + frames = 0; + } // all done send_ready();