blob: cf21085e509c1d16015fc98098e6a03f2d13fab4 [file] [log] [blame]
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +02001# Process the test results
2# Test status (like passed, or failed with error code)
3
4import argparse
5import re
6import TestScripts.NewParser as parse
7import TestScripts.CodeGen
8from collections import deque
9import os.path
10import numpy as np
11import pandas as pd
12import statsmodels.api as sm
13import statsmodels.formula.api as smf
14import csv
15import TestScripts.Deprecate as d
16import sqlite3
17import datetime, time
18import re
19
20# For table creation
21MKSTRFIELD=['NAME','Regression']
Christophe Favergeon74a31ba2019-09-09 09:14:18 +010022MKBOOLFIELD=['HARDFP', 'FASTMATH', 'NEON', 'HELIUM','UNROLL', 'ROUNDING','OPTIMIZED']
Christophe Favergeon5cacf9d2019-08-14 10:41:17 +020023MKINTFIELD=['ID','MAX']
24MKREALFIELD=['MAXREGCOEF']
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020025MKDATEFIELD=['DATE']
26MKKEYFIELD=['CATEGORY', 'PLATFORM', 'CORE', 'COMPILER','TYPE']
27MKKEYFIELDID={'CATEGORY':'categoryid',
28 'PLATFORM':'platformid',
29 'CORE':'coreid',
30 'COMPILER':'compilerid',
31 'TYPE':'typeid'}
32
33# For table value extraction
34VALSTRFIELD=['NAME','VERSION','Regression']
Christophe Favergeon74a31ba2019-09-09 09:14:18 +010035VALBOOLFIELD=['HARDFP', 'FASTMATH', 'NEON', 'HELIUM','UNROLL', 'ROUNDING','OPTIMIZED']
Christophe Favergeon5cacf9d2019-08-14 10:41:17 +020036VALINTFIELD=['ID', 'MAX']
37VALREALFIELD=['MAXREGCOEF']
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020038VALDATEFIELD=['DATE']
39VALKEYFIELD=['CATEGORY', 'PLATFORM', 'CORE', 'COMPILER','TYPE']
40
41def joinit(iterable, delimiter):
42 it = iter(iterable)
43 yield next(it)
44 for x in it:
45 yield delimiter
46 yield x
47
48def tableExists(c,tableName):
49 req=(tableName,)
50 r=c.execute("SELECT name FROM sqlite_master WHERE type='table' AND name=?",req)
51 return(r.fetchone() != None)
52
53def diff(first, second):
54 second = set(second)
55 return [item for item in first if item not in second]
56
57def getColumns(elem,full):
58 colsToKeep=[]
59 cols = list(full.columns)
60 params=diff(elem.params.full , elem.params.summary)
61 common = diff(cols + ["TYPE"] , ['OLDID'] + params)
62
63 for field in common:
64 if field in MKSTRFIELD:
65 colsToKeep.append(field)
66 if field in MKINTFIELD:
67 colsToKeep.append(field)
Christophe Favergeon5cacf9d2019-08-14 10:41:17 +020068 if field in MKREALFIELD:
69 colsToKeep.append(field)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020070 if field in MKKEYFIELD:
71 colsToKeep.append(field)
72 if field in MKDATEFIELD:
73 colsToKeep.append(field)
74 if field in MKBOOLFIELD:
75 colsToKeep.append(field)
76 return(colsToKeep)
77
78def createTableIfMissing(conn,elem,tableName,full):
79 if not tableExists(conn,tableName):
80 sql = "CREATE TABLE %s (" % tableName
81 cols = list(full.columns)
82 params=diff(elem.params.full , elem.params.summary)
83 common = diff(cols + ["TYPE"] , ['OLDID'] + params)
84
85 sql += "%sid INTEGER PRIMARY KEY" % (tableName)
86 start = ","
87
88 for field in params:
89 sql += " %s\n %s INTEGER" % (start,field)
90 start = ","
91
92 for field in common:
93 if field in MKSTRFIELD:
94 sql += "%s\n %s TEXT" % (start,field)
95 if field in MKINTFIELD:
96 sql += "%s\n %s INTEGER" % (start,field)
Christophe Favergeon5cacf9d2019-08-14 10:41:17 +020097 if field in MKREALFIELD:
98 sql += "%s\n %s REAL" % (start,field)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020099 if field in MKKEYFIELD:
100 sql += "%s\n %s INTEGER" % (start,MKKEYFIELDID[field])
101 if field in MKDATEFIELD:
102 sql += "%s\n %s TEXT" % (start,field)
103 if field in MKBOOLFIELD:
104 sql += "%s\n %s INTEGER" % (start,field)
105 start = ","
106 # Create foreign keys
107 sql += "%sFOREIGN KEY(typeid) REFERENCES TYPE(typeid)," % start
108 sql += "FOREIGN KEY(categoryid) REFERENCES CATEGORY(categoryid),"
109 sql += "FOREIGN KEY(platformid) REFERENCES PLATFORM(platformid),"
110 sql += "FOREIGN KEY(coreid) REFERENCES CORE(coreid),"
111 sql += "FOREIGN KEY(compilerid) REFERENCES COMPILER(compilerid)"
112 sql += " )"
113 conn.execute(sql)
114
115# Find the key or add it in a table
116def findInTable(conn,table,keystr,strv,key):
117 #print(sql)
118 r = conn.execute("select %s from %s where %s=?" % (key,table,keystr),(strv,))
119 result=r.fetchone()
120 if result != None:
121 return(result[0])
122 else:
123 conn.execute("INSERT INTO %s(%s) VALUES(?)" % (table,keystr),(strv,))
124 conn.commit()
125 r = conn.execute("select %s from %s where %s=?" % (key,table,keystr),(strv,))
126 result=r.fetchone()
127 if result != None:
128 #print(result)
129 return(result[0])
130 else:
131 return(None)
132
133def findInCompilerTable(conn,kind,version):
134 #print(sql)
135 r = conn.execute("select compilerid from COMPILER where compilerkindid=? AND version=?" , (kind,version))
136 result=r.fetchone()
137 if result != None:
138 return(result[0])
139 else:
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200140 fullDate = datetime.datetime.now()
141 conn.execute("INSERT INTO COMPILER(compilerkindid,version,date) VALUES(?,?,?)" ,(kind,version,fullDate))
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200142 conn.commit()
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200143 r = conn.execute("select compilerid from COMPILER where compilerkindid=? AND version=? AND date=?" , (kind,version,fullDate))
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200144 result=r.fetchone()
145 if result != None:
146 #print(result)
147 return(result[0])
148 else:
149 return(None)
150
151
152def addRows(conn,elem,tableName,full):
153 # List of columns we have in DB which is
154 # different from the columns in the table
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200155 compilerid = 0
156 platformid = 0
157 coreid = 0
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200158 keep = getColumns(elem,full)
159 cols = list(full.columns)
160 params=diff(elem.params.full , elem.params.summary)
161 common = diff(["TYPE"] + cols , ['OLDID'] + params)
162 colNameList = []
163 for c in params + keep:
164 if c in MKKEYFIELD:
165 colNameList.append(MKKEYFIELDID[c])
166 else:
167 colNameList.append(c)
168 colNames = "".join(joinit(colNameList,","))
169 #print(colNameList)
170 #print(colNames)
171 #print(full)
172 for index, row in full.iterrows():
173 sql = "INSERT INTO %s(%s) VALUES(" % (tableName,colNames)
174 keys = {}
175
176 # Get data from columns
177 for field in common:
178 if field in VALSTRFIELD:
179 keys[field]=row[field]
180 if field == "NAME":
181 name = row[field]
182 if re.match(r'^.*_f64',name):
183 keys["TYPE"] = "f64"
184 if re.match(r'^.*_f32',name):
185 keys["TYPE"] = "f32"
186 if re.match(r'^.*_f16',name):
187 keys["TYPE"] = "f16"
188 if re.match(r'^.*_q31',name):
189 keys["TYPE"] = "q31"
190 if re.match(r'^.*_q15',name):
191 keys["TYPE"] = "q15"
192 if re.match(r'^.*_q7',name):
193 keys["TYPE"] = "q7"
194
195 if re.match(r'^.*_s8',name):
196 keys["TYPE"] = "s8"
197 if re.match(r'^.*_u8',name):
198 keys["TYPE"] = "u8"
199 if re.match(r'^.*_s16',name):
200 keys["TYPE"] = "s16"
201 if re.match(r'^.*_u16',name):
202 keys["TYPE"] = "u16"
203 if re.match(r'^.*_s32',name):
204 keys["TYPE"] = "s32"
205 if re.match(r'^.*_u32',name):
206 keys["TYPE"] = "u32"
207 if re.match(r'^.*_s64',name):
208 keys["TYPE"] = "s64"
209 if re.match(r'^.*_u64',name):
210 keys["TYPE"] = "u64"
211
212 if field in VALINTFIELD:
213 keys[field]=row[field]
Christophe Favergeon5cacf9d2019-08-14 10:41:17 +0200214 if field in VALREALFIELD:
215 keys[field]=row[field]
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200216 if field in VALDATEFIELD:
217 keys[field]=row[field]
218 if field in VALBOOLFIELD:
219 keys[field]=row[field]
220
221
222 # Get foreign keys and create missing data
223 for field in common:
224 if field in VALKEYFIELD:
225 if field == "CATEGORY":
226 val = findInTable(conn,"CATEGORY","category",row[field],"categoryid")
227 keys[field]=val
228 if field == "CORE":
229 val = findInTable(conn,"CORE","coredef",row[field],"coreid")
230 keys[field]=val
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200231 coreid = val
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200232 if field == "PLATFORM":
233 val = findInTable(conn,"PLATFORM","platform",row[field],"platformid")
234 keys[field]=val
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200235 platformid = val
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200236 if field == "TYPE":
237 val = findInTable(conn,"TYPE","type",keys["TYPE"],"typeid")
238 keys[field]=val
239 if field == "COMPILER":
240 compilerkind = findInTable(conn,"COMPILERKIND","compiler",row[field],"compilerkindid")
241 compiler = findInCompilerTable(conn,compilerkind,keys["VERSION"])
242 keys[field]=compiler
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200243 compilerid = compiler
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200244
245 # Generate sql command
246 start = ""
247 for field in params:
248 sql += " %s\n %d" % (start,row[field])
249 start = ","
250
251 for field in keep:
252 if field in MKSTRFIELD or field in MKDATEFIELD:
253 sql += " %s\n \"%s\"" % (start,keys[field])
254 elif field in keep:
Christophe Favergeon5cacf9d2019-08-14 10:41:17 +0200255 if field in VALREALFIELD:
256 sql += " %s\n %f" % (start,keys[field])
257 else:
258 sql += " %s\n %d" % (start,keys[field])
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200259 start = ","
260
261 sql += " )"
262 #print(sql)
263 conn.execute(sql)
264 conn.commit()
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200265 return({'compilerid':compilerid,'platformid':platformid,'coreid':coreid})
266
267def addConfig(conn,config,fullDate):
268 conn.execute("INSERT INTO CONFIG(compilerid,platformid,coreid,date) VALUES(?,?,?,?)" ,(config['compilerid'],config['platformid'],config['coreid'],fullDate))
269 conn.commit()
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200270
271def addOneBenchmark(elem,fullPath,db,group):
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100272 if os.path.isfile(fullPath):
273 full=pd.read_csv(fullPath,dtype={'OLDID': str} ,keep_default_na = False)
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200274 fullDate = datetime.datetime.now()
275 full['DATE'] = fullDate
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100276 if group:
277 tableName = group
278 else:
279 tableName = elem.data["class"]
280 conn = sqlite3.connect(db)
281 createTableIfMissing(conn,elem,tableName,full)
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200282 config = addRows(conn,elem,tableName,full)
283 addConfig(conn,config,fullDate)
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100284 conn.close()
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200285
286
287def addToDB(benchmark,dbpath,elem,group):
288 if not elem.data["deprecated"]:
289 if elem.params:
290 benchPath = os.path.join(benchmark,elem.fullPath(),"regression.csv")
291 print("Processing %s" % benchPath)
292 addOneBenchmark(elem,benchPath,dbpath,group)
293
294 for c in elem.children:
295 addToDB(benchmark,dbpath,c,group)
296
297
298
299parser = argparse.ArgumentParser(description='Generate summary benchmarks')
300
Christophe Favergeon6f8eee92019-10-09 12:21:27 +0100301parser.add_argument('-f', nargs='?',type = str, default="Output.pickle", help="Test description file path")
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200302parser.add_argument('-b', nargs='?',type = str, default="FullBenchmark", help="Full Benchmark dir path")
303#parser.add_argument('-e', action='store_true', help="Embedded test")
304parser.add_argument('-o', nargs='?',type = str, default="reg.db", help="Regression benchmark database")
305
306parser.add_argument('others', nargs=argparse.REMAINDER)
307
308args = parser.parse_args()
309
310if args.f is not None:
Christophe Favergeon6f8eee92019-10-09 12:21:27 +0100311 #p = parse.Parser()
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200312 # Parse the test description file
Christophe Favergeon6f8eee92019-10-09 12:21:27 +0100313 #root = p.parse(args.f)
314 root=parse.loadRoot(args.f)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200315 d.deprecate(root,args.others)
316 if args.others:
317 group=args.others[0]
318 else:
319 group=None
320 addToDB(args.b,args.o,root,group)
321
322else:
323 parser.print_help()