From: Michael Tremer Date: Thu, 4 Feb 2021 12:05:19 +0000 (+0000) Subject: client: Show timestamp when dumping stats X-Git-Tag: 0.1.0~9 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=fcee34f996727c6109a49fcd0902a054bc69b8d9;p=fireperf.git client: Show timestamp when dumping stats Signed-off-by: Michael Tremer --- 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; }