From 7a35b1e67c7eb0bf37ae2f464a6ec541a02cd608 Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Mon, 15 Jul 2024 04:30:05 +0200 Subject: [PATCH] src/output-state.c: add a FPS debug option Logs the FPS per output every $timeout ms via wlr_log() if enabled. By default this patch does nothing unless the FPS_TIMEOUT define has been set, for example via `meson configure build -DFPS_TIMEOUT=5000`. --- include/labwc.h | 2 ++ src/output-state.c | 26 ++++++++++++++++++++++++++ src/output.c | 5 +++++ 3 files changed, 33 insertions(+) diff --git a/include/labwc.h b/include/labwc.h index 21cab83b..0a4c9793 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -371,6 +371,7 @@ struct output { struct server *server; struct wlr_output *wlr_output; struct wlr_output_state pending; + struct wl_event_source *fps_timer; struct wlr_scene_output *scene_output; struct wlr_scene_tree *layer_tree[LAB_NR_LAYERS]; struct wlr_scene_tree *layer_popup_tree; @@ -389,6 +390,7 @@ struct output { bool leased; bool gamma_lut_changed; + uint32_t frames; }; #undef LAB_NR_LAYERS diff --git a/src/output-state.c b/src/output-state.c index 602149a2..24fe02cc 100644 --- a/src/output-state.c +++ b/src/output-state.c @@ -2,9 +2,25 @@ #include #include +#include #include "labwc.h" #include "output-state.h" +//#define FPS_TIMEOUT (2 * 1000) + +#ifdef FPS_TIMEOUT +static int +handle_fps_timer(void *data) +{ + struct output *output = data; + wlr_log(WLR_DEBUG, "%s commit: avg %.2f fps", + output->wlr_output->name, (double)output->frames / (FPS_TIMEOUT / 1000)); + wl_event_source_timer_update(output->fps_timer, FPS_TIMEOUT); + output->frames = 0; + return 0; +} +#endif + void output_state_init(struct output *output) { @@ -37,8 +53,18 @@ bool wlr_output_commit(struct wlr_output *wlr_output) { struct output *output = wlr_output->data; +#ifdef FPS_TIMEOUT + if (!output->fps_timer) { + output->fps_timer = wl_event_loop_add_timer( + output->server->wl_event_loop, handle_fps_timer, output); + wl_event_source_timer_update(output->fps_timer, FPS_TIMEOUT); + } +#endif bool committed = wlr_output_commit_state(wlr_output, &output->pending); if (committed) { +#ifdef FPS_TIMEOUT + output->frames++; +#endif wlr_output_state_finish(&output->pending); wlr_output_state_init(&output->pending); } else { diff --git a/src/output.c b/src/output.c index 8ca93c47..4ae7a41f 100644 --- a/src/output.c +++ b/src/output.c @@ -168,6 +168,11 @@ output_destroy_notify(struct wl_listener *listener, void *data) */ output->wlr_output->data = NULL; + if (output->fps_timer) { + wl_event_source_remove(output->fps_timer); + output->fps_timer = NULL; + } + /* * output->scene_output (if still around at this point) is * destroyed automatically when the wlr_output is destroyed