blob: 3e7a54a65e2224ae09adf3d68091213ea210bba4 [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":
Christophe Favergeond6556452020-05-12 07:23:54 +0200226 # Remove type extension to get category name so that
227 # all types are maped to same category which will
228 # help for post processing.
229 testField=re.sub(r'^(.*)[:]([^:]+)(F16|F32|F64|Q31|Q15|Q7)$',r'\1',row[field])
230 val = findInTable(conn,"CATEGORY","category",testField,"categoryid")
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200231 keys[field]=val
232 if field == "CORE":
233 val = findInTable(conn,"CORE","coredef",row[field],"coreid")
234 keys[field]=val
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200235 coreid = val
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200236 if field == "PLATFORM":
237 val = findInTable(conn,"PLATFORM","platform",row[field],"platformid")
238 keys[field]=val
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200239 platformid = val
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200240 if field == "TYPE":
241 val = findInTable(conn,"TYPE","type",keys["TYPE"],"typeid")
242 keys[field]=val
243 if field == "COMPILER":
244 compilerkind = findInTable(conn,"COMPILERKIND","compiler",row[field],"compilerkindid")
245 compiler = findInCompilerTable(conn,compilerkind,keys["VERSION"])
246 keys[field]=compiler
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200247 compilerid = compiler
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200248
249 # Generate sql command
250 start = ""
251 for field in params:
252 sql += " %s\n %d" % (start,row[field])
253 start = ","
254
255 for field in keep:
256 if field in MKSTRFIELD or field in MKDATEFIELD:
257 sql += " %s\n \"%s\"" % (start,keys[field])
258 elif field in keep:
Christophe Favergeon5cacf9d2019-08-14 10:41:17 +0200259 if field in VALREALFIELD:
260 sql += " %s\n %f" % (start,keys[field])
261 else:
262 sql += " %s\n %d" % (start,keys[field])
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200263 start = ","
264
265 sql += " )"
266 #print(sql)
267 conn.execute(sql)
268 conn.commit()
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200269 return({'compilerid':compilerid,'platformid':platformid,'coreid':coreid})
270
271def addConfig(conn,config,fullDate):
272 conn.execute("INSERT INTO CONFIG(compilerid,platformid,coreid,date) VALUES(?,?,?,?)" ,(config['compilerid'],config['platformid'],config['coreid'],fullDate))
273 conn.commit()
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200274
275def addOneBenchmark(elem,fullPath,db,group):
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100276 if os.path.isfile(fullPath):
277 full=pd.read_csv(fullPath,dtype={'OLDID': str} ,keep_default_na = False)
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200278 fullDate = datetime.datetime.now()
279 full['DATE'] = fullDate
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100280 if group:
281 tableName = group
282 else:
283 tableName = elem.data["class"]
284 conn = sqlite3.connect(db)
285 createTableIfMissing(conn,elem,tableName,full)
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200286 config = addRows(conn,elem,tableName,full)
287 addConfig(conn,config,fullDate)
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100288 conn.close()
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200289
290
291def addToDB(benchmark,dbpath,elem,group):
292 if not elem.data["deprecated"]:
293 if elem.params:
294 benchPath = os.path.join(benchmark,elem.fullPath(),"regression.csv")
295 print("Processing %s" % benchPath)
296 addOneBenchmark(elem,benchPath,dbpath,group)
297
298 for c in elem.children:
299 addToDB(benchmark,dbpath,c,group)
300
301
302
303parser = argparse.ArgumentParser(description='Generate summary benchmarks')
304
Christophe Favergeon512b1482020-02-07 11:25:11 +0100305parser.add_argument('-f', nargs='?',type = str, default="Output.pickle", help="File path")
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200306parser.add_argument('-b', nargs='?',type = str, default="FullBenchmark", help="Full Benchmark dir path")
307#parser.add_argument('-e', action='store_true', help="Embedded test")
308parser.add_argument('-o', nargs='?',type = str, default="reg.db", help="Regression benchmark database")
309
310parser.add_argument('others', nargs=argparse.REMAINDER)
311
312args = parser.parse_args()
313
314if args.f is not None:
Christophe Favergeon6f8eee92019-10-09 12:21:27 +0100315 #p = parse.Parser()
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200316 # Parse the test description file
Christophe Favergeon6f8eee92019-10-09 12:21:27 +0100317 #root = p.parse(args.f)
318 root=parse.loadRoot(args.f)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200319 d.deprecate(root,args.others)
320 if args.others:
321 group=args.others[0]
322 else:
323 group=None
324 addToDB(args.b,args.o,root,group)
325
326else:
327 parser.print_help()