#!/usr/bin/perl -w
use strict;
use warnings;

my $file = shift;
if (!defined($file)) 
{
	print "hello... what is the filename ? \n";
	exit(0);
}
my $sortedfound = "sortedfound";
my $hopsfile = "hops";
my $loadfile = "loaddist";
my $lookups = `grep 'Lookedup' $file | cut --delimiter=' ' -f 2`;
chomp($lookups);
my $found = `grep 'Found' $file | cut --delimiter=' ' -f 4 | sort -u | wc -l`;
chomp($found);
system("grep 'Found' $file | sort > $sortedfound ");
#my $malicious = `grep 'is malicious' $file | wc -l`;
#chomp($malicious);
my $totalnodes = `grep 'inside hello' $file | wc -l`;
chomp($totalnodes);
#`grep my_get_count $file | cut --delimiter=' ' -f 2,4 | awk '{get+=$1 ; put+=$2; count++;} END {print "The count of get: ", get, " put: ", put }'`;
system("grep my_get_count $file | cut --delimiter=' ' -f 2,4 | awk -f get_put_count.awk");
#`grep "ignored counters" $file | cut --delimiter=' ' -f 5,7,9,11 | awk '{get_root+= $1; get_nonroot+=$2; put_root+=$3; put_nonroot+=$4;} END {print "Ignored counters get_root: ", get_root, "get_nonroot: ", get_nonroot, "put_root: ", put_root, "put_nonroot: ", put_nonroot }'`;
system("grep 'ignored counters' $file | cut --delimiter=' ' -f 5,7,9,11 | awk -f ignored_counters.awk");
system("grep found_blocks $file | cut --delimiter=' ' -f 2,4 | awk -f found_missing.awk");
#`grep found_blocks $file | cut --delimiter=' ' -f 2,4 | awk '{found+=$1; missing+=$2;} END {print "Blocks Found: ", found, " Missing: ", missing}'`;

system("grep 'in its hashtable' $file | cut --delimiter=' ' -f 3 > $loadfile");
system("./gethops.pl $sortedfound > $hopsfile");
print "Number of lookups is $lookups and found: $found percentage is " . $found/$lookups*100 . "%\n";
#print "malicious nodes: $malicious/$totalnodes = " . $malicious/$totalnodes . "\n";
print "hops data file: $hopsfile and load distribution file: $loadfile\n";
system("grep bootstrap_count $file | awk '{ sum+=\$3; } END {print \"The total number of bootstrap msgs = \", sum;}'");
my $errors = `grep -i error $file | wc -l`;
chomp($errors);
print "number of Errors: " . $errors . "\n";
