blob: cf6297d44749e020b8d389e573509d6eb3026f9d [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']
Christophe Favergeon8cb37302020-05-13 13:06:58 +020026MKKEYFIELD=['CATEGORY', 'PLATFORM', 'CORE', 'COMPILER','TYPE','RUN']
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020027MKKEYFIELDID={'CATEGORY':'categoryid',
28 'PLATFORM':'platformid',
29 'CORE':'coreid',
30 'COMPILER':'compilerid',
Christophe Favergeon8cb37302020-05-13 13:06:58 +020031 'TYPE':'typeid',
32 'RUN':'runid'}
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020033
34# For table value extraction
35VALSTRFIELD=['NAME','VERSION','Regression']
Christophe Favergeon74a31ba2019-09-09 09:14:18 +010036VALBOOLFIELD=['HARDFP', 'FASTMATH', 'NEON', 'HELIUM','UNROLL', 'ROUNDING','OPTIMIZED']
Christophe Favergeon5cacf9d2019-08-14 10:41:17 +020037VALINTFIELD=['ID', 'MAX']
38VALREALFIELD=['MAXREGCOEF']
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020039VALDATEFIELD=['DATE']
40VALKEYFIELD=['CATEGORY', 'PLATFORM', 'CORE', 'COMPILER','TYPE']
41
42def joinit(iterable, delimiter):
43 it = iter(iterable)
44 yield next(it)
45 for x in it:
46 yield delimiter
47 yield x
48
49def tableExists(c,tableName):
50 req=(tableName,)
51 r=c.execute("SELECT name FROM sqlite_master WHERE type='table' AND name=?",req)
52 return(r.fetchone() != None)
53
54def diff(first, second):
55 second = set(second)
56 return [item for item in first if item not in second]
57
58def getColumns(elem,full):
59 colsToKeep=[]
60 cols = list(full.columns)
61 params=diff(elem.params.full , elem.params.summary)
Christophe Favergeon8cb37302020-05-13 13:06:58 +020062 common = diff(cols + ["TYPE","RUN"] , ['OLDID'] + params)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020063
64 for field in common:
65 if field in MKSTRFIELD:
66 colsToKeep.append(field)
67 if field in MKINTFIELD:
68 colsToKeep.append(field)
Christophe Favergeon5cacf9d2019-08-14 10:41:17 +020069 if field in MKREALFIELD:
70 colsToKeep.append(field)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020071 if field in MKKEYFIELD:
72 colsToKeep.append(field)
73 if field in MKDATEFIELD:
74 colsToKeep.append(field)
75 if field in MKBOOLFIELD:
76 colsToKeep.append(field)
77 return(colsToKeep)
78
79def createTableIfMissing(conn,elem,tableName,full):
80 if not tableExists(conn,tableName):
81 sql = "CREATE TABLE %s (" % tableName
82 cols = list(full.columns)
83 params=diff(elem.params.full , elem.params.summary)
Christophe Favergeon8cb37302020-05-13 13:06:58 +020084 common = diff(cols + ["TYPE","RUN"] , ['OLDID'] + params)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020085
86 sql += "%sid INTEGER PRIMARY KEY" % (tableName)
87 start = ","
88
89 for field in params:
90 sql += " %s\n %s INTEGER" % (start,field)
91 start = ","
92
93 for field in common:
94 if field in MKSTRFIELD:
95 sql += "%s\n %s TEXT" % (start,field)
96 if field in MKINTFIELD:
97 sql += "%s\n %s INTEGER" % (start,field)
Christophe Favergeon5cacf9d2019-08-14 10:41:17 +020098 if field in MKREALFIELD:
99 sql += "%s\n %s REAL" % (start,field)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200100 if field in MKKEYFIELD:
101 sql += "%s\n %s INTEGER" % (start,MKKEYFIELDID[field])
102 if field in MKDATEFIELD:
103 sql += "%s\n %s TEXT" % (start,field)
104 if field in MKBOOLFIELD:
105 sql += "%s\n %s INTEGER" % (start,field)
106 start = ","
107 # Create foreign keys
108 sql += "%sFOREIGN KEY(typeid) REFERENCES TYPE(typeid)," % start
109 sql += "FOREIGN KEY(categoryid) REFERENCES CATEGORY(categoryid),"
110 sql += "FOREIGN KEY(platformid) REFERENCES PLATFORM(platformid),"
111 sql += "FOREIGN KEY(coreid) REFERENCES CORE(coreid),"
112 sql += "FOREIGN KEY(compilerid) REFERENCES COMPILER(compilerid)"
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200113 sql += "FOREIGN KEY(runid) REFERENCES RUN(runid)"
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200114 sql += " )"
115 conn.execute(sql)
116
117# Find the key or add it in a table
118def findInTable(conn,table,keystr,strv,key):
119 #print(sql)
120 r = conn.execute("select %s from %s where %s=?" % (key,table,keystr),(strv,))
121 result=r.fetchone()
122 if result != None:
123 return(result[0])
124 else:
125 conn.execute("INSERT INTO %s(%s) VALUES(?)" % (table,keystr),(strv,))
126 conn.commit()
127 r = conn.execute("select %s from %s where %s=?" % (key,table,keystr),(strv,))
128 result=r.fetchone()
129 if result != None:
130 #print(result)
131 return(result[0])
132 else:
133 return(None)
134
135def findInCompilerTable(conn,kind,version):
136 #print(sql)
137 r = conn.execute("select compilerid from COMPILER where compilerkindid=? AND version=?" , (kind,version))
138 result=r.fetchone()
139 if result != None:
140 return(result[0])
141 else:
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200142 fullDate = datetime.datetime.now()
143 conn.execute("INSERT INTO COMPILER(compilerkindid,version,date) VALUES(?,?,?)" ,(kind,version,fullDate))
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200144 conn.commit()
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200145 r = conn.execute("select compilerid from COMPILER where compilerkindid=? AND version=? AND date=?" , (kind,version,fullDate))
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200146 result=r.fetchone()
147 if result != None:
148 #print(result)
149 return(result[0])
150 else:
151 return(None)
152
153
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200154def addRows(conn,elem,tableName,full,runid=0):
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200155 # List of columns we have in DB which is
156 # different from the columns in the table
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200157 compilerid = 0
158 platformid = 0
159 coreid = 0
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200160 keep = getColumns(elem,full)
161 cols = list(full.columns)
162 params=diff(elem.params.full , elem.params.summary)
163 common = diff(["TYPE"] + cols , ['OLDID'] + params)
164 colNameList = []
165 for c in params + keep:
166 if c in MKKEYFIELD:
167 colNameList.append(MKKEYFIELDID[c])
168 else:
169 colNameList.append(c)
170 colNames = "".join(joinit(colNameList,","))
171 #print(colNameList)
172 #print(colNames)
173 #print(full)
174 for index, row in full.iterrows():
175 sql = "INSERT INTO %s(%s) VALUES(" % (tableName,colNames)
176 keys = {}
177
178 # Get data from columns
179 for field in common:
180 if field in VALSTRFIELD:
181 keys[field]=row[field]
182 if field == "NAME":
183 name = row[field]
184 if re.match(r'^.*_f64',name):
185 keys["TYPE"] = "f64"
186 if re.match(r'^.*_f32',name):
187 keys["TYPE"] = "f32"
188 if re.match(r'^.*_f16',name):
189 keys["TYPE"] = "f16"
190 if re.match(r'^.*_q31',name):
191 keys["TYPE"] = "q31"
192 if re.match(r'^.*_q15',name):
193 keys["TYPE"] = "q15"
194 if re.match(r'^.*_q7',name):
195 keys["TYPE"] = "q7"
196
197 if re.match(r'^.*_s8',name):
198 keys["TYPE"] = "s8"
199 if re.match(r'^.*_u8',name):
200 keys["TYPE"] = "u8"
201 if re.match(r'^.*_s16',name):
202 keys["TYPE"] = "s16"
203 if re.match(r'^.*_u16',name):
204 keys["TYPE"] = "u16"
205 if re.match(r'^.*_s32',name):
206 keys["TYPE"] = "s32"
207 if re.match(r'^.*_u32',name):
208 keys["TYPE"] = "u32"
209 if re.match(r'^.*_s64',name):
210 keys["TYPE"] = "s64"
211 if re.match(r'^.*_u64',name):
212 keys["TYPE"] = "u64"
213
214 if field in VALINTFIELD:
215 keys[field]=row[field]
Christophe Favergeon5cacf9d2019-08-14 10:41:17 +0200216 if field in VALREALFIELD:
217 keys[field]=row[field]
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200218 if field in VALDATEFIELD:
219 keys[field]=row[field]
220 if field in VALBOOLFIELD:
221 keys[field]=row[field]
222
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200223 keys['RUN']=runid
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200224 # Get foreign keys and create missing data
225 for field in common:
226 if field in VALKEYFIELD:
227 if field == "CATEGORY":
Christophe Favergeond6556452020-05-12 07:23:54 +0200228 # Remove type extension to get category name so that
229 # all types are maped to same category which will
230 # help for post processing.
231 testField=re.sub(r'^(.*)[:]([^:]+)(F16|F32|F64|Q31|Q15|Q7)$',r'\1',row[field])
232 val = findInTable(conn,"CATEGORY","category",testField,"categoryid")
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200233 keys[field]=val
234 if field == "CORE":
235 val = findInTable(conn,"CORE","coredef",row[field],"coreid")
236 keys[field]=val
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200237 coreid = val
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200238 if field == "PLATFORM":
239 val = findInTable(conn,"PLATFORM","platform",row[field],"platformid")
240 keys[field]=val
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200241 platformid = val
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200242 if field == "TYPE":
243 val = findInTable(conn,"TYPE","type",keys["TYPE"],"typeid")
244 keys[field]=val
245 if field == "COMPILER":
246 compilerkind = findInTable(conn,"COMPILERKIND","compiler",row[field],"compilerkindid")
247 compiler = findInCompilerTable(conn,compilerkind,keys["VERSION"])
248 keys[field]=compiler
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200249 compilerid = compiler
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200250
251 # Generate sql command
252 start = ""
253 for field in params:
254 sql += " %s\n %d" % (start,row[field])
255 start = ","
256
257 for field in keep:
258 if field in MKSTRFIELD or field in MKDATEFIELD:
259 sql += " %s\n \"%s\"" % (start,keys[field])
260 elif field in keep:
Christophe Favergeon5cacf9d2019-08-14 10:41:17 +0200261 if field in VALREALFIELD:
262 sql += " %s\n %f" % (start,keys[field])
263 else:
264 sql += " %s\n %d" % (start,keys[field])
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200265 start = ","
266
267 sql += " )"
268 #print(sql)
269 conn.execute(sql)
270 conn.commit()
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200271 return({'compilerid':compilerid,'platformid':platformid,'coreid':coreid})
272
273def addConfig(conn,config,fullDate):
274 conn.execute("INSERT INTO CONFIG(compilerid,platformid,coreid,date) VALUES(?,?,?,?)" ,(config['compilerid'],config['platformid'],config['coreid'],fullDate))
275 conn.commit()
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200276
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200277def getGroup(a):
278 return(re.sub(r'^(.+)(F64|F32|F16|Q31|Q15|Q7|U32|U16|U8|S32|S16|S8)$',r'\1',a))
279
280def addOneBenchmark(elem,fullPath,db,group,runid):
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100281 if os.path.isfile(fullPath):
282 full=pd.read_csv(fullPath,dtype={'OLDID': str} ,keep_default_na = False)
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200283 fullDate = datetime.datetime.now()
284 full['DATE'] = fullDate
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100285 if group:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200286 tableName = getGroup(group)
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100287 else:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200288 tableName = getGroup(elem.data["class"])
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100289 conn = sqlite3.connect(db)
290 createTableIfMissing(conn,elem,tableName,full)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200291 config = addRows(conn,elem,tableName,full,runid)
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200292 addConfig(conn,config,fullDate)
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100293 conn.close()
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200294
295
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200296def addToDB(benchmark,dbpath,elem,group,runid):
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200297 if not elem.data["deprecated"]:
298 if elem.params:
299 benchPath = os.path.join(benchmark,elem.fullPath(),"regression.csv")
300 print("Processing %s" % benchPath)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200301 addOneBenchmark(elem,benchPath,dbpath,group,runid)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200302
303 for c in elem.children:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200304 addToDB(benchmark,dbpath,c,group,runid)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200305
306
307
308parser = argparse.ArgumentParser(description='Generate summary benchmarks')
309
Christophe Favergeon512b1482020-02-07 11:25:11 +0100310parser.add_argument('-f', nargs='?',type = str, default="Output.pickle", help="File path")
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200311parser.add_argument('-b', nargs='?',type = str, default="FullBenchmark", help="Full Benchmark dir path")
312#parser.add_argument('-e', action='store_true', help="Embedded test")
313parser.add_argument('-o', nargs='?',type = str, default="reg.db", help="Regression benchmark database")
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200314parser.add_argument('-r', nargs='?',type = int, default=0, help="Run ID")
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200315
316parser.add_argument('others', nargs=argparse.REMAINDER)
317
318args = parser.parse_args()
319
320if args.f is not None:
Christophe Favergeon6f8eee92019-10-09 12:21:27 +0100321 #p = parse.Parser()
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200322 # Parse the test description file
Christophe Favergeon6f8eee92019-10-09 12:21:27 +0100323 #root = p.parse(args.f)
324 root=parse.loadRoot(args.f)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200325 d.deprecate(root,args.others)
326 if args.others:
327 group=args.others[0]
328 else:
329 group=None
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200330 addToDB(args.b,args.o,root,group,args.r)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200331
332else:
333 parser.print_help()