]> git.ipfire.org Git - fireperf.git/commitdiff
client: Show timestamp when dumping stats
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Feb 2021 12:05:19 +0000 (12:05 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Feb 2021 12:05:19 +0000 (12:05 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/client.c

index 829dd7c2da88f19426701e896f6fb5b2629b9069..ffbf11521ad9c0922d47e34508ad0f9041ee092d 100644 (file)
 #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;
 }