#!/s/std/bin/perl

$res_dir = $ENV{"PWD"} . "/../" . $ARGV[0];
mkdir($res_dir, O777);
$ENV{"RESULTS_DIR"} = $res_dir;
$seq_filename = $ENV{"ECPERF_HOME"} . "/ecperf.seq";

print "WARNING: source ecperf.env before running this script!\n\n";

# 0 processors -> no procset
@processors = (1, 4, 8, 12);
@threads = (20, 25, 30);
@connections = (30);
@options = (
	#"-verbose:gc -XX:+UseISM -Xms1624m -Xmx1624m",
	#"-verbose:gc -XX:+UseISM -Xms1624m -Xmx1624m -XX:MaxNewSize=128m",
	"-verbose:gc -XX:+UseISM -Xms1624m -Xmx1624m -XX:MaxNewSize=700m"
	);

@rates = (10, 15, 20, 25, 30);
#@rates = (10, 14, 18, 22, 26, 28, 32);
#  %rates = {};
#  $rates{1} = 3;
#  $rates{2} = 6;
#  $rates{4} = 10;
#  $rates{6} = 12;
#  $rates{8} = 14;
#  $rates{10} = 16;
#  $rates{12} = 18;
#  $rates{16} = 20;

print "threads_list: " . @threads . "\n";

foreach $p (@processors){
    foreach $t (@threads){
	foreach $c (@connections){
	    foreach $o (@options){
		foreach $r (@rates){
		    open(cmd_pipe, "./make-outdir.sh|") 
			|| die "can't open input\n";
		    while(<cmd_pipe>){
			@_ = split;
			print $_;
		    }
		    open(seq_file, $seq_filename) || die "can't output open file: " . $file . "\n";
		    while(<seq_file>){
			split();
			$seq_num = $_[0];
		    }
		    close(seq_file);
		    
		    $file = $res_dir . "/$seq_num/autodrive.log";
		    open(out_file, ">$file") || die "can't output open file: " . $file . "\n";
		    $ENV{"JAVA_OPTIONS"} = $o;
		    #open(cmd_pipe, "./test_drive.sh $p $rates{$p} $t $c -l|") 
		    #|| die "can't open input\n";
		    open(cmd_pipe, "./autodrive_remote.sh $p $r $t $c -l -env|") 
			|| die "can't open input\n";
		    while(<cmd_pipe>){
			@_ = split;
			print $_;
			print out_file $_;
		    }
		    close(cmd_pipe);
		    close(out_file);
		}
	    }
    	}
    }
}





