#!/bin/awk -f
BEGIN {
   
    filename="";
    run=1;   
    times[""]="";    
    files[""]="";  
    
    producer=0;
    consumer=0;
    num=split("Blocking Sleeping Yielding BusySpin",strategies," ");
    strategy="Blocking";

    machine[""]="";
    jvm="";
    jstar="";
    key="";
}
{
 
    if(filename != FILENAME){
	filename=FILENAME;
	n=split(filename,array,".");
	consumer=substr(array[2],9, length(array[2])+1);
	producer=substr(array[3],9, length(array[3])+1);
	strategy=substr(array[4],9, length(array[4])+1);
	run=1;
    }

    if($0 ~ "Execution time:"){
	split($0,array," "); 
	key=producer","consumer","strategy","run;	
	#times[filename","run]=array[3];
	times[key]=array[3];
	run++;	    
    }else{

	if(match($0, "Linux.*")){
	    machine["OS"]=substr($0,1,index($0,"#"));
	}else if(match($0, "processor")){
	    split($0,array," ");
	    machine["processor"]=array[3];
	}else  if(match($0, "model name")){
	    split($0,array,":");
	    machine["model"]=array[2];
	}else if(match($0, "MemTotal:")){
	    split($0,array," ");
	    machine["memtotal"]=array[2];
	}else if(match($0, "====.*")){
	    machine["header"]=$0
	}else if(match($0, "java.*")){
	    split($0, array," ");
	    machine["jvm"]=array[2]"\t"array[3]"\t"array[4]"\t"array[5]"\t"array[6];
	    machien["jstar"]=array[7]"\t"array[8]"\t"array[9]"\t"array[10]"\t"array[11]"\t"array[12];
	}
    }  
   
}
END {
    consumer=12;
    producer=1;

     
    
    for(n=1;n<=num;n++){	
	   strategy=strategies[n];
	   printf("Machine: %s with %d CPUs (%s) and %s memory\n",machine["OS"],machine["processor"]+1,machine["model"],machine["memtotal"]);
     	   printf("Disruptor PvWatts program:\tConsumer:%s\tProducer:%s\tStrategy:%s\tLarge1000.csv(192,749,048 bytes)\n",consumer, producer,strategy);
     	   printf("JVM options:%s\n",machine["jvm"]);

	   for(run=1;run<=30;run++){
		printf("Run%s",run);
		key=producer","consumer","strategy","run;
		printf("\t%s",times[key]);	
		printf("\n");
	   }  	    
	   printf("Average6-30\n");
	   printf("Median6-30\n");
	   printf("Variance6-20\n");
	   printf("\n");
    }
     
    
}
