#!/opt/vdops/bin/perl # This script reads packet trace summary files, summing the DeltaT column, # writing the result to a text report. # V Who When What # --------------------------------------------------------------------------- # 1.1.0 skendric 2011-11-13 More debugging # 1.0.1 skendric 2011-09-16 More verbose file names # 1.0.0 skendric 2011-09-11 First version # # Load modules use strict; use warnings FATAL => 'all'; use feature 'say'; use feature 'switch'; use English; use Data::Dumper; use Getopt::Std; use Regexp::Common; use Statistics::Lite qw(mean); # Declare variables my $debug; # Integer 0 - 4 my %option; my $output; # Output file my $program_name; # Name of this script my %results; # Data hash my $version; # Version number of this script # Define variables $debug = 0; $output = 'cns-pie.txt'; $program_name = 'calculate-cns-pie'; $version = '1.1.0'; # Set AUTOFLUSH to true to support printing debug output $OUTPUT_AUTOFLUSH = 1; # Grab arguments getopts('d:', \%option); $debug = $option{d} if defined $option{d}; die "Usage: $program_name -d {integer}" unless $RE{num}{int}->matches($debug); # Open current directory opendir my $dir_handle, '.' or die "Cannot open current directory: $!"; # Walk output files from extract-summary-lines-from-pcap FILE: while (defined (my $input = readdir($dir_handle))) { my ($base, $sum); next FILE if $input =~ /^\.\.?$/; next FILE if -d $input; next FILE if $input =~ /\.swp/; next FILE if $input =~ /$output/; next FILE if $input =~ /cns-pie/; next FILE if $input =~ /\.pcap/; next FILE unless $input =~ /\.txt/; say "Processing $input" if $debug; ($base) = ($input =~ /^(.*?)-at-/); say " Using $base" if $debug > 1; # Open summary file open my $input_fh, '<', $input or die "Cannot open $input: $!"; # Sum DeltaT while (my $line = <$input_fh>) { my ($num, $delta, $rest) = split ' ', $line; die "Cannot parse $line" unless $RE{num}{real}->matches($delta); $sum += $delta; } close $input_fh or warn "Cannot close $input: $!"; say " sum = $sum" if $debug > 2; # Save sum in data hash given ($input) { when ($input =~ /at-client-with-client-as-source/) { $results{$base}->{client1} = $sum; } when ($input =~ /at-client-with-server-as-source/) { $results{$base}->{server1} = $sum; } when ($input =~ /at-server-with-client-as-source/) { $results{$base}->{client2} = $sum; } when ($input =~ /at-server-with-server-as-source/) { $results{$base}->{server2} = $sum; } } } closedir $dir_handle or warn "Cannot close current directory: $!"; say(''); say Dumper(%results) if $debug > 3; # Open output file open my $output_fh, '>', $output or die "Cannot open $output: $!"; print {$output_fh} "Trial,Client,Server,Network\n"; # Calculate CNS times; write to output file for my $base (sort keys %results) { my ($client1, $network1, $server1, $client2, $network2, $server2, $network3); say "Calculating $base" if $debug; $client1 = $results{$base}->{client1}; $server1 = $results{$base}->{server1}; $client2 = $results{$base}->{client2}; $server2 = $results{$base}->{server2}; $network1 = abs($client1 - $server1); $network2 = abs($client2 - $server2); $network3 = mean($network1, $network2); print {$output_fh} "$base,$client1,$server2,$network3\n"; } # Close output file say "Wrote output to $output" if $debug; close $output_fh or warn "Cannot close $output: $!";