forked from eclipse-cyclonedds/cyclonedds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ethload
executable file
·48 lines (41 loc) · 938 Bytes
/
ethload
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl -w
use strict;
use bignum;
use Time::HiRes qw (time);
if (@ARGV != 2) {
print STDERR "usage: $0 device {100|1000}\n";
exit 1;
}
my $devname = $ARGV[0];
my $speed = $ARGV[1] * 1e6;
$| = 1;
my ($lt, $t, $lrecv, $lxmit);
while (1) {
open FH, "< /proc/net/dev" or die "can't open /proc/net/dev";
$t = time;
my $info = undef;
while (<FH>) {
chomp;
if (s/^\s+$devname\s*:\s*//) {
$info = $_;
last;
}
}
close FH;
die "can't locate info for $devname" unless defined $info;
my @info = split ' ', $info;
my $recv = $info[0] + 0;
my $xmit = $info[8] + 0;
if (defined $lt) {
my $dr = $recv - $lrecv;
my $dx = $xmit - $lxmit;
my $dt = $t - $lt;
my $ur = 100 * (8 * $dr) / ($dt * $speed);
my $xr = 100 * (8 * $dx) / ($dt * $speed);
printf "r %5.1f x %5.1f (%8d %8d)\n", $ur, $xr, $dr, $dx;
}
$lt = $t;
$lrecv = $recv;
$lxmit = $xmit;
sleep 1;
}