#!/bin/awk -f
BEGIN {   
    filename="";
    run=1;   
    times[""]="";    
    files[""]="";  
    producer=0;
    consumer=12;
    gamma="";
    strategy="Blocking";
    machine[""]="";
    jvm="";
    jvmList[""]="";
    jstar="";
    key="";
}
{
 
    if(filename != FILENAME){
		filename=FILENAME;
		n=split(filename,array,".");
		jvm=array[1];
		jvmList[jvm]=jvm;
		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);
		gamma=array[5];
		run=1;
    }

    if($0 ~ "Execution time:"){
		split($0,array," "); 
		key=jvm","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{
   
    for(jvm in jvmList){	
	   if(jvm != ""){
		   printf("Machine: %s with %d CPUs (%s) and %s memory\n",machine["OS"],int(machine["processor"])+1,machine["model"],machine["memtotal"]);
	       printf("JVM:%s\tConsumer:%s\tStrategy:%s\tsorted1000.csv(192,749,048 bytes)\n",jvm,consumer,strategy);
		   printf("\nProducer:\t1\t2\t3\n");
		  
		   for(run=1;run<=30;run++){
				printf("Run%s",run);
				for(producer=1;producer<=3;producer++){
					key=jvm","producer","consumer","strategy","run;
					printf("\t%s",times[key]);
			   	}
			    printf("\n");
		   }
		   printf("\nJVM:");
		   for(producer=1;producer<=3;producer++){
			   printf("\t%s",jvm);
		   }
		   printf("\nFile:");
		   for(producer=1;producer<=3;producer++){
			   printf("\tsorted1000.csv");
		   }
		   printf("\nConsumer:");
		   for(producer=1;producer<=3;producer++){
			   printf("\t%s",consumer);
		   }
		   printf("\nStrategy:");
		   for(producer=1;producer<=3;producer++){
			   printf("\t%s",strategy);
		   }
		   printf("\nProducer:");
		   for(producer=1;producer<=3;producer++){
			   printf("\t%s",producer);
		   }  	    
		   printf("\nAverage6-30");
		   printf("\nMedian6-30");
		   printf("\nVariance6-20");
		   printf("\nSpeedup");
		   printf("\n");
	   }
    }
     
    
}
