From: Michael Tremer Date: Thu, 18 Feb 2021 16:44:37 +0000 (+0000) Subject: stats: Show sent/received stats everywhere X-Git-Tag: 0.2.0~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=88a97a6c07bf8d682155a941c1f6e367f7a9f229;p=fireperf.git stats: Show sent/received stats everywhere Signed-off-by: Michael Tremer --- diff --git a/src/main.c b/src/main.c index 7e00baa..84e40a7 100644 --- a/src/main.c +++ b/src/main.c @@ -369,46 +369,40 @@ int fireperf_dump_stats(struct fireperf_config* conf, struct fireperf_stats* sta // Format timestamp const char* timestamp = format_timespec(&now); - INFO( conf, "--- %s --------------------\n", timestamp); - DEBUG(conf, " %-20s: %19.4fs\n", "Delta", delta); - INFO( conf, " %-20s: %20u\n", "Open Connection(s)", stats->open_connections); - INFO( conf, " %-20s: %18.2f/s\n", "New Connections", stats->connections / delta); + INFO(conf, "--- %s -------------------------\n", timestamp); + INFO(conf, " : %12s %12s\n", "RX", "TX"); + INFO(conf, " %-20s: %25u\n", "Open Connection(s)", stats->open_connections); + INFO(conf, " %-20s: %23.2f/s\n", "New Connections", stats->connections / delta); // Show current bandwidth - char* bps = NULL; - switch (mode) { - case FIREPERF_MODE_CLIENT: - bps = format_size(stats->bytes_received * 8 / delta, FIREPERF_FORMAT_BITS); - break; + char* bps_received = format_size(stats->bytes_received * 8 / delta, FIREPERF_FORMAT_BITS); + char* bps_sent = format_size(stats->bytes_sent * 8 / delta, FIREPERF_FORMAT_BITS); - case FIREPERF_MODE_SERVER: - bps = format_size(stats->bytes_sent * 8 / delta, FIREPERF_FORMAT_BITS); - break; - } + if (bps_received || bps_sent) { + INFO(conf, " %-20s: %10s/s %10s/s\n", "Current Bandwidth", bps_received, bps_sent); - if (bps) { - INFO( conf, " %-20s: %18s/s\n", "Current Bandwidth", bps); - free(bps); + if (bps_received) + free(bps_received); + if (bps_sent) + free(bps_sent); } - struct total_bytes { - const char* label; - size_t bytes; - } totals[] = { - { "Total Bytes Received", stats->total_bytes_received, }, - { "Total Bytes Sent", stats->total_bytes_sent, }, - { NULL }, - }; + // Total bytes + char* total_bytes_received = format_size(stats->total_bytes_received, FIREPERF_FORMAT_BYTES); + char* total_bytes_sent = format_size(stats->total_bytes_sent, FIREPERF_FORMAT_BYTES); - for (struct total_bytes* total = totals; total->label; total++) { - if (!total->bytes) - continue; + if (total_bytes_received || total_bytes_sent) { + INFO(conf, " %-20s: %12s %12s\n", "Total Bytes", total_bytes_received, total_bytes_sent); - char* s = format_size(total->bytes, FIREPERF_FORMAT_BYTES); - INFO(conf, " %-20s: %20s\n", total->label, s); - free(s); + if (total_bytes_received) + free(total_bytes_received); + if (total_bytes_sent) + free(total_bytes_sent); } + // Empty line + INFO(conf, "\n"); + // Remember when this was printed last stats->last_printed = now;