blob: 5b2d117e55f99945dcdb033559bf789fc9bcffe0 [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']
25MKKEYFIELD=['CATEGORY', 'PLATFORM', 'CORE', 'COMPILER','TYPE']
26MKKEYFIELDID={'CATEGORY':'categoryid',
27 'PLATFORM':'platformid',
28 'CORE':'coreid',
29 'COMPILER':'compilerid',
30 'TYPE':'typeid'}
31
32# For table value extraction
33VALSTRFIELD=['NAME','VERSION']
Christophe Favergeon74a31ba2019-09-09 09:14:18 +010034VALBOOLFIELD=['HARDFP', 'FASTMATH', 'NEON', 'HELIUM','UNROLL', 'ROUNDING','OPTIMIZED']
Christophe Favergeon37b86222019-07-17 11:49:00 +020035VALINTFIELD=['ID', 'CYCLES']
36VALDATEFIELD=['DATE']
37VALKEYFIELD=['CATEGORY', 'PLATFORM', 'CORE', 'COMPILER','TYPE']
38
39def joinit(iterable, delimiter):
40 it = iter(iterable)
41 yield next(it)
42 for x in it:
43 yield delimiter
44 yield x
45
46def tableExists(c,tableName):
47 req=(tableName,)
48 r=c.execute("SELECT name FROM sqlite_master WHERE type='table' AND name=?",req)
49 return(r.fetchone() != None)
50
51def diff(first, second):
52 second = set(second)
53 return [item for item in first if item not in second]
54
55def getColumns(elem,full):
56 colsToKeep=[]
57 cols = list(full.columns)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020058 params = list(elem.params.full)
Christophe Favergeon37b86222019-07-17 11:49:00 +020059 common = diff(cols + ["TYPE"] , ['OLDID'] + params)
60
61 for field in common:
62 if field in MKSTRFIELD:
63 colsToKeep.append(field)
64 if field in MKINTFIELD:
65 colsToKeep.append(field)
66 if field in MKKEYFIELD:
67 colsToKeep.append(field)
68 if field in MKDATEFIELD:
69 colsToKeep.append(field)
70 if field in MKBOOLFIELD:
71 colsToKeep.append(field)
72 return(colsToKeep)
73
74def createTableIfMissing(conn,elem,tableName,full):
75 if not tableExists(conn,tableName):
76 sql = "CREATE TABLE %s (" % tableName
77 cols = list(full.columns)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +020078 params = list(elem.params.full)
79 common = diff(cols + ["TYPE"] , ['OLDID'] + params)
Christophe Favergeon058b63b2019-07-25 10:40:32 +020080
81 sql += "%sid INTEGER PRIMARY KEY" % (tableName)
82 start = ","
Christophe Favergeon37b86222019-07-17 11:49:00 +020083
84 for field in params:
85 sql += " %s\n %s INTEGER" % (start,field)
86 start = ","
87
88 for field in common:
89 if field in MKSTRFIELD:
90 sql += "%s\n %s TEXT" % (start,field)
91 if field in MKINTFIELD:
92 sql += "%s\n %s INTEGER" % (start,field)
93 if field in MKKEYFIELD:
94 sql += "%s\n %s INTEGER" % (start,MKKEYFIELDID[field])
95 if field in MKDATEFIELD:
96 sql += "%s\n %s TEXT" % (start,field)
97 if field in MKBOOLFIELD:
98 sql += "%s\n %s INTEGER" % (start,field)
99 start = ","
100 # Create foreign keys
101 sql += "%sFOREIGN KEY(typeid) REFERENCES TYPE(typeid)," % start
102 sql += "FOREIGN KEY(categoryid) REFERENCES CATEGORY(categoryid),"
103 sql += "FOREIGN KEY(platformid) REFERENCES PLATFORM(platformid),"
104 sql += "FOREIGN KEY(coreid) REFERENCES CORE(coreid),"
105 sql += "FOREIGN KEY(compilerid) REFERENCES COMPILER(compilerid)"
106 sql += " )"
Christophe Favergeon37b86222019-07-17 11:49:00 +0200107 conn.execute(sql)
108
109# Find the key or add it in a table
110def findInTable(conn,table,keystr,strv,key):
111 #print(sql)
112 r = conn.execute("select %s from %s where %s=?" % (key,table,keystr),(strv,))
113 result=r.fetchone()
114 if result != None:
115 return(result[0])
116 else:
117 conn.execute("INSERT INTO %s(%s) VALUES(?)" % (table,keystr),(strv,))
118 conn.commit()
119 r = conn.execute("select %s from %s where %s=?" % (key,table,keystr),(strv,))
120 result=r.fetchone()
121 if result != None:
122 #print(result)
123 return(result[0])
124 else:
125 return(None)
126
127def findInCompilerTable(conn,kind,version):
128 #print(sql)
129 r = conn.execute("select compilerid from COMPILER where compilerkindid=? AND version=?" , (kind,version))
130 result=r.fetchone()
131 if result != None:
132 return(result[0])
133 else:
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200134 fullDate = datetime.datetime.now()
135 conn.execute("INSERT INTO COMPILER(compilerkindid,version,date) VALUES(?,?,?)" ,(kind,version,fullDate))
Christophe Favergeon37b86222019-07-17 11:49:00 +0200136 conn.commit()
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200137 r = conn.execute("select compilerid from COMPILER where compilerkindid=? AND version=? AND date=?" , (kind,version,fullDate))
Christophe Favergeon37b86222019-07-17 11:49:00 +0200138 result=r.fetchone()
139 if result != None:
140 #print(result)
141 return(result[0])
142 else:
143 return(None)
144
145
146def addRows(conn,elem,tableName,full):
147 # List of columns we have in DB which is
148 # different from the columns in the table
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200149 compilerid = 0
150 platformid = 0
151 coreid = 0
Christophe Favergeon37b86222019-07-17 11:49:00 +0200152 keep = getColumns(elem,full)
153 cols = list(full.columns)
Christophe Favergeon4a8d9dc2019-08-14 08:55:46 +0200154 params = list(elem.params.full)
Christophe Favergeon37b86222019-07-17 11:49:00 +0200155 common = diff(["TYPE"] + cols , ['OLDID'] + params)
Christophe Favergeon058b63b2019-07-25 10:40:32 +0200156 colNameList = []
157 for c in params + keep:
158 if c in MKKEYFIELD:
159 colNameList.append(MKKEYFIELDID[c])
160 else:
161 colNameList.append(c)
162 colNames = "".join(joinit(colNameList,","))
163 #print(colNameList)
164 #print(colNames)
Christophe Favergeon37b86222019-07-17 11:49:00 +0200165 #print(full)
166 for index, row in full.iterrows():
Christophe Favergeon058b63b2019-07-25 10:40:32 +0200167 sql = "INSERT INTO %s(%s) VALUES(" % (tableName,colNames)
Christophe Favergeon37b86222019-07-17 11:49:00 +0200168 keys = {}
169
170 # Get data from columns
171 for field in common:
172 if field in VALSTRFIELD:
173 keys[field]=row[field]
174 if field == "NAME":
175 name = row[field]
176 if re.match(r'^.*_f64',name):
177 keys["TYPE"] = "f64"
178 if re.match(r'^.*_f32',name):
179 keys["TYPE"] = "f32"
180 if re.match(r'^.*_f16',name):
181 keys["TYPE"] = "f16"
182 if re.match(r'^.*_q31',name):
183 keys["TYPE"] = "q31"
184 if re.match(r'^.*_q15',name):
185 keys["TYPE"] = "q15"
186 if re.match(r'^.*_q7',name):
187 keys["TYPE"] = "q7"
188
189 if re.match(r'^.*_s8',name):
190 keys["TYPE"] = "s8"
191 if re.match(r'^.*_u8',name):
192 keys["TYPE"] = "u8"
193 if re.match(r'^.*_s16',name):
194 keys["TYPE"] = "s16"
195 if re.match(r'^.*_u16',name):
196 keys["TYPE"] = "u16"
197 if re.match(r'^.*_s32',name):
198 keys["TYPE"] = "s32"
199 if re.match(r'^.*_u32',name):
200 keys["TYPE"] = "u32"
201 if re.match(r'^.*_s64',name):
202 keys["TYPE"] = "s64"
203 if re.match(r'^.*_u64',name):
204 keys["TYPE"] = "u64"
205
206 if field in VALINTFIELD:
207 keys[field]=row[field]
208 if field in VALDATEFIELD:
209 keys[field]=row[field]
210 if field in VALBOOLFIELD:
211 keys[field]=row[field]
212
213
214 # Get foreign keys and create missing data
215 for field in common:
216 if field in VALKEYFIELD:
217 if field == "CATEGORY":
218 val = findInTable(conn,"CATEGORY","category",row[field],"categoryid")
219 keys[field]=val
220 if field == "CORE":
221 val = findInTable(conn,"CORE","coredef",row[field],"coreid")
222 keys[field]=val
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200223 coreid = val
Christophe Favergeon37b86222019-07-17 11:49:00 +0200224 if field == "PLATFORM":
225 val = findInTable(conn,"PLATFORM","platform",row[field],"platformid")
226 keys[field]=val
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200227 platformid = val
Christophe Favergeon37b86222019-07-17 11:49:00 +0200228 if field == "TYPE":
229 val = findInTable(conn,"TYPE","type",keys["TYPE"],"typeid")
230 keys[field]=val
231 if field == "COMPILER":
232 compilerkind = findInTable(conn,"COMPILERKIND","compiler",row[field],"compilerkindid")
233 compiler = findInCompilerTable(conn,compilerkind,keys["VERSION"])
234 keys[field]=compiler
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200235 compilerid = compiler
Christophe Favergeon37b86222019-07-17 11:49:00 +0200236
237 # Generate sql command
238 start = ""
239 for field in params:
240 sql += " %s\n %d" % (start,row[field])
241 start = ","
242
243 for field in keep:
244 if field in MKSTRFIELD or field in MKDATEFIELD:
245 sql += " %s\n \"%s\"" % (start,keys[field])
246 elif field in keep:
247 sql += " %s\n %d" % (start,keys[field])
248 start = ","
249
250 sql += " )"
251 #print(sql)
252 conn.execute(sql)
253 conn.commit()
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200254 return({'compilerid':compilerid,'platformid':platformid,'coreid':coreid})
255
256def addConfig(conn,config,fullDate):
257 conn.execute("INSERT INTO CONFIG(compilerid,platformid,coreid,date) VALUES(?,?,?,?)" ,(config['compilerid'],config['platformid'],config['coreid'],fullDate))
258 conn.commit()
Christophe Favergeon37b86222019-07-17 11:49:00 +0200259
260def addOneBenchmark(elem,fullPath,db,group):
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100261 if os.path.isfile(fullPath):
262 full=pd.read_csv(fullPath,dtype={'OLDID': str} ,keep_default_na = False)
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200263 fullDate = datetime.datetime.now()
264 full['DATE'] = fullDate
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100265 if group:
266 tableName = group
267 else:
268 tableName = elem.data["class"]
269 conn = sqlite3.connect(db)
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200270 #createTableIfMissing(conn,elem,tableName,full)
271 config = addRows(conn,elem,tableName,full)
272 addConfig(conn,config,fullDate)
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100273 conn.close()
Christophe Favergeon37b86222019-07-17 11:49:00 +0200274
275
276def addToDB(benchmark,dbpath,elem,group):
277 if not elem.data["deprecated"]:
278 if elem.params:
279 benchPath = os.path.join(benchmark,elem.fullPath(),"fullBenchmark.csv")
280 print("Processing %s" % benchPath)
281 addOneBenchmark(elem,benchPath,dbpath,group)
282
283 for c in elem.children:
284 addToDB(benchmark,dbpath,c,group)
285
286
287
288parser = argparse.ArgumentParser(description='Generate summary benchmarks')
289
Christophe Favergeon6f8eee92019-10-09 12:21:27 +0100290parser.add_argument('-f', nargs='?',type = str, default="Output.pickle", help="Test description file path")
Christophe Favergeon37b86222019-07-17 11:49:00 +0200291parser.add_argument('-b', nargs='?',type = str, default="FullBenchmark", help="Full Benchmark dir path")
Christophe Favergeon97ce6fd2019-07-29 07:44:23 +0200292#parser.add_argument('-e', action='store_true', help="Embedded test")
Christophe Favergeon37b86222019-07-17 11:49:00 +0200293parser.add_argument('-o', nargs='?',type = str, default="bench.db", help="Benchmark database")
294
295parser.add_argument('others', nargs=argparse.REMAINDER)
296
297args = parser.parse_args()
298
299if args.f is not None:
Christophe Favergeon6f8eee92019-10-09 12:21:27 +0100300 #p = parse.Parser()
Christophe Favergeon37b86222019-07-17 11:49:00 +0200301 # Parse the test description file
Christophe Favergeon6f8eee92019-10-09 12:21:27 +0100302 #root = p.parse(args.f)
303 root=parse.loadRoot(args.f)
Christophe Favergeon37b86222019-07-17 11:49:00 +0200304 d.deprecate(root,args.others)
305 if args.others:
306 group=args.others[0]
307 else:
308 group=None
309 addToDB(args.b,args.o,root,group)
310
311else:
312 parser.print_help()