From: Michael Tremer Date: Fri, 29 Jan 2021 15:33:03 +0000 (+0000) Subject: server: Compute delta in seconds between dump_stats() calls X-Git-Tag: 0.1.0~34 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=db939889e903bdb5046ec2ab18e8f733f249a8f5;p=fireperf.git server: Compute delta in seconds between dump_stats() calls Signed-off-by: Michael Tremer --- diff --git a/src/server.c b/src/server.c index c6672f1..92c4ff3 100644 --- a/src/server.c +++ b/src/server.c @@ -33,6 +33,8 @@ // Struct to collect server statistics struct fireperf_server_stats { + struct timespec last_printed; + // Total number of open connections unsigned int connections; }; @@ -51,7 +53,16 @@ static const char* format_timespec(const struct timespec* t) { return NULL; } -static int dump_stats(struct fireperf_config* conf, const struct fireperf_server_stats* stats) { +static unsigned long timespec_delta(struct timespec* t1, struct timespec* t2) { + // Compute delta in milliseconds + return ( + ((t1->tv_sec * 1000) + (t1->tv_nsec / 1000000)) + - + ((t2->tv_sec * 1000) + (t2->tv_nsec / 1000000)) + ) / 1000.0; +} + +static int dump_stats(struct fireperf_config* conf, struct fireperf_server_stats* stats) { struct timespec now; // Fetch the time @@ -61,11 +72,17 @@ static int dump_stats(struct fireperf_config* conf, const struct fireperf_server return 1; } + double delta = timespec_delta(&now, &stats->last_printed); + // Format timestamp const char* timestamp = format_timespec(&now); - INFO(conf, "--- %s --------------------\n", timestamp); - INFO(conf, " %-20s: %20u\n", "Open Connection(s)", stats->connections); + INFO( conf, "--- %s --------------------\n", timestamp); + DEBUG(conf, " %-20s: %19.4fs\n", "Delta", delta); + INFO( conf, " %-20s: %20u\n", "Open Connection(s)", stats->connections); + + // Remember when this was printed last + stats->last_printed = now; return 0; }