From: sgunderson@bigfoot.com <> Date: Wed, 31 Jan 2007 23:18:20 +0000 (+0100) Subject: Make a per-second traffic counter. X-Git-Url: https://git.sesse.net/?p=jam;a=commitdiff_plain;h=fca1a00f0d9b599d3ea73767f3e1ab6b0b78444a Make a per-second traffic counter. --- diff --git a/jam.c b/jam.c index 1b6aaed..3d11408 100644 --- a/jam.c +++ b/jam.c @@ -377,6 +377,8 @@ int main(int argc, char **argv) // Just stay around collecting statistics until we're done. for ( ;; ) { unsigned long long sent, received; + static unsigned long long last_sent = 0, last_received = 0; + double recv_rate, send_rate; pthread_mutex_lock(&send_mutex); sent = total_bytes_sent; @@ -386,7 +388,14 @@ int main(int argc, char **argv) received = total_bytes_received; pthread_mutex_unlock(&receive_mutex); - printf("%llu %llu\n", sent, received); + send_rate = (sent - last_sent) * 8.0 / 1048576.0; + recv_rate = (received - last_received) * 8.0 / 1048576.0; + + printf("%12llu %12llu %5.0f Mbit/sec %5.0f Mbit/sec\n", sent, received, + send_rate, recv_rate); + + last_sent = sent; + last_received = received; sleep(1); }