#!/bin/awk -f
BEGIN {
    filename="";
    version="";
    versionList[""]="";
    run=1;   
    times[""]="";
  	num_map=split("TreeSet ConcurrentSkipListSet HashMap ConcurrentHashMap ConcurrentHashMapV8",gammas," ");
    n=0;
    thread=0;
    machine[""]="";
    jvm="";
    jstar="";
    gc[""]="";
    threads=8;
    capacity=16000000;
    #n=split("0_1000000_2000000_4000000_8000000_16000000",capacityList,"_");
    #n=split("0_8000000_16000000",capacityList,"_");
}
{
 
    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);
		capacity=array[4];
		run=1;
    }

    if($0 ~ "Execution time:"){
		split($0,array," ");
		key=version","gamma","thread","capacity","run;
		times[key]=array[3];
		#printf("%s %s\n",key,times[key]);
		run++;
    }else{
		if(match($0,"*.GC.*")){
			gc[gamma","run]=$0;
		}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";
			    machine["jstar"]=array[8]"\t"array[9]"\t"array[10]"\t"array[11]"\t"array[12]"\t"array[13]"\t"array[14]"\t"array[15];
			}
		}
    }  
   
}
END {
    
    for(version in versionList){
		for(g=1;g<=num_map;g++){
			gamma=gammas[g];
			capacity=16000000;
			key=version","gamma",1,"capacity","1;
			#printf("%s %s\n",key,times[key]);
			if(times[version","gamma",1,"capacity","1] != ""){
				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\t\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","run;
					    printf("\t%s",times[key]);
					}
					printf("\n");
			    }
			    	 
			    printf("\nVersion:");
			    for(thread=1;thread<=threads;thread++){
			   	    printf("\t%s",version);
			    }
			    
			    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");
			}
		}
	}
}