blob: 1c194695858662cd6a966cc23d26e8c580dca26d [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
Christophe Favergeon4fa1e232020-05-15 12:28:17 +020020# For sql table creation
21MKSTRFIELD=['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 Favergeon4fa1e232020-05-15 12:28:17 +020025MKDATEFIELD=[]
26MKKEYFIELD=['DATE','NAME','CATEGORY', 'PLATFORM', 'CORE', 'COMPILER','TYPE','RUN']
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020027MKKEYFIELDID={'CATEGORY':'categoryid',
Christophe Favergeon4fa1e232020-05-15 12:28:17 +020028 'NAME':'testnameid',
29 'DATE':'testdateid',
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020030 'PLATFORM':'platformid',
31 'CORE':'coreid',
32 'COMPILER':'compilerid',
Christophe Favergeon8cb37302020-05-13 13:06:58 +020033 'TYPE':'typeid',
34 'RUN':'runid'}
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020035
Christophe Favergeon4fa1e232020-05-15 12:28:17 +020036# For csv table value extraction
37VALSTRFIELD=['TESTNAME','VERSION','Regression']
Christophe Favergeon74a31ba2019-09-09 09:14:18 +010038VALBOOLFIELD=['HARDFP', 'FASTMATH', 'NEON', 'HELIUM','UNROLL', 'ROUNDING','OPTIMIZED']
Christophe Favergeon5cacf9d2019-08-14 10:41:17 +020039VALINTFIELD=['ID', 'MAX']
40VALREALFIELD=['MAXREGCOEF']
Christophe Favergeon4fa1e232020-05-15 12:28:17 +020041VALDATEFIELD=[]
42# Some of those fields may be created by the parsing of other fields
43VALKEYFIELD=['DATE','NAME','CATEGORY', 'PLATFORM', 'CORE', 'COMPILER','TYPE']
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020044
45def joinit(iterable, delimiter):
46 it = iter(iterable)
47 yield next(it)
48 for x in it:
49 yield delimiter
50 yield x
51
52def tableExists(c,tableName):
53 req=(tableName,)
54 r=c.execute("SELECT name FROM sqlite_master WHERE type='table' AND name=?",req)
55 return(r.fetchone() != None)
56
57def diff(first, second):
58 second = set(second)
59 return [item for item in first if item not in second]
60
61def getColumns(elem,full):
62 colsToKeep=[]
63 cols = list(full.columns)
64 params=diff(elem.params.full , elem.params.summary)
Christophe Favergeon8cb37302020-05-13 13:06:58 +020065 common = diff(cols + ["TYPE","RUN"] , ['OLDID'] + params)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020066
67 for field in common:
68 if field in MKSTRFIELD:
69 colsToKeep.append(field)
70 if field in MKINTFIELD:
71 colsToKeep.append(field)
Christophe Favergeon5cacf9d2019-08-14 10:41:17 +020072 if field in MKREALFIELD:
73 colsToKeep.append(field)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020074 if field in MKKEYFIELD:
75 colsToKeep.append(field)
76 if field in MKDATEFIELD:
77 colsToKeep.append(field)
78 if field in MKBOOLFIELD:
79 colsToKeep.append(field)
80 return(colsToKeep)
81
82def createTableIfMissing(conn,elem,tableName,full):
83 if not tableExists(conn,tableName):
84 sql = "CREATE TABLE %s (" % tableName
85 cols = list(full.columns)
86 params=diff(elem.params.full , elem.params.summary)
Christophe Favergeon8cb37302020-05-13 13:06:58 +020087 common = diff(cols + ["TYPE","RUN"] , ['OLDID'] + params)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020088
89 sql += "%sid INTEGER PRIMARY KEY" % (tableName)
90 start = ","
91
92 for field in params:
93 sql += " %s\n %s INTEGER" % (start,field)
94 start = ","
95
96 for field in common:
97 if field in MKSTRFIELD:
98 sql += "%s\n %s TEXT" % (start,field)
99 if field in MKINTFIELD:
100 sql += "%s\n %s INTEGER" % (start,field)
Christophe Favergeon5cacf9d2019-08-14 10:41:17 +0200101 if field in MKREALFIELD:
102 sql += "%s\n %s REAL" % (start,field)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200103 if field in MKKEYFIELD:
104 sql += "%s\n %s INTEGER" % (start,MKKEYFIELDID[field])
105 if field in MKDATEFIELD:
106 sql += "%s\n %s TEXT" % (start,field)
107 if field in MKBOOLFIELD:
108 sql += "%s\n %s INTEGER" % (start,field)
109 start = ","
110 # Create foreign keys
111 sql += "%sFOREIGN KEY(typeid) REFERENCES TYPE(typeid)," % start
112 sql += "FOREIGN KEY(categoryid) REFERENCES CATEGORY(categoryid),"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200113 sql += "FOREIGN KEY(testnameid) REFERENCES TESTNAME(testnameid),"
114 sql += "FOREIGN KEY(testdateid) REFERENCES TESTDATE(testdateid),"
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200115 sql += "FOREIGN KEY(platformid) REFERENCES PLATFORM(platformid),"
116 sql += "FOREIGN KEY(coreid) REFERENCES CORE(coreid),"
117 sql += "FOREIGN KEY(compilerid) REFERENCES COMPILER(compilerid)"
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200118 sql += "FOREIGN KEY(runid) REFERENCES RUN(runid)"
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200119 sql += " )"
120 conn.execute(sql)
121
122# Find the key or add it in a table
123def findInTable(conn,table,keystr,strv,key):
124 #print(sql)
125 r = conn.execute("select %s from %s where %s=?" % (key,table,keystr),(strv,))
126 result=r.fetchone()
127 if result != None:
128 return(result[0])
129 else:
130 conn.execute("INSERT INTO %s(%s) VALUES(?)" % (table,keystr),(strv,))
131 conn.commit()
132 r = conn.execute("select %s from %s where %s=?" % (key,table,keystr),(strv,))
133 result=r.fetchone()
134 if result != None:
135 #print(result)
136 return(result[0])
137 else:
138 return(None)
139
140def findInCompilerTable(conn,kind,version):
141 #print(sql)
142 r = conn.execute("select compilerid from COMPILER where compilerkindid=? AND version=?" , (kind,version))
143 result=r.fetchone()
144 if result != None:
145 return(result[0])
146 else:
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200147 fullDate = datetime.datetime.now()
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200148 dateid = findInTable(conn,"TESTDATE","date",str(fullDate),"testdateid")
149 conn.execute("INSERT INTO COMPILER(compilerkindid,version,testdateid) VALUES(?,?,?)" ,(kind,version,dateid))
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200150 conn.commit()
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200151 r = conn.execute("select compilerid from COMPILER where compilerkindid=? AND version=? AND testdateid=?" , (kind,version,dateid))
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200152 result=r.fetchone()
153 if result != None:
154 #print(result)
155 return(result[0])
156 else:
157 return(None)
158
159
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200160def addRows(conn,elem,tableName,full,runid=0):
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200161 # List of columns we have in DB which is
162 # different from the columns in the table
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200163 compilerid = 0
164 platformid = 0
165 coreid = 0
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200166 keep = getColumns(elem,full)
167 cols = list(full.columns)
168 params=diff(elem.params.full , elem.params.summary)
169 common = diff(["TYPE"] + cols , ['OLDID'] + params)
170 colNameList = []
171 for c in params + keep:
172 if c in MKKEYFIELD:
173 colNameList.append(MKKEYFIELDID[c])
174 else:
175 colNameList.append(c)
176 colNames = "".join(joinit(colNameList,","))
177 #print(colNameList)
178 #print(colNames)
179 #print(full)
180 for index, row in full.iterrows():
181 sql = "INSERT INTO %s(%s) VALUES(" % (tableName,colNames)
182 keys = {}
183
184 # Get data from columns
185 for field in common:
186 if field in VALSTRFIELD:
187 keys[field]=row[field]
188 if field == "NAME":
189 name = row[field]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200190 if field == "TESTNAME":
191 testname = row[field]
192 if re.match(r'^.*_f64',testname):
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200193 keys["TYPE"] = "f64"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200194 if re.match(r'^.*_f32',testname):
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200195 keys["TYPE"] = "f32"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200196 if re.match(r'^.*_f16',testname):
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200197 keys["TYPE"] = "f16"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200198 if re.match(r'^.*_q31',testname):
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200199 keys["TYPE"] = "q31"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200200 if re.match(r'^.*_q15',testname):
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200201 keys["TYPE"] = "q15"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200202 if re.match(r'^.*_q7',testname):
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200203 keys["TYPE"] = "q7"
204
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200205 if re.match(r'^.*_s8',testname):
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200206 keys["TYPE"] = "s8"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200207 if re.match(r'^.*_u8',testname):
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200208 keys["TYPE"] = "u8"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200209 if re.match(r'^.*_s16',testname):
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200210 keys["TYPE"] = "s16"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200211 if re.match(r'^.*_u16',testname):
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200212 keys["TYPE"] = "u16"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200213 if re.match(r'^.*_s32',testname):
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200214 keys["TYPE"] = "s32"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200215 if re.match(r'^.*_u32',testname):
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200216 keys["TYPE"] = "u32"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200217 if re.match(r'^.*_s64',testname):
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200218 keys["TYPE"] = "s64"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200219 if re.match(r'^.*_u64',testname):
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200220 keys["TYPE"] = "u64"
221
222 if field in VALINTFIELD:
223 keys[field]=row[field]
Christophe Favergeon5cacf9d2019-08-14 10:41:17 +0200224 if field in VALREALFIELD:
225 keys[field]=row[field]
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200226 if field in VALDATEFIELD:
227 keys[field]=row[field]
228 if field in VALBOOLFIELD:
229 keys[field]=row[field]
230
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200231 keys['RUN']=runid
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200232 # Get foreign keys and create missing data
233 for field in common:
234 if field in VALKEYFIELD:
235 if field == "CATEGORY":
Christophe Favergeond6556452020-05-12 07:23:54 +0200236 # Remove type extension to get category name so that
237 # all types are maped to same category which will
238 # help for post processing.
239 testField=re.sub(r'^(.*)[:]([^:]+)(F16|F32|F64|Q31|Q15|Q7)$',r'\1',row[field])
240 val = findInTable(conn,"CATEGORY","category",testField,"categoryid")
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200241 keys[field]=val
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200242 if field == "NAME":
243 val = findInTable(conn,"TESTNAME","name",row[field],"testnameid")
244 keys[field]=val
245 if field == "DATE":
246 val = findInTable(conn,"TESTDATE","date",str(row[field]),"testdateid")
247 keys[field]=val
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200248 if field == "CORE":
249 val = findInTable(conn,"CORE","coredef",row[field],"coreid")
250 keys[field]=val
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200251 coreid = val
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200252 if field == "PLATFORM":
253 val = findInTable(conn,"PLATFORM","platform",row[field],"platformid")
254 keys[field]=val
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200255 platformid = val
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200256 if field == "TYPE":
257 val = findInTable(conn,"TYPE","type",keys["TYPE"],"typeid")
258 keys[field]=val
259 if field == "COMPILER":
260 compilerkind = findInTable(conn,"COMPILERKIND","compiler",row[field],"compilerkindid")
261 compiler = findInCompilerTable(conn,compilerkind,keys["VERSION"])
262 keys[field]=compiler
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200263 compilerid = compiler
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200264
265 # Generate sql command
266 start = ""
267 for field in params:
268 sql += " %s\n %d" % (start,row[field])
269 start = ","
270
271 for field in keep:
272 if field in MKSTRFIELD or field in MKDATEFIELD:
273 sql += " %s\n \"%s\"" % (start,keys[field])
274 elif field in keep:
Christophe Favergeon5cacf9d2019-08-14 10:41:17 +0200275 if field in VALREALFIELD:
276 sql += " %s\n %f" % (start,keys[field])
277 else:
278 sql += " %s\n %d" % (start,keys[field])
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200279 start = ","
280
281 sql += " )"
282 #print(sql)
283 conn.execute(sql)
284 conn.commit()
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200285 return({'compilerid':compilerid,'platformid':platformid,'coreid':coreid})
286
287def addConfig(conn,config,fullDate):
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200288 dateid = findInTable(conn,"TESTDATE","date",str(fullDate),"testdateid")
289 conn.execute("INSERT INTO CONFIG(compilerid,platformid,coreid,testdateid) VALUES(?,?,?,?)" ,(config['compilerid'],config['platformid'],config['coreid'],dateid))
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200290 conn.commit()
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200291
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200292def getGroup(a):
293 return(re.sub(r'^(.+)(F64|F32|F16|Q31|Q15|Q7|U32|U16|U8|S32|S16|S8)$',r'\1',a))
294
295def addOneBenchmark(elem,fullPath,db,group,runid):
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100296 if os.path.isfile(fullPath):
297 full=pd.read_csv(fullPath,dtype={'OLDID': str} ,keep_default_na = False)
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200298 fullDate = datetime.datetime.now()
299 full['DATE'] = fullDate
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100300 if group:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200301 tableName = getGroup(group)
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100302 else:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200303 tableName = getGroup(elem.data["class"])
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100304 conn = sqlite3.connect(db)
305 createTableIfMissing(conn,elem,tableName,full)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200306 config = addRows(conn,elem,tableName,full,runid)
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200307 addConfig(conn,config,fullDate)
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100308 conn.close()
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200309
310
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200311def addToDB(benchmark,dbpath,elem,group,runid):
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200312 if not elem.data["deprecated"]:
313 if elem.params:
314 benchPath = os.path.join(benchmark,elem.fullPath(),"regression.csv")
315 print("Processing %s" % benchPath)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200316 addOneBenchmark(elem,benchPath,dbpath,group,runid)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200317
318 for c in elem.children:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200319 addToDB(benchmark,dbpath,c,group,runid)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200320
321
322
323parser = argparse.ArgumentParser(description='Generate summary benchmarks')
324
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200325parser.add_argument('-f', nargs='?',type = str, default="Output.pickle", help="Pickle path")
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200326parser.add_argument('-b', nargs='?',type = str, default="FullBenchmark", help="Full Benchmark dir path")
327#parser.add_argument('-e', action='store_true', help="Embedded test")
328parser.add_argument('-o', nargs='?',type = str, default="reg.db", help="Regression benchmark database")
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200329parser.add_argument('-r', nargs='?',type = int, default=0, help="Run ID")
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200330
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200331parser.add_argument('others', nargs=argparse.REMAINDER, help="Suite class")
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200332
333args = parser.parse_args()
334
335if args.f is not None:
Christophe Favergeon6f8eee92019-10-09 12:21:27 +0100336 #p = parse.Parser()
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200337 # Parse the test description file
Christophe Favergeon6f8eee92019-10-09 12:21:27 +0100338 #root = p.parse(args.f)
339 root=parse.loadRoot(args.f)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200340 d.deprecate(root,args.others)
341 if args.others:
342 group=args.others[0]
343 else:
344 group=None
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200345 addToDB(args.b,args.o,root,group,args.r)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200346
347else:
348 parser.print_help()