#!/usr/bin/perl

$sumbw = 0;
$valid = 0;
print "bprobe $ARGV[0] $ARGV[1] times\ntrial# bottleneck_bw\n";
for ($i=0; $i< $ARGV[1]; $i++) {
	system("bprobe  $ARGV[0] > test.bp.bw");
        open(TEST, "test.bp.bw");
        $first = 0;
        while (<TEST>) {
		if (/Final Bandwidth/) {
			@fields=split(/:/, $_);
			$bw = @fields[1];
		}
        }
        print "$i\t$bw";
	$_ = $bw;
	unless (/^ 0\.0/) {
		$sumbw += $bw;
		$valid++;
	}
}
$avgbw=$sumbw/$valid;
print "valid trial#=$valid, average bottleneck bw=$avgbw\n";
