15 gettimeofday (&tv, NULL);
16 return (tv.tv_sec + tv.tv_usec / 1000000.0);
22 static char buffer[1024];
23 static double last = 0.0;
24 static unsigned long long old_bytes;
25 static unsigned long old_packets;
26 static unsigned long old_errors;
29 unsigned long long new_bytes, bytes;
30 unsigned long new_packets, packets;
31 unsigned long new_errors, errors;
35 lseek (fd, 0, SEEK_SET);
37 n = read (fd, buffer, sizeof (buffer));
40 fprintf (stderr, "Can't read statfile\n");
45 n = sscanf (buffer, "%Lu %lu %lu %lu",
46 &new_bytes, &new_packets, &new_errors, &depth);
50 fprintf (stderr, "Can't parse statfile\n");
55 printf ("%llu bytes, %lu packets (sz %lld), %lu errors",
56 new_bytes, new_packets,
57 (long long)((new_packets == 0) ? 0LL : new_bytes/new_packets),
63 if (new_bytes < old_bytes)
64 bytes = -1ULL - old_bytes + new_bytes + 1;
66 bytes = new_bytes - old_bytes;
67 if (new_packets < old_packets)
68 packets = -1UL - old_packets + new_packets + 1;
70 packets = new_packets - old_packets;
71 if (new_errors < old_errors)
72 errors = -1UL - old_errors + new_errors + 1;
74 errors = new_errors - old_errors;
76 printf ("%9llu bytes (%7.2fMb/s), %7lu packets (sz %5lld, %5ld/s), %lu errors (%ld/s)",
77 bytes, ((double)bytes)/((1<<20) * t),
78 packets, (long long)((packets == 0) ? 0LL : bytes/packets), (long)(packets/t),
79 errors, (long)(errors/t));
81 old_bytes = new_bytes;
82 old_packets = new_packets;
83 old_errors = new_errors;
86 printf (", depth (%ld)\n", depth);
92 lseek (fd, 0, SEEK_SET);
96 int main (int argc, char **argv)
102 interval = atoi (argv[1]);
104 fd = open ("/proc/sys/portals/router", O_RDONLY);
107 fprintf (stderr, "Can't open stat: %s\n", strerror (errno));