#!/bin/awk -f
BEGIN {   
    filename="";
    run=1;   
    times[""]="";    
    version="";
    reader="";
    capacity="";
    versionList[""]="";
    num_gamma=split("TreeSet HashMap ConcurrentHashMap ConcurrentHashMapV8 ConcurrentSkipListSet",gammas," ");
    num_capacity=split("0 2000000 16000000",capacityList, " ");
    num_reader=split("1 48",readerList, " ");  
    machine[""]="";
    key="";
    threads=15;
}
{
    if(filename != FILENAME){
		filename=FILENAME;
		n=split(filename,array,".");
		version=array[1];
		versionList[version]=version;
		gamma=array[2];
		thread=substr(array[3],7,length(array[3])+1);
		reader=substr(array[4],7,length(array[4])+1);
		capacity=substr(array[5],9,length(array[5])+1);
		run=1;
    }

    if($0 ~ "Execution time:"){
		split($0,array," "); 
		key=version","gamma","thread","capacity","reader","run;		
		times[key]=array[3];
		#printf("%s %s\n",key,times[key]);
		run++;
    }else{	
	 	key="hardware";
		if(match($0, "Linux.*")){
		    machine["OS"]=substr($0,1,index($0,"#"));
		}
		if(match($0, "processor")){
		    split($0,array," ");
		    machine["processor"]=array[3];
		}    
		if(match($0, "model name")){
		    split($0,array,":");
		    machine["model"]=array[2];
		}

		if(match($0, "MemTotal:")){
		    split($0,array," ");
		    machine["memtotal"]=array[2];
		}

		if(match($0, "====.*")){
		    machine["header"]=$0
		}
    }  
   
}
END {     
    for(version in versionList){
    	if(version != ""){
		    for(g=1;g<=num_gamma;g++){
			   gamma=gammas[g];
			   for(c=1;c<=num_capacity;c++){
			   	   capacity=capacityList[c];
			   	   for(r=1;r<=num_reader;r++){
			   	   	   reader=readerList[r];
				   	   key=version","gamma","1","capacity","reader","1;
				   	   if(times[key] != ""){
						   printf("Machine: %s with %d cores (%s) and %s memory\n",machine["OS"],int(machine["processor"])+1,machine["model"],machine["memtotal"]);
						   printf("Version:%s\tGamma:%s\tCapacity:%s\tFile:sorted1000X.csv\n",version,gamma,capacity);
					 	   printf("\nNumThreads:\t1\t2\t3\t4\t5\t6\t7\t8\n");
						   for(run=1;run<=30;run++){
								printf("Run%s",run);
								for(thread=1;thread<=threads;thread++){
										key=version","gamma","thread","capacity","reader","run;	
										printf("\t%s",times[key]);
								}	
								printf("\n");
						   }
						   printf("\nVersion:");
						   for(thread=1;thread<=threads;thread++){
						   	   printf("\t%s",version);
						   }
						   printf("\nReaders:");
						   for(thread=1;thread<=threads;thread++){						   	   
							   printf("\t%s",reader);							 
						   }
						   printf("\nPvWattsGamma:");
						   for(thread=1;thread<=threads;thread++){						   	  
							   printf("\t%s",gamma);
						   }
						   printf("\nCapacity:");
						   for(thread=1;thread<=threads;thread++){						   	  
							   printf("\t%s",capacity);
						   }
						    printf("\nNumThreads:");
						   for(thread=1;thread<=threads;thread++){						   	   
							   printf("\t%s",thread);
						   }						   
						   printf("\nAverage6-30");
						   printf("\nMedian6-30");
						   printf("\nVariance6-30");
						   printf("\nSpeedup");
						   printf("\n");
					   }
				   }
			   } 
			}
	     }   
    }
}
