diff --git a/Netstat.pm b/Netstat.pm index ab1142d..6517249 100644 --- a/Netstat.pm +++ b/Netstat.pm @@ -21,7 +21,7 @@ use warnings; use parent 'Exporter'; our @EXPORT= qw( - generate_diff_netstat_s + generate_diff_netstat ); # netstat output might use plural for some nouns always use @@ -60,7 +60,7 @@ sub canonicalize_key { # map netstat indentation to perl hash some nestat -s lines increase the # indentation and at the same time have a value. Write that value to the # "total" field. -sub parse { +sub parse_s { my ($fname) = @_; my %netstat; my $l1; @@ -124,6 +124,40 @@ sub parse { return %netstat; } +sub parse_m { + my ($fname) = @_; + my %netstat; + my $l1 = "memory"; + my $l2; + my $l3; + open(my $fh, '<', $fname) + or die "Open '$fname' for reading failed: $!"; + + while(<$fh>) { + if (m{^(\d+) mbufs? (in use):}) { + $l2 = "mbuf $2"; + $netstat{$l1}{$l2} = $1; + $l2 = "mbuf types"; + } elsif (m{^ (\d+) mbufs? (allocated to .+)}) { + $l3 = "mbuf $2"; + $netstat{$l1}{$l2}{$l3} = $1; + } elsif (m{^(\d+)/\d+ (mbuf \d+ byte clusters in use)}) { + $l2 = "mbuf cluster in use"; + $l3 = $2; + $netstat{$l1}{$l2}{$l3} = $1; + } elsif (m{^(\d+)/\d+/\d+ (Kbytes allocated to network)}) { + $l2 = $2; + $netstat{$l1}{$l2} = $1; + } elsif (m{^(\d+) (\w[\w ]+)$}) { + $l2 = "counter"; + $l3 = $2; + $netstat{$l1}{$l2}{$l3} = $1; + } + } + + return %netstat; +} + # iterate over all key value pairs and print them sub myprint { my ($fh, $l1) = @_; @@ -231,18 +265,28 @@ sub sweep { } } -sub generate_diff_netstat_s { +sub generate_diff_netstat { my ($test) = @_; - my %bef = parse("$test.stats-before-netstat_-s.log"); - my %aft = parse("$test.stats-after-netstat_-s.log"); - my %dif = diff(\%bef, \%aft); - sweep(\%dif); - my $name = "$test.stats-diff-netstat_-s.log"; - open(my $fh, '>', $name) - or die "Open '$name' for writing failed: $!"; - myprint($fh, \%dif); - unlink("$test.stats-before-netstat_-s.log"); - unlink("$test.stats-after-netstat_-s.log"); + + my $diff = "$test.stats-diff-netstat.log"; + open(my $fh, '>', $diff) + or die "Open '$diff' for writing failed: $!"; + foreach my $opt (qw(m s)) { + my $before = "$test.stats-before-netstat_-$opt.log"; + my $after = "$test.stats-after-netstat_-$opt.log"; + -r $before && -r $after + or next; + my $parser; + $parser = \&parse_m if $opt eq 'm'; + $parser = \&parse_s if $opt eq 's'; + my %bef = $parser->($before); + my %aft = $parser->($after); + my %dif = diff(\%bef, \%aft); + sweep(\%dif); + myprint($fh, \%dif); + } + close($fh) + or die "Close '$diff' after writing failed: $!"; } 1; diff --git a/netlink-html.pl b/netlink-html.pl index 4b6dc93..8b6073b 100755 --- a/netlink-html.pl +++ b/netlink-html.pl @@ -644,7 +644,7 @@ sub parse_result_files { $tv->{message} = $message; my $logfile = "$file->{dir}/logs/$test.log"; $tv->{logfile} = $logfile if -f $logfile; - my $stats = "$file->{dir}/logs/$test.stats-diff-netstat_-s.log"; + my $stats = "$file->{dir}/logs/$test.stats-diff-netstat.log"; $tv->{stats} = $stats if -f $stats; $V{$test}{$hk} = [ @values ]; undef @values; diff --git a/netlink.pl b/netlink.pl index a34effa..1063a1c 100755 --- a/netlink.pl +++ b/netlink.pl @@ -217,7 +217,7 @@ sub bad { print $tr "$reason\t$test\t$message\n"; statistics($test, "after"); - generate_diff_netstat_s($test); + generate_diff_netstat($test); $log->sync() if $log; $tr->sync(); @@ -232,10 +232,10 @@ sub good { my $duration = sprintf("%dm%02d.%02ds", $diff/60, $diff%60, 100*$diff%100); statistics($test, "after"); - generate_diff_netstat_s($test); + generate_diff_netstat($test); my $pass = "PASS"; - my $netstat = "$test.stats-diff-netstat_-s.log"; + my $netstat = "$test.stats-diff-netstat.log"; open(my $fh, '<', $netstat) or die("Could not open '$netstat'"); while(<$fh>) { @@ -1350,38 +1350,6 @@ sub statistics { } } -sub netstat_m_parser { - my ($l, $log) = @_; - if ($l =~ m{(\d+) mbufs? in use}) { - my $mbufs = $1; - print "used mbufs: $mbufs\n"; - } elsif ($l =~ m{(\d+) mbufs? allocated to data}) { - my $data_mbufs = $1; - print "data mbufs: $data_mbufs\n"; - } elsif ($l =~ m{(\d+) mbufs? allocated to packet headers}) { - my $header_mbufs = $1; - print "header mbufs: $header_mbufs\n"; - } elsif ($l =~ m{(\d+) mbufs? allocated to socket names and addresses}) { - my $named_mbufs = $1; - print "named mbufs: $named_mbufs\n"; - } elsif ($l =~ m{(\d+)/(\d+) mbuf (\d+) byte clusters in use}) { - my ($current, $peak, $mbuf_size) = ($1, $2, $3); - print "mbufs of size $mbuf_size: curr: $current peak: $peak\n"; - } elsif ($l =~ m{(\d+)/(\d+)/(\d+) Kbytes allocated to network}) { - my ($current, $peak, $max) = ($1, $2, $3); - print "network mbufs: curr: $current peak: $peak max: $max\n"; - } elsif ($l =~ m{(\d+) requests for memory denied}) { - my $denied = $1; - print "denied requests: $denied\n"; - } elsif ($l =~ m{(\d+) requests for memory delayed}) { - my $delayed = $1; - print "delayed requests: $delayed\n"; - } elsif ($l =~ m{(\d+) calls to protocol drain routines}) { - my $drains = $1; - print "called drains: $drains\n"; - } -} - sub netstat_binv_parser { my ($l, $log) = @_; if ($l =~ m{([a-z]+\d+\*?)\s+(\d+)\s+[0-9a-f:\s]+\s+(\d+)\s+(\d+)}) {