summaryrefslogtreecommitdiff
path: root/tun.c
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2016-07-04 18:11:59 +0100
committerFrediano Ziglio <fziglio@redhat.com>2016-07-08 09:24:20 +0100
commit487dfd24e2b262c077e41df4b6441c204fb4bfcf (patch)
treeac7fd4331990e8ea3ee59343d1b8af8f7dbe1df6 /tun.c
parent55b65d04b5ed1313c5d250d5f26b5e8a3abfb321 (diff)
print some statistics
Diffstat (limited to 'tun.c')
-rw-r--r--tun.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/tun.c b/tun.c
index 665cd03..3775824 100644
--- a/tun.c
+++ b/tun.c
@@ -220,6 +220,10 @@ handle_tun(int fd)
pthread_create(&writer, NULL, writer_proc, NULL);
+ uint64_t old_time = get_time_us();
+ uint64_t tot_bytes = 0;
+ uint32_t num_packets = 0;
+
while (!term && (pkt = alloc_packet())) {
int len = read(fd, pkt->data, MIN_PKT_LEN);
if (len < 0)
@@ -228,6 +232,16 @@ handle_tun(int fd)
uint64_t curr_time = get_time_us();
uint64_t time_to_send;
+ tot_bytes += len;
+ num_packets++;
+ if (old_time + 1000000u <= curr_time) {
+ printf("bytes/s %g\n", (double) tot_bytes * 1000000.0 / (curr_time - old_time));
+ printf("%u packets (avg %u)\n", num_packets, num_packets ? (unsigned) (tot_bytes / num_packets) : 0u);
+ old_time = curr_time;
+ tot_bytes = 0;
+ num_packets = 0;
+ }
+
pkt->len = len;
if (bytes_from_first_read == 0 || curr_time > first_received_at + bytes2time(bytes_from_first_read)) {
time_to_send = curr_time;