From 42a5727e3fc48db6efc8bf946f3fec4d7e20e312 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 29 Jan 2021 16:56:59 +0000 Subject: [PATCH] server: Show current bandwidth Signed-off-by: Michael Tremer --- src/server.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/server.c b/src/server.c index cbaf708..e4bbac9 100644 --- a/src/server.c +++ b/src/server.c @@ -40,6 +40,7 @@ struct fireperf_server_stats { // Total number of open connections unsigned int connections; + size_t bytes_received; size_t total_bytes_received; }; @@ -111,15 +112,25 @@ static int dump_stats(struct fireperf_config* conf, struct fireperf_server_stats // Format total bytes received char* total_bytes_received = format_size(stats->total_bytes_received); + // Calculate bandwidth + char* bps = format_size(stats->bytes_received / delta); + INFO( conf, "--- %s --------------------\n", timestamp); DEBUG(conf, " %-20s: %19.4fs\n", "Delta", delta); INFO( conf, " %-20s: %20u\n", "Open Connection(s)", stats->connections); + INFO( conf, " %-20s: %18s/s\n", "Current Bandwidth", bps); INFO( conf, " %-20s: %20s\n", "Total Bytes Received", total_bytes_received); // Remember when this was printed last stats->last_printed = now; + // Reset statistics + stats->bytes_received = 0; + // Cleanup + if (bps) + free(bps); + if (total_bytes_received) free(total_bytes_received); @@ -203,6 +214,7 @@ static int handle_io_on_connection(struct fireperf_config* conf, DEBUG(conf, "Read %zu bytes from socket %d\n", bytes_read, fd); // Update statistics + stats->bytes_received += bytes_read; stats->total_bytes_received += bytes_read; return 0; -- 2.47.2