From 464fee3e209bbb97bff877e889294d8eb07e31b9 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 17 Jan 2022 22:08:56 +1100 Subject: [PATCH] [client] overlay/graphs: allow the graph to have a custom title format --- client/displayservers/Wayland/presentation.c | 3 +- client/include/app.h | 5 ++- client/renderers/EGL/egl.c | 3 +- client/src/app.c | 5 ++- client/src/main.c | 6 +-- client/src/overlay/graphs.c | 43 +++++++++++++------- client/src/overlays.h | 2 +- 7 files changed, 43 insertions(+), 24 deletions(-) diff --git a/client/displayservers/Wayland/presentation.c b/client/displayservers/Wayland/presentation.c index eb545cd3..b91902a3 100644 --- a/client/displayservers/Wayland/presentation.c +++ b/client/displayservers/Wayland/presentation.c @@ -86,7 +86,8 @@ bool waylandPresentationInit(void) if (wlWm.presentation) { wlWm.photonTimings = ringbuffer_new(256, sizeof(float)); - wlWm.photonGraph = app_registerGraph("PHOTON", wlWm.photonTimings, 0.0f, 30.0f); + wlWm.photonGraph = app_registerGraph("PHOTON", wlWm.photonTimings, + 0.0f, 30.0f, NULL); wp_presentation_add_listener(wlWm.presentation, &presentationListener, NULL); } return true; diff --git a/client/include/app.h b/client/include/app.h index 7ac0fa75..8baa6225 100644 --- a/client/include/app.h +++ b/client/include/app.h @@ -110,8 +110,11 @@ void app_invalidateOverlay(bool renderTwice); struct OverlayGraph; typedef struct OverlayGraph * GraphHandle; +typedef const char * (*GraphFormatFn)(const char * name, + float min, float max, float avg, float freq, float last); -GraphHandle app_registerGraph(const char * name, RingBuffer buffer, float min, float max); +GraphHandle app_registerGraph(const char * name, RingBuffer buffer, + float min, float max, GraphFormatFn formatFn); void app_unregisterGraph(GraphHandle handle); void app_overlayConfigRegister(const char * title, diff --git a/client/renderers/EGL/egl.c b/client/renderers/EGL/egl.c index fdf5ee4c..7051a74b 100644 --- a/client/renderers/EGL/egl.c +++ b/client/renderers/EGL/egl.c @@ -258,7 +258,8 @@ static bool egl_create(LG_Renderer ** renderer, const LG_RendererParams params, this->desktopDamage[0].count = -1; this->importTimings = ringbuffer_new(256, sizeof(float)); - this->importGraph = app_registerGraph("IMPORT", this->importTimings, 0.0f, 5.0f); + this->importGraph = app_registerGraph("IMPORT", this->importTimings, + 0.0f, 5.0f, NULL); *needsOpenGL = false; return true; diff --git a/client/src/app.c b/client/src/app.c index 7f3a8792..74252e46 100644 --- a/client/src/app.c +++ b/client/src/app.c @@ -695,9 +695,10 @@ void app_releaseAllKeybinds(void) } } -GraphHandle app_registerGraph(const char * name, RingBuffer buffer, float min, float max) +GraphHandle app_registerGraph(const char * name, RingBuffer buffer, + float min, float max, GraphFormatFn formatFn) { - return overlayGraph_register(name, buffer, min, max); + return overlayGraph_register(name, buffer, min, max, formatFn); } void app_unregisterGraph(GraphHandle handle) diff --git a/client/src/main.c b/client/src/main.c index 7bec06b9..48aa0c6e 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -1031,9 +1031,9 @@ static int lg_run(void) g_state.renderTimings = ringbuffer_new(256, sizeof(float)); g_state.uploadTimings = ringbuffer_new(256, sizeof(float)); g_state.renderDuration = ringbuffer_new(256, sizeof(float)); - overlayGraph_register("FRAME" , g_state.renderTimings , 0.0f, 50.0f); - overlayGraph_register("UPLOAD", g_state.uploadTimings , 0.0f, 50.0f); - overlayGraph_register("RENDER", g_state.renderDuration, 0.0f, 10.0f); + overlayGraph_register("FRAME" , g_state.renderTimings , 0.0f, 50.0f, NULL); + overlayGraph_register("UPLOAD", g_state.uploadTimings , 0.0f, 50.0f, NULL); + overlayGraph_register("RENDER", g_state.renderDuration, 0.0f, 10.0f, NULL); initImGuiKeyMap(g_state.io->KeyMap); diff --git a/client/src/overlay/graphs.c b/client/src/overlay/graphs.c index 58a69094..91e55094 100644 --- a/client/src/overlay/graphs.c +++ b/client/src/overlay/graphs.c @@ -36,11 +36,12 @@ static struct GraphState gs = {0}; struct OverlayGraph { - const char * name; - RingBuffer buffer; - bool enabled; - float min; - float max; + const char * name; + RingBuffer buffer; + bool enabled; + float min; + float max; + GraphFormatFn formatFn; }; @@ -93,6 +94,7 @@ struct BufferMetrics float sum; float avg; float freq; + float last; }; static bool rbCalcMetrics(int index, void * value_, void * udata_) @@ -115,6 +117,7 @@ static bool rbCalcMetrics(int index, void * value_, void * udata_) udata->max = *value; udata->sum += *value; + udata->last = *value; return true; } @@ -170,10 +173,18 @@ static int graphs_render(void * udata, bool interactive, metrics.freq = 1000.0f / metrics.avg; } - char title[64]; - snprintf(title, sizeof(title), - "%s: min:%4.2f max:%4.2f avg:%4.2f/%4.2fHz", - graph->name, metrics.min, metrics.max, metrics.avg, metrics.freq); + const char * title; + if (graph->formatFn) + title = graph->formatFn(graph->name, + metrics.min, metrics.max, metrics.avg, metrics.freq, metrics.last); + else + { + static char _title[64]; + snprintf(_title, sizeof(_title), + "%s: min:%4.2f max:%4.2f avg:%4.2f/%4.2fHz", + graph->name, metrics.min, metrics.max, metrics.avg, metrics.freq); + title = _title; + } igPlotLines_FloatPtr( "", @@ -201,14 +212,16 @@ struct LG_OverlayOps LGOverlayGraphs = .render = graphs_render }; -GraphHandle overlayGraph_register(const char * name, RingBuffer buffer, float min, float max) +GraphHandle overlayGraph_register(const char * name, RingBuffer buffer, + float min, float max, GraphFormatFn formatFn) { struct OverlayGraph * graph = malloc(sizeof(*graph)); - graph->name = name; - graph->buffer = buffer; - graph->enabled = true; - graph->min = min; - graph->max = max; + graph->name = name; + graph->buffer = buffer; + graph->enabled = true; + graph->min = min; + graph->max = max; + graph->formatFn = formatFn; ll_push(gs.graphs, graph); return graph; } diff --git a/client/src/overlays.h b/client/src/overlays.h index 54dd08be..f96c1195 100644 --- a/client/src/overlays.h +++ b/client/src/overlays.h @@ -43,7 +43,7 @@ extern struct LG_OverlayOps LGOverlayMsg; void overlayAlert_show(LG_MsgAlert type, const char * fmt, va_list args); GraphHandle overlayGraph_register(const char * name, RingBuffer buffer, - float min, float max); + float min, float max, GraphFormatFn formatFn); void overlayGraph_unregister(); void overlayGraph_iterate(void (*callback)(GraphHandle handle, const char * name, bool * enabled, void * udata), void * udata);