#! /usr/local/bin/perl -w #assumes input files are sorted use strict; my %lats; my %IPs; my $ignore = "ignore"; open IGNORE, $ignore; my %ignore; while () { chomp; $ignore{$_} = "bad!"; } my $lines = 0; $| = 1; # perform flush after each write to STDOUT my $cur_key = "init"; my @cur_lats; while (<>) { next: if (/^([0-9\.]*) --> ([0-9\.]+) ([0-9]+) ([0-9]+) ([0-9]+)/) { #ignore initial measurements. These have caching problems goto next if ($3 == 1); my $lat = ($4 - $5)/1000; goto next if ($lat < 0); # latency can be less than zero if # the first query has to be retried (e.g.) my $k = "$1-$2"; # print "$k $cur_key: $_"; if ($cur_key eq $k) { #processing a stream of measurements push (@cur_lats, $lat); } else { # we're starting a new pair # write down the value from the last pair my @tmp = sort {$a <=> $b} @cur_lats; my @alat_f; foreach my $m (@tmp) { push (@alat_f, $m) if ($m < 1000); } if (defined $lats{$cur_key}) { # this must be a bug or the input wasn't sorted die "$k already processed?\n"; } elsif ($cur_key eq "init") { # print "ignoring initial key\n"; } else { if ($#alat_f >= 0) { my $key = $#alat_f/4 if ($#alat_f >= 4); $key = $#alat_f/2 if ($#alat_f < 4); $lats{$cur_key} = $alat_f[$key]; # $lats{$cur_key} = avg(\@alat_f); } else { $lats{$cur_key} = -1; } # print "$cur_key | $lats{$cur_key} | @tmp\n"; } #don't ignore the new measurement @cur_lats = ($lat); } $cur_key = $k; #note that we've seen these IPs $IPs{$1} = "p"; $IPs{$2} = "p"; #progress meter $lines++; print STDERR "." if ($lines % 10000 == 0); print STDERR "($lines)" if ($lines % 1000000 == 0); } } my $size = scalar keys %IPs; print "outputting a $size x $size matrix\n"; foreach my $from (sort keys %IPs) { next if (defined $ignore{$from}); foreach my $to (sort keys %IPs) { next if (defined $ignore{$to}); if ($from eq $to) { print "0.0 "; } else { my $lat = -1; my $key = "$from-$to"; if (defined $lats{$key} && $lats{$key} > 1 && $lats{$key} < 800) { $lat = $lats{$key}; } print "$lat "; } } print "\n"; } print "row to IP mappings:\n"; my $i = 0; foreach my $ip (sort keys %IPs) { next if (defined $ignore{$ip}); print "$i: $ip\n"; $i++; } sub avg () { my $aref = $_[0]; my $sum = 0; foreach $i (@$aref) { $sum += $i; } return $sum/(@$aref + 1); }