From fcee34f996727c6109a49fcd0902a054bc69b8d9 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 4 Feb 2021 12:05:19 +0000 Subject: [PATCH] client: Show timestamp when dumping stats Signed-off-by: Michael Tremer --- src/client.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/client.c b/src/client.c index 829dd7c..ffbf115 100644 --- a/src/client.c +++ b/src/client.c @@ -30,9 +30,12 @@ #include "client.h" #include "logging.h" #include "main.h" +#include "util.h" // Struct to collect client statistics struct fireperf_client_stats { + struct timespec last_printed; + // Total number of open connections unsigned int connections; }; @@ -102,7 +105,28 @@ static const char* fireperf_random_pool_get_slice(struct fireperf_random_pool* p } static int dump_stats(struct fireperf_config* conf, struct fireperf_client_stats* stats) { - INFO(conf, "Dumping stats...\n"); + struct timespec now; + + // Fetch the time + int r = clock_gettime(CLOCK_REALTIME, &now); + if (r) { + ERROR(conf, "Could not fetch the time: %s\n", strerror(errno)); + return 1; + } + + double delta = timespec_delta(&now, &stats->last_printed); + + // Called too soon again? + if (delta < 0.1) + return 0; + + // Format timestamp + const char* timestamp = format_timespec(&now); + + INFO( conf, "--- %s --------------------\n", timestamp); + + // Remember when this was printed last + stats->last_printed = now; return 0; } -- 2.47.2