From 1c96ee619d77ed0fafac992db6b3e6cbd0c90762 Mon Sep 17 00:00:00 2001 From: Mario Kleiner Date: Fri, 14 Apr 2023 21:24:42 +0200 Subject: [PATCH] u/metrics: Add option to fflush after writing each metrics record. This allows to use the metrics logging in "streaming mode" where records are written out with low delay, e.g., into a Unix fifo file / pipe for live consumption by some tracing or recording application. XRT_METRICS_EARLY_FLUSH=true enables this "streaming mode". Signed-off-by: Mario Kleiner --- src/xrt/auxiliary/util/u_metrics.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/xrt/auxiliary/util/u_metrics.c b/src/xrt/auxiliary/util/u_metrics.c index 4aa80c105..acace7743 100644 --- a/src/xrt/auxiliary/util/u_metrics.c +++ b/src/xrt/auxiliary/util/u_metrics.c @@ -23,8 +23,10 @@ static FILE *g_file = NULL; static struct os_mutex g_file_mutex; static bool g_metrics_initialized = false; +static bool g_metrics_early_flush = false; DEBUG_GET_ONCE_OPTION(metrics_file, "XRT_METRICS_FILE", NULL) +DEBUG_GET_ONCE_BOOL_OPTION(metrics_early_flush, "XRT_METRICS_EARLY_FLUSH", false) @@ -51,6 +53,10 @@ write_record(monado_metrics_Record *r) fwrite(buffer, stream.bytes_written, 1, g_file); + if (g_metrics_early_flush) { + fflush(g_file); + } + os_mutex_unlock(&g_file_mutex); } @@ -96,6 +102,7 @@ u_metrics_init(void) os_mutex_init(&g_file_mutex); g_metrics_initialized = true; + g_metrics_early_flush = debug_get_bool_option_metrics_early_flush(); write_version(VERSION_MAJOR, VERSION_MINOR);