]> git.sesse.net Git - jam/commitdiff
Make a per-second traffic counter.
authorsgunderson@bigfoot.com <>
Wed, 31 Jan 2007 23:18:20 +0000 (00:18 +0100)
committersgunderson@bigfoot.com <>
Wed, 31 Jan 2007 23:18:20 +0000 (00:18 +0100)
jam.c

diff --git a/jam.c b/jam.c
index 1b6aaed6cf7625462f638d86eaa9430a5212b585..3d11408d9e9c6c4be49a3b7ecae83718ab9988ae 100644 (file)
--- 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);
        }