#!/usr/bin/perl ############################################################### # parseIperfLog.pl # # parses output of the doIper.sh script and creates gnuplot # command files for producing graphics # # Author: Derek Feichtinger 2006-11-12 # # $Id: parseIperfLog.pl,v 1.5 2007/01/11 23:55:17 feichtinger Exp $ ############################################################### use Data::Dumper; use strict; my $outfile_root="pIL"; my $infile=$ARGV[0]; open(INFILE,"<$infile") or die "Error: Could not open $infile\n"; my %res; my $mode; my $state="p"; # state can be (h)eader, (r)esult or (p)reliminary my ($direction,$host,$time,$port,$streams,$tcpwin,$unit,$ID,$sum,$total,$tunit,$rate,$runit); while (my $line = ) { if ($line =~ /^command:/) { $state="h"; if ($line =~ /-P\s*(\d+)/) { ($streams) = $line =~ m/-P\s*(\d+)/; } else { $streams=1; } if ($line =~ /-t\s*(\d+)/) { ($time) = $line =~ m/-t\s*(\d+)/; } else { $time=10; # default iperf measuring time } print "STREAMS: $streams\n$line"; next; } next if $state eq "p"; if ($state eq "h") { # header if ($line =~ /Server listening on TCP port .*/) { $mode="server"; ($port) = $line =~ m/Server listening on TCP port\s+(\d+)/; print "Server mode, port $port\n"; next; } if ($line =~ /Client connecting to .* TCP port .*/) { $mode="client"; ($host,$port) = $line =~ m/Client connecting to\s+([^,\s]+).*TCP port\s+(\d+)/; print "Client host $host, port $port\n"; $direction=1; next; } if ($line =~ /TCP window size:\s+[\d.]+\s+[^\s]+/) { ($tcpwin,$unit) = $line =~ m/TCP window size:\s+([\d.]+)\s+([^\s]+)/; print " TCP windows size: $tcpwin $unit\n"; next; } # if($line =~ /.*local.*connected with.*/) { # $streams++; # next; # } if ($line =~ /\[ ID\]\s+Interval\s+Transfer\s+Bandwidth/) { $state="r"; ($total,$tunit,$rate,$runit)=0; next; } next; } if ($line =~ /\[.*\].*sec\s+[\d.]+\s+[^\s]+\s+[^\s]+\s+[^\s]+/) { ($ID,$total,$tunit,$rate,$runit) = $line =~ m/\[\s*(.*)\].*sec\s+([\d.]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)/; if($ID eq "SUM" or $streams == 1) { normalize_rate(\$rate,\$runit); normalize_size(\$tcpwin,\$unit); push @{$res{$direction}{$tcpwin}{$streams}},$rate; print "dir: $direction nstreams: $streams Total: $total $tunit Rate: $rate $runit\n"; $direction = -$direction; } next; } } close INFILE; #print Dumper(\%res) . "\n"; # write the gnuplot input and command files foreach $direction (1,-1) { my ($outfile,$gnuplotfile,$dirstr); if ($direction==1) { $dirstr="TO"; } else { $dirstr="FROM"; } $outfile="${outfile_root}-${host}-${dirstr}.out"; $gnuplotfile="${outfile_root}-${host}-${dirstr}.gpl"; my $index=0; my %meanrate; die "Error: $outfile already exists. Cancelling!" if (-e $outfile); open(OUTFILE,">$outfile") or die "Error: Could not open output file $outfile\n"; open(GNUF,">$gnuplotfile") or die "Error: Could not open output file $gnuplotfile\n"; print GNUF <<"EOF"; set title "Throughput $dirstr $host for different TCP window sizes" set output "${outfile_root}-${dirstr}-${host}.png" set term png set xlabel "# of streams" set ylabel "MBits/sec" EOF foreach $tcpwin (sort {$a <=> $b} keys %{$res{$direction}}) { print OUTFILE "# tcp win size $tcpwin KByte\n"; if ($index>0) { print GNUF ",\\\n"; } else { print GNUF "plot " } print GNUF "\"$outfile\" index $index using 1:2 ti \"tcpw $tcpwin KB\""; $index++; foreach $streams (sort {$a <=> $b} keys %{$res{$direction}{$tcpwin}}) { $meanrate{$tcpwin}{$streams}=0; foreach $rate (@{$res{$direction}{$tcpwin}{$streams}}) { print OUTFILE "$streams $rate\n"; $meanrate{$tcpwin}{$streams}+=$rate; } my $nmeas=1+$#{@{$res{$direction}{$tcpwin}{$streams}}}; $meanrate{$tcpwin}{$streams} /= $nmeas; print "meanrate: $meanrate{$tcpwin}{$streams} (#streams=$streams," . "tcpw=$tcpwin, $nmeas measurements)\n"; } print OUTFILE "\n\n"; } print OUTFILE "# Mean rates\n"; foreach $tcpwin (sort {$a <=> $b} keys %{$res{$direction}}) { print OUTFILE "# MEAN tcp win size $tcpwin KByte\n"; print GNUF ",\\\n"; print GNUF "\"$outfile\" index $index using 1:2 ti \"tcpw $tcpwin KB (mean)\" w linespoints"; $index++; foreach $streams (sort {$a <=> $b} keys %{$meanrate{$tcpwin}}) { print OUTFILE "$streams $meanrate{$tcpwin}{$streams}\n"; } print OUTFILE "\n\n"; } print GNUF "\n"; close OUTFILE; close GNUF; } sub normalize_rate() { my $value=shift; my $unit=shift; if($$unit eq "Kbits/sec") { $$value=$$value/1000; } elsif ($$unit ne "Mbits/sec") { die "Error: unknown bandwidth unit: $$unit. Please add to program\n"; } $$unit="Mbits/sec"; } sub normalize_size() { my $value=shift; my $unit=shift; if($$unit eq "MByte") { $$value*=1000; } elsif ($$unit ne "KByte") { die "Error: unknown size unit: $$unit. Please add to program\n"; } $$unit="KByte"; }