sel.py 1.63 KB
Newer Older
German Leon's avatar
German Leon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python
import csv
import sys
import re

patron=re.compile('(^[^=](.*)$)',re.M)
fields=['Metric Name'] 
for i in range(1,len(sys.argv)):
	a=sys.argv[i]
        a=a.split('_')
        a=a[2]+'_'+a[3]
        fields.append(a)     
metricas=[]        
print(metricas)
file=open(sys.argv[1])
contents=file.read()
with open("tmpxx","w") as filetmp:
	for m in patron.findall(contents):
		#print(m)
		filetmp.write((m[0]+"\n"))
with open("tmpxx") as csvtmp:
      dst=csv.DictReader(csvtmp)
      for row in dst:
         metricas.append(row['Metric Name'])
#print ("====================")
#print (metricas)          
with open('total.csv','w') as csvdstfile:
	writer=csv.DictWriter(csvdstfile,fieldnames=fields);
	writer.writeheader()
	dw={}
	ix=0;
	for account in ['grid size','thread block size']:
	        #print("M",account)
		dw['Metric Name']=account
		for f in  fields[1:]:
			a=f.split('_')
			dw[f]=a[ix]
		ix=ix+1
	        writer.writerow(dw)
	        dw={}
	for m in metricas:
		dw={}
		dw['Metric Name']=m
		#print ("Metr", m)
		for i in range(1,len(sys.argv)):		
			print(sys.argv[i])
			file=open(sys.argv[i])
			contents=file.read()
			with open("tmpxx","w") as filetmp:
				for my in patron.findall(contents):
					filetmp.write(my[0])
					filetmp.write("\n")
			with open("tmpxx") as csvtmp:
				dst=csv.DictReader(csvtmp)
				#print(dst)
				for row in dst:
					#print("Row",row['Metric Name'], " y mi m es ",m,"\n")
	        	  		if (row['Metric Name']==m):
	        	  			#print("Entro")
	         		    		dw[fields[i]]=row['Avg'].replace(".",",")
	         		    	
	        print (dw) 		    			
		writer.writerow(dw)