blob: 32e2f2979537a5a12ad3a86ab490dadda3f2d864 [file] [log] [blame]
Christophe Favergeon37b86222019-07-17 11:49:00 +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=[]
Christophe Favergeon74a31ba2019-09-09 09:14:18 +010022MKBOOLFIELD=['HARDFP', 'FASTMATH', 'NEON', 'HELIUM','UNROLL', 'ROUNDING','OPTIMIZED']
Christophe Favergeon37b86222019-07-17 11:49:00 +020023MKINTFIELD=['ID', 'CYCLES']
Christophe Favergeon4fa1e232020-05-15 12:28:17 +020024MKDATEFIELD=[]
25MKKEYFIELD=['DATE','NAME','CATEGORY', 'PLATFORM', 'CORE', 'COMPILER','TYPE',"RUN"]
Christophe Favergeon37b86222019-07-17 11:49:00 +020026MKKEYFIELDID={'CATEGORY':'categoryid',
Christophe Favergeon4fa1e232020-05-15 12:28:17 +020027 'NAME':'testnameid',
28 'DATE':'testdateid',
Christophe Favergeon37b86222019-07-17 11:49:00 +020029 'PLATFORM':'platformid',
30 'CORE':'coreid',
31 'COMPILER':'compilerid',
Christophe Favergeon8cb37302020-05-13 13:06:58 +020032 'TYPE':'typeid',
33 'RUN':'runid'}
Christophe Favergeon37b86222019-07-17 11:49:00 +020034
Christophe Favergeon4fa1e232020-05-15 12:28:17 +020035# For csv table value extraction
36VALSTRFIELD=['TESTNAME','VERSION']
Christophe Favergeon74a31ba2019-09-09 09:14:18 +010037VALBOOLFIELD=['HARDFP', 'FASTMATH', 'NEON', 'HELIUM','UNROLL', 'ROUNDING','OPTIMIZED']
Christophe Favergeon37b86222019-07-17 11:49:00 +020038VALINTFIELD=['ID', 'CYCLES']
Christophe Favergeon4fa1e232020-05-15 12:28:17 +020039VALDATEFIELD=[]
40# Some of those fields may be created by the parsing of other fields
41VALKEYFIELD=['DATE','NAME','CATEGORY', 'PLATFORM', 'CORE', 'COMPILER','TYPE']
Christophe Favergeon37b86222019-07-17 11:49:00 +020042
43def joinit(iterable, delimiter):
44 it = iter(iterable)
45 yield next(it)
46 for x in it:
47 yield delimiter
48 yield x
49
50def tableExists(c,tableName):
51 req=(tableName,)
52 r=c.execute("SELECT name FROM sqlite_master WHERE type='table' AND name=?",req)
53 return(r.fetchone() != None)
54
55def diff(first, second):
56 second = set(second)
57 return [item for item in first if item not in second]
58
59def getColumns(elem,full):
60 colsToKeep=[]
61 cols = list(full.columns)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020062 params = list(elem.params.full)
Christophe Favergeon8cb37302020-05-13 13:06:58 +020063 common = diff(cols + ["TYPE","RUN"] , ['OLDID'] + params)
Christophe Favergeon37b86222019-07-17 11:49:00 +020064
65 for field in common:
66 if field in MKSTRFIELD:
67 colsToKeep.append(field)
68 if field in MKINTFIELD:
69 colsToKeep.append(field)
70 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)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020082 params = list(elem.params.full)
Christophe Favergeon8cb37302020-05-13 13:06:58 +020083 common = diff(cols + ["TYPE","RUN"] , ['OLDID'] + params)
Christophe Favergeon058b63b2019-07-25 10:40:32 +020084
85 sql += "%sid INTEGER PRIMARY KEY" % (tableName)
86 start = ","
Christophe Favergeon37b86222019-07-17 11:49:00 +020087
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)
97 if field in MKKEYFIELD:
98 sql += "%s\n %s INTEGER" % (start,MKKEYFIELDID[field])
99 if field in MKDATEFIELD:
100 sql += "%s\n %s TEXT" % (start,field)
101 if field in MKBOOLFIELD:
102 sql += "%s\n %s INTEGER" % (start,field)
103 start = ","
104 # Create foreign keys
105 sql += "%sFOREIGN KEY(typeid) REFERENCES TYPE(typeid)," % start
106 sql += "FOREIGN KEY(categoryid) REFERENCES CATEGORY(categoryid),"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200107 sql += "FOREIGN KEY(testnameid) REFERENCES TESTNAME(testnameid),"
108 sql += "FOREIGN KEY(testdateid) REFERENCES TESTDATE(testdateid),"
Christophe Favergeon37b86222019-07-17 11:49:00 +0200109 sql += "FOREIGN KEY(platformid) REFERENCES PLATFORM(platformid),"
110 sql += "FOREIGN KEY(coreid) REFERENCES CORE(coreid),"
111 sql += "FOREIGN KEY(compilerid) REFERENCES COMPILER(compilerid)"
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200112 sql += "FOREIGN KEY(runid) REFERENCES RUN(runid)"
Christophe Favergeon37b86222019-07-17 11:49:00 +0200113 sql += " )"
Christophe Favergeon37b86222019-07-17 11:49:00 +0200114 conn.execute(sql)
115
116# Find the key or add it in a table
117def findInTable(conn,table,keystr,strv,key):
118 #print(sql)
119 r = conn.execute("select %s from %s where %s=?" % (key,table,keystr),(strv,))
120 result=r.fetchone()
121 if result != None:
122 return(result[0])
123 else:
124 conn.execute("INSERT INTO %s(%s) VALUES(?)" % (table,keystr),(strv,))
125 conn.commit()
126 r = conn.execute("select %s from %s where %s=?" % (key,table,keystr),(strv,))
127 result=r.fetchone()
128 if result != None:
129 #print(result)
130 return(result[0])
131 else:
132 return(None)
133
134def findInCompilerTable(conn,kind,version):
135 #print(sql)
136 r = conn.execute("select compilerid from COMPILER where compilerkindid=? AND version=?" , (kind,version))
137 result=r.fetchone()
138 if result != None:
139 return(result[0])
140 else:
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200141 fullDate = datetime.datetime.now()
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200142 dateid = findInTable(conn,"TESTDATE","date",str(fullDate),"testdateid")
143 conn.execute("INSERT INTO COMPILER(compilerkindid,version,testdateid) VALUES(?,?,?)" ,(kind,version,dateid))
Christophe Favergeon37b86222019-07-17 11:49:00 +0200144 conn.commit()
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200145 r = conn.execute("select compilerid from COMPILER where compilerkindid=? AND version=? AND testdateid=?" , (kind,version,dateid))
Christophe Favergeon37b86222019-07-17 11:49:00 +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 Favergeon37b86222019-07-17 11:49:00 +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 Favergeon37b86222019-07-17 11:49:00 +0200160 keep = getColumns(elem,full)
161 cols = list(full.columns)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200162 params = list(elem.params.full)
Christophe Favergeon37b86222019-07-17 11:49:00 +0200163 common = diff(["TYPE"] + cols , ['OLDID'] + params)
Christophe Favergeon058b63b2019-07-25 10:40:32 +0200164 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)
Christophe Favergeon37b86222019-07-17 11:49:00 +0200173 #print(full)
174 for index, row in full.iterrows():
Christophe Favergeon058b63b2019-07-25 10:40:32 +0200175 sql = "INSERT INTO %s(%s) VALUES(" % (tableName,colNames)
Christophe Favergeon37b86222019-07-17 11:49:00 +0200176 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]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200184 if field == "TESTNAME":
185 testname = row[field]
186 if re.match(r'^.*_f64',testname):
Christophe Favergeon37b86222019-07-17 11:49:00 +0200187 keys["TYPE"] = "f64"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200188 if re.match(r'^.*_f32',testname):
Christophe Favergeon37b86222019-07-17 11:49:00 +0200189 keys["TYPE"] = "f32"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200190 if re.match(r'^.*_f16',testname):
Christophe Favergeon37b86222019-07-17 11:49:00 +0200191 keys["TYPE"] = "f16"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200192 if re.match(r'^.*_q31',testname):
Christophe Favergeon37b86222019-07-17 11:49:00 +0200193 keys["TYPE"] = "q31"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200194 if re.match(r'^.*_q15',testname):
Christophe Favergeon37b86222019-07-17 11:49:00 +0200195 keys["TYPE"] = "q15"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200196 if re.match(r'^.*_q7',testname):
Christophe Favergeon37b86222019-07-17 11:49:00 +0200197 keys["TYPE"] = "q7"
198
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200199 if re.match(r'^.*_s8',testname):
Christophe Favergeon37b86222019-07-17 11:49:00 +0200200 keys["TYPE"] = "s8"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200201 if re.match(r'^.*_u8',testname):
Christophe Favergeon37b86222019-07-17 11:49:00 +0200202 keys["TYPE"] = "u8"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200203 if re.match(r'^.*_s16',testname):
Christophe Favergeon37b86222019-07-17 11:49:00 +0200204 keys["TYPE"] = "s16"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200205 if re.match(r'^.*_u16',testname):
Christophe Favergeon37b86222019-07-17 11:49:00 +0200206 keys["TYPE"] = "u16"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200207 if re.match(r'^.*_s32',testname):
Christophe Favergeon37b86222019-07-17 11:49:00 +0200208 keys["TYPE"] = "s32"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200209 if re.match(r'^.*_u32',testname):
Christophe Favergeon37b86222019-07-17 11:49:00 +0200210 keys["TYPE"] = "u32"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200211 if re.match(r'^.*_s64',testname):
Christophe Favergeon37b86222019-07-17 11:49:00 +0200212 keys["TYPE"] = "s64"
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200213 if re.match(r'^.*_u64',testname):
Christophe Favergeon37b86222019-07-17 11:49:00 +0200214 keys["TYPE"] = "u64"
215
216 if field in VALINTFIELD:
217 keys[field]=row[field]
218 if field in VALDATEFIELD:
219 keys[field]=row[field]
220 if field in VALBOOLFIELD:
221 keys[field]=row[field]
222
223
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200224 keys['RUN']=runid
Christophe Favergeon37b86222019-07-17 11:49:00 +0200225 # Get foreign keys and create missing data
226 for field in common:
227 if field in VALKEYFIELD:
228 if field == "CATEGORY":
Christophe Favergeond6556452020-05-12 07:23:54 +0200229 # Remove type extension to get category name so that
230 # all types are maped to same category which will
231 # help for post processing.
232 testField=re.sub(r'^(.*)[:]([^:]+)(F16|F32|F64|Q31|Q15|Q7)$',r'\1',row[field])
233 val = findInTable(conn,"CATEGORY","category",testField,"categoryid")
Christophe Favergeon37b86222019-07-17 11:49:00 +0200234 keys[field]=val
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200235 if field == "NAME":
236 val = findInTable(conn,"TESTNAME","name",row[field],"testnameid")
237 keys[field]=val
238 if field == "DATE":
239 val = findInTable(conn,"TESTDATE","date",str(row[field]),"testdateid")
240 keys[field]=val
Christophe Favergeon37b86222019-07-17 11:49:00 +0200241 if field == "CORE":
242 val = findInTable(conn,"CORE","coredef",row[field],"coreid")
243 keys[field]=val
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200244 coreid = val
Christophe Favergeon37b86222019-07-17 11:49:00 +0200245 if field == "PLATFORM":
246 val = findInTable(conn,"PLATFORM","platform",row[field],"platformid")
247 keys[field]=val
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200248 platformid = val
Christophe Favergeon37b86222019-07-17 11:49:00 +0200249 if field == "TYPE":
250 val = findInTable(conn,"TYPE","type",keys["TYPE"],"typeid")
251 keys[field]=val
252 if field == "COMPILER":
253 compilerkind = findInTable(conn,"COMPILERKIND","compiler",row[field],"compilerkindid")
254 compiler = findInCompilerTable(conn,compilerkind,keys["VERSION"])
255 keys[field]=compiler
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200256 compilerid = compiler
Christophe Favergeon37b86222019-07-17 11:49:00 +0200257
258 # Generate sql command
259 start = ""
260 for field in params:
261 sql += " %s\n %d" % (start,row[field])
262 start = ","
263
264 for field in keep:
265 if field in MKSTRFIELD or field in MKDATEFIELD:
266 sql += " %s\n \"%s\"" % (start,keys[field])
267 elif field in keep:
268 sql += " %s\n %d" % (start,keys[field])
269 start = ","
270
271 sql += " )"
272 #print(sql)
273 conn.execute(sql)
274 conn.commit()
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200275 return({'compilerid':compilerid,'platformid':platformid,'coreid':coreid})
276
277def addConfig(conn,config,fullDate):
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200278 dateid = findInTable(conn,"TESTDATE","date",str(fullDate),"testdateid")
279 conn.execute("INSERT INTO CONFIG(compilerid,platformid,coreid,testdateid) VALUES(?,?,?,?)" ,(config['compilerid'],config['platformid'],config['coreid'],dateid))
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200280 conn.commit()
Christophe Favergeon37b86222019-07-17 11:49:00 +0200281
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200282def getGroup(a):
283 return(re.sub(r'^(.+)(F64|F32|F16|Q31|Q15|Q7|U32|U16|U8|S32|S16|S8)$',r'\1',a))
284
285def addOneBenchmark(elem,fullPath,db,group,runid):
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100286 if os.path.isfile(fullPath):
287 full=pd.read_csv(fullPath,dtype={'OLDID': str} ,keep_default_na = False)
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200288 fullDate = datetime.datetime.now()
289 full['DATE'] = fullDate
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100290 if group:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200291 tableName = getGroup(group)
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100292 else:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200293 tableName = getGroup(elem.data["class"])
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100294 conn = sqlite3.connect(db)
Christophe Favergeon512b1482020-02-07 11:25:11 +0100295 createTableIfMissing(conn,elem,tableName,full)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200296 config = addRows(conn,elem,tableName,full,runid)
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200297 addConfig(conn,config,fullDate)
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100298 conn.close()
Christophe Favergeon37b86222019-07-17 11:49:00 +0200299
300
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200301def addToDB(benchmark,dbpath,elem,group,runid):
Christophe Favergeon37b86222019-07-17 11:49:00 +0200302 if not elem.data["deprecated"]:
303 if elem.params:
304 benchPath = os.path.join(benchmark,elem.fullPath(),"fullBenchmark.csv")
305 print("Processing %s" % benchPath)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200306 addOneBenchmark(elem,benchPath,dbpath,group,runid)
Christophe Favergeon37b86222019-07-17 11:49:00 +0200307
308 for c in elem.children:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200309 addToDB(benchmark,dbpath,c,group,runid)
Christophe Favergeon37b86222019-07-17 11:49:00 +0200310
311
312
313parser = argparse.ArgumentParser(description='Generate summary benchmarks')
314
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200315parser.add_argument('-f', nargs='?',type = str, default="Output.pickle", help="Pickle")
Christophe Favergeon37b86222019-07-17 11:49:00 +0200316parser.add_argument('-b', nargs='?',type = str, default="FullBenchmark", help="Full Benchmark dir path")
Christophe Favergeon97ce6fd2019-07-29 07:44:23 +0200317#parser.add_argument('-e', action='store_true', help="Embedded test")
Christophe Favergeon37b86222019-07-17 11:49:00 +0200318parser.add_argument('-o', nargs='?',type = str, default="bench.db", help="Benchmark database")
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200319parser.add_argument('-r', nargs='?',type = int, default=0, help="Run ID")
Christophe Favergeon37b86222019-07-17 11:49:00 +0200320
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200321parser.add_argument('others', nargs=argparse.REMAINDER, help="Suite class")
Christophe Favergeon37b86222019-07-17 11:49:00 +0200322
323args = parser.parse_args()
324
325if args.f is not None:
Christophe Favergeon6f8eee92019-10-09 12:21:27 +0100326 #p = parse.Parser()
Christophe Favergeon37b86222019-07-17 11:49:00 +0200327 # Parse the test description file
Christophe Favergeon6f8eee92019-10-09 12:21:27 +0100328 #root = p.parse(args.f)
329 root=parse.loadRoot(args.f)
Christophe Favergeon37b86222019-07-17 11:49:00 +0200330 d.deprecate(root,args.others)
331 if args.others:
332 group=args.others[0]
333 else:
334 group=None
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200335 addToDB(args.b,args.o,root,group,args.r)
Christophe Favergeon37b86222019-07-17 11:49:00 +0200336
337else:
338 parser.print_help()