From c3bc5fb0ff2b68a5c69cad970cd762131c056ff2 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Fri, 9 Jul 2021 01:53:49 +1000 Subject: [PATCH] [client] app: collect render and frame timing information --- client/src/main.c | 24 +++++++++++++++++++++--- client/src/main.h | 5 ++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/client/src/main.c b/client/src/main.c index 0159b521..a78ae3d8 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -149,11 +149,15 @@ static int renderThread(void * unused) } LG_UNLOCK(g_state.lgrLock); + const uint64_t t = nanotime(); + const uint64_t delta = t - g_state.lastRenderTime; + g_state.lastRenderTime = t; + const float fdelta = (float)delta / 1000000.0f; + ringbuffer_push(g_state.renderTimings, &fdelta); + if (g_state.showFPS) { - const uint64_t t = nanotime(); - g_state.renderTime += t - g_state.lastFrameTime; - g_state.lastFrameTime = t; + g_state.renderTime += delta; ++g_state.renderCount; if (g_state.renderTime > 1e9) @@ -594,6 +598,12 @@ int main_frameThread(void * unused) g_state.autoIdleInhibitState = frame->blockScreensaver; } + const uint64_t t = nanotime(); + const uint64_t delta = t - g_state.lastFrameTime; + g_state.lastFrameTime = t; + const float fdelta = (float)delta / 1000000.0f; + ringbuffer_push(g_state.frameTimings, &fdelta); + atomic_fetch_add_explicit(&g_state.frameCount, 1, memory_order_relaxed); lgSignalEvent(e_frame); lgmpClientMessageDone(queue); @@ -697,6 +707,10 @@ static int lg_run(void) ImFontAtlas_GetTexDataAsRGBA32(g_state.io->Fonts, &text_pixels, &text_w, &text_h, NULL); + // initialize metrics ringbuffers + g_state.renderTimings = ringbuffer_new(256, sizeof(float)); + g_state.frameTimings = ringbuffer_new(256, sizeof(float)); + // search for the best displayserver ops to use for(int i = 0; i < LG_DISPLAYSERVER_COUNT; ++i) if (LG_DisplayServers[i]->probe()) @@ -1064,6 +1078,10 @@ static void lg_shutdown(void) ivshmemClose(&g_state.shm); + // free metrics ringbuffers + ringbuffer_free(&g_state.renderTimings); + ringbuffer_free(&g_state.frameTimings ); + igDestroyContext(NULL); } diff --git a/client/src/main.h b/client/src/main.h index 9c7c239b..65781c2e 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -29,6 +29,7 @@ #include "common/types.h" #include "common/ivshmem.h" #include "common/locking.h" +#include "common/ringbuffer.h" #include "spice/spice.h" #include @@ -96,9 +97,11 @@ struct AppState atomic_uint_least64_t frameTime; uint64_t lastFrameTime; uint64_t renderTime; + uint64_t lastRenderTime; atomic_uint_least64_t frameCount; uint64_t renderCount; - + RingBuffer renderTimings; + RingBuffer frameTimings; uint64_t resizeTimeout; bool resizeDone;