blob: 5b43cff03fcc73bb756273e0aa4683e64f0a69c5 [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
20# For table creation
21MKSTRFIELD=['NAME']
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']
24MKDATEFIELD=['DATE']
Christophe Favergeon8cb37302020-05-13 13:06:58 +020025MKKEYFIELD=['CATEGORY', 'PLATFORM', 'CORE', 'COMPILER','TYPE',"RUN"]
Christophe Favergeon37b86222019-07-17 11:49:00 +020026MKKEYFIELDID={'CATEGORY':'categoryid',
27 'PLATFORM':'platformid',
28 'CORE':'coreid',
29 'COMPILER':'compilerid',
Christophe Favergeon8cb37302020-05-13 13:06:58 +020030 'TYPE':'typeid',
31 'RUN':'runid'}
Christophe Favergeon37b86222019-07-17 11:49:00 +020032
33# For table value extraction
34VALSTRFIELD=['NAME','VERSION']
Christophe Favergeon74a31ba2019-09-09 09:14:18 +010035VALBOOLFIELD=['HARDFP', 'FASTMATH', 'NEON', 'HELIUM','UNROLL', 'ROUNDING','OPTIMIZED']
Christophe Favergeon37b86222019-07-17 11:49:00 +020036VALINTFIELD=['ID', 'CYCLES']
37VALDATEFIELD=['DATE']
38VALKEYFIELD=['CATEGORY', 'PLATFORM', 'CORE', 'COMPILER','TYPE']
39
40def joinit(iterable, delimiter):
41 it = iter(iterable)
42 yield next(it)
43 for x in it:
44 yield delimiter
45 yield x
46
47def tableExists(c,tableName):
48 req=(tableName,)
49 r=c.execute("SELECT name FROM sqlite_master WHERE type='table' AND name=?",req)
50 return(r.fetchone() != None)
51
52def diff(first, second):
53 second = set(second)
54 return [item for item in first if item not in second]
55
56def getColumns(elem,full):
57 colsToKeep=[]
58 cols = list(full.columns)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020059 params = list(elem.params.full)
Christophe Favergeon8cb37302020-05-13 13:06:58 +020060 common = diff(cols + ["TYPE","RUN"] , ['OLDID'] + params)
Christophe Favergeon37b86222019-07-17 11:49:00 +020061
62 for field in common:
63 if field in MKSTRFIELD:
64 colsToKeep.append(field)
65 if field in MKINTFIELD:
66 colsToKeep.append(field)
67 if field in MKKEYFIELD:
68 colsToKeep.append(field)
69 if field in MKDATEFIELD:
70 colsToKeep.append(field)
71 if field in MKBOOLFIELD:
72 colsToKeep.append(field)
73 return(colsToKeep)
74
75def createTableIfMissing(conn,elem,tableName,full):
76 if not tableExists(conn,tableName):
77 sql = "CREATE TABLE %s (" % tableName
78 cols = list(full.columns)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020079 params = list(elem.params.full)
Christophe Favergeon8cb37302020-05-13 13:06:58 +020080 common = diff(cols + ["TYPE","RUN"] , ['OLDID'] + params)
Christophe Favergeon058b63b2019-07-25 10:40:32 +020081
82 sql += "%sid INTEGER PRIMARY KEY" % (tableName)
83 start = ","
Christophe Favergeon37b86222019-07-17 11:49:00 +020084
85 for field in params:
86 sql += " %s\n %s INTEGER" % (start,field)
87 start = ","
88
89 for field in common:
90 if field in MKSTRFIELD:
91 sql += "%s\n %s TEXT" % (start,field)
92 if field in MKINTFIELD:
93 sql += "%s\n %s INTEGER" % (start,field)
94 if field in MKKEYFIELD:
95 sql += "%s\n %s INTEGER" % (start,MKKEYFIELDID[field])
96 if field in MKDATEFIELD:
97 sql += "%s\n %s TEXT" % (start,field)
98 if field in MKBOOLFIELD:
99 sql += "%s\n %s INTEGER" % (start,field)
100 start = ","
101 # Create foreign keys
102 sql += "%sFOREIGN KEY(typeid) REFERENCES TYPE(typeid)," % start
103 sql += "FOREIGN KEY(categoryid) REFERENCES CATEGORY(categoryid),"
104 sql += "FOREIGN KEY(platformid) REFERENCES PLATFORM(platformid),"
105 sql += "FOREIGN KEY(coreid) REFERENCES CORE(coreid),"
106 sql += "FOREIGN KEY(compilerid) REFERENCES COMPILER(compilerid)"
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200107 sql += "FOREIGN KEY(runid) REFERENCES RUN(runid)"
Christophe Favergeon37b86222019-07-17 11:49:00 +0200108 sql += " )"
Christophe Favergeon37b86222019-07-17 11:49:00 +0200109 conn.execute(sql)
110
111# Find the key or add it in a table
112def findInTable(conn,table,keystr,strv,key):
113 #print(sql)
114 r = conn.execute("select %s from %s where %s=?" % (key,table,keystr),(strv,))
115 result=r.fetchone()
116 if result != None:
117 return(result[0])
118 else:
119 conn.execute("INSERT INTO %s(%s) VALUES(?)" % (table,keystr),(strv,))
120 conn.commit()
121 r = conn.execute("select %s from %s where %s=?" % (key,table,keystr),(strv,))
122 result=r.fetchone()
123 if result != None:
124 #print(result)
125 return(result[0])
126 else:
127 return(None)
128
129def findInCompilerTable(conn,kind,version):
130 #print(sql)
131 r = conn.execute("select compilerid from COMPILER where compilerkindid=? AND version=?" , (kind,version))
132 result=r.fetchone()
133 if result != None:
134 return(result[0])
135 else:
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200136 fullDate = datetime.datetime.now()
137 conn.execute("INSERT INTO COMPILER(compilerkindid,version,date) VALUES(?,?,?)" ,(kind,version,fullDate))
Christophe Favergeon37b86222019-07-17 11:49:00 +0200138 conn.commit()
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200139 r = conn.execute("select compilerid from COMPILER where compilerkindid=? AND version=? AND date=?" , (kind,version,fullDate))
Christophe Favergeon37b86222019-07-17 11:49:00 +0200140 result=r.fetchone()
141 if result != None:
142 #print(result)
143 return(result[0])
144 else:
145 return(None)
146
147
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200148def addRows(conn,elem,tableName,full,runid=0):
Christophe Favergeon37b86222019-07-17 11:49:00 +0200149 # List of columns we have in DB which is
150 # different from the columns in the table
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200151 compilerid = 0
152 platformid = 0
153 coreid = 0
Christophe Favergeon37b86222019-07-17 11:49:00 +0200154 keep = getColumns(elem,full)
155 cols = list(full.columns)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200156 params = list(elem.params.full)
Christophe Favergeon37b86222019-07-17 11:49:00 +0200157 common = diff(["TYPE"] + cols , ['OLDID'] + params)
Christophe Favergeon058b63b2019-07-25 10:40:32 +0200158 colNameList = []
159 for c in params + keep:
160 if c in MKKEYFIELD:
161 colNameList.append(MKKEYFIELDID[c])
162 else:
163 colNameList.append(c)
164 colNames = "".join(joinit(colNameList,","))
165 #print(colNameList)
166 #print(colNames)
Christophe Favergeon37b86222019-07-17 11:49:00 +0200167 #print(full)
168 for index, row in full.iterrows():
Christophe Favergeon058b63b2019-07-25 10:40:32 +0200169 sql = "INSERT INTO %s(%s) VALUES(" % (tableName,colNames)
Christophe Favergeon37b86222019-07-17 11:49:00 +0200170 keys = {}
171
172 # Get data from columns
173 for field in common:
174 if field in VALSTRFIELD:
175 keys[field]=row[field]
176 if field == "NAME":
177 name = row[field]
178 if re.match(r'^.*_f64',name):
179 keys["TYPE"] = "f64"
180 if re.match(r'^.*_f32',name):
181 keys["TYPE"] = "f32"
182 if re.match(r'^.*_f16',name):
183 keys["TYPE"] = "f16"
184 if re.match(r'^.*_q31',name):
185 keys["TYPE"] = "q31"
186 if re.match(r'^.*_q15',name):
187 keys["TYPE"] = "q15"
188 if re.match(r'^.*_q7',name):
189 keys["TYPE"] = "q7"
190
191 if re.match(r'^.*_s8',name):
192 keys["TYPE"] = "s8"
193 if re.match(r'^.*_u8',name):
194 keys["TYPE"] = "u8"
195 if re.match(r'^.*_s16',name):
196 keys["TYPE"] = "s16"
197 if re.match(r'^.*_u16',name):
198 keys["TYPE"] = "u16"
199 if re.match(r'^.*_s32',name):
200 keys["TYPE"] = "s32"
201 if re.match(r'^.*_u32',name):
202 keys["TYPE"] = "u32"
203 if re.match(r'^.*_s64',name):
204 keys["TYPE"] = "s64"
205 if re.match(r'^.*_u64',name):
206 keys["TYPE"] = "u64"
207
208 if field in VALINTFIELD:
209 keys[field]=row[field]
210 if field in VALDATEFIELD:
211 keys[field]=row[field]
212 if field in VALBOOLFIELD:
213 keys[field]=row[field]
214
215
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200216 keys['RUN']=runid
Christophe Favergeon37b86222019-07-17 11:49:00 +0200217 # Get foreign keys and create missing data
218 for field in common:
219 if field in VALKEYFIELD:
220 if field == "CATEGORY":
Christophe Favergeond6556452020-05-12 07:23:54 +0200221 # Remove type extension to get category name so that
222 # all types are maped to same category which will
223 # help for post processing.
224 testField=re.sub(r'^(.*)[:]([^:]+)(F16|F32|F64|Q31|Q15|Q7)$',r'\1',row[field])
225 val = findInTable(conn,"CATEGORY","category",testField,"categoryid")
Christophe Favergeon37b86222019-07-17 11:49:00 +0200226 keys[field]=val
227 if field == "CORE":
228 val = findInTable(conn,"CORE","coredef",row[field],"coreid")
229 keys[field]=val
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200230 coreid = val
Christophe Favergeon37b86222019-07-17 11:49:00 +0200231 if field == "PLATFORM":
232 val = findInTable(conn,"PLATFORM","platform",row[field],"platformid")
233 keys[field]=val
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200234 platformid = val
Christophe Favergeon37b86222019-07-17 11:49:00 +0200235 if field == "TYPE":
236 val = findInTable(conn,"TYPE","type",keys["TYPE"],"typeid")
237 keys[field]=val
238 if field == "COMPILER":
239 compilerkind = findInTable(conn,"COMPILERKIND","compiler",row[field],"compilerkindid")
240 compiler = findInCompilerTable(conn,compilerkind,keys["VERSION"])
241 keys[field]=compiler
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200242 compilerid = compiler
Christophe Favergeon37b86222019-07-17 11:49:00 +0200243
244 # Generate sql command
245 start = ""
246 for field in params:
247 sql += " %s\n %d" % (start,row[field])
248 start = ","
249
250 for field in keep:
251 if field in MKSTRFIELD or field in MKDATEFIELD:
252 sql += " %s\n \"%s\"" % (start,keys[field])
253 elif field in keep:
254 sql += " %s\n %d" % (start,keys[field])
255 start = ","
256
257 sql += " )"
258 #print(sql)
259 conn.execute(sql)
260 conn.commit()
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200261 return({'compilerid':compilerid,'platformid':platformid,'coreid':coreid})
262
263def addConfig(conn,config,fullDate):
264 conn.execute("INSERT INTO CONFIG(compilerid,platformid,coreid,date) VALUES(?,?,?,?)" ,(config['compilerid'],config['platformid'],config['coreid'],fullDate))
265 conn.commit()
Christophe Favergeon37b86222019-07-17 11:49:00 +0200266
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200267def getGroup(a):
268 return(re.sub(r'^(.+)(F64|F32|F16|Q31|Q15|Q7|U32|U16|U8|S32|S16|S8)$',r'\1',a))
269
270def addOneBenchmark(elem,fullPath,db,group,runid):
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100271 if os.path.isfile(fullPath):
272 full=pd.read_csv(fullPath,dtype={'OLDID': str} ,keep_default_na = False)
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200273 fullDate = datetime.datetime.now()
274 full['DATE'] = fullDate
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100275 if group:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200276 tableName = getGroup(group)
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100277 else:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200278 tableName = getGroup(elem.data["class"])
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100279 conn = sqlite3.connect(db)
Christophe Favergeon512b1482020-02-07 11:25:11 +0100280 createTableIfMissing(conn,elem,tableName,full)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200281 config = addRows(conn,elem,tableName,full,runid)
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200282 addConfig(conn,config,fullDate)
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100283 conn.close()
Christophe Favergeon37b86222019-07-17 11:49:00 +0200284
285
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200286def addToDB(benchmark,dbpath,elem,group,runid):
Christophe Favergeon37b86222019-07-17 11:49:00 +0200287 if not elem.data["deprecated"]:
288 if elem.params:
289 benchPath = os.path.join(benchmark,elem.fullPath(),"fullBenchmark.csv")
290 print("Processing %s" % benchPath)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200291 addOneBenchmark(elem,benchPath,dbpath,group,runid)
Christophe Favergeon37b86222019-07-17 11:49:00 +0200292
293 for c in elem.children:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200294 addToDB(benchmark,dbpath,c,group,runid)
Christophe Favergeon37b86222019-07-17 11:49:00 +0200295
296
297
298parser = argparse.ArgumentParser(description='Generate summary benchmarks')
299
Christophe Favergeon512b1482020-02-07 11:25:11 +0100300parser.add_argument('-f', nargs='?',type = str, default="Output.pickle", help="File path")
Christophe Favergeon37b86222019-07-17 11:49:00 +0200301parser.add_argument('-b', nargs='?',type = str, default="FullBenchmark", help="Full Benchmark dir path")
Christophe Favergeon97ce6fd2019-07-29 07:44:23 +0200302#parser.add_argument('-e', action='store_true', help="Embedded test")
Christophe Favergeon37b86222019-07-17 11:49:00 +0200303parser.add_argument('-o', nargs='?',type = str, default="bench.db", help="Benchmark database")
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200304parser.add_argument('-r', nargs='?',type = int, default=0, help="Run ID")
Christophe Favergeon37b86222019-07-17 11:49:00 +0200305
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 Favergeon37b86222019-07-17 11:49:00 +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 Favergeon37b86222019-07-17 11:49:00 +0200315 d.deprecate(root,args.others)
316 if args.others:
317 group=args.others[0]
318 else:
319 group=None
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200320 addToDB(args.b,args.o,root,group,args.r)
Christophe Favergeon37b86222019-07-17 11:49:00 +0200321
322else:
323 parser.print_help()