blob: 4d7b668802af84933450351e570bfc15d8f812e3 [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":
Christophe Favergeond6556452020-05-12 07:23:54 +0200218 # Remove type extension to get category name so that
219 # all types are maped to same category which will
220 # help for post processing.
221 testField=re.sub(r'^(.*)[:]([^:]+)(F16|F32|F64|Q31|Q15|Q7)$',r'\1',row[field])
222 val = findInTable(conn,"CATEGORY","category",testField,"categoryid")
Christophe Favergeon37b86222019-07-17 11:49:00 +0200223 keys[field]=val
224 if field == "CORE":
225 val = findInTable(conn,"CORE","coredef",row[field],"coreid")
226 keys[field]=val
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200227 coreid = val
Christophe Favergeon37b86222019-07-17 11:49:00 +0200228 if field == "PLATFORM":
229 val = findInTable(conn,"PLATFORM","platform",row[field],"platformid")
230 keys[field]=val
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200231 platformid = val
Christophe Favergeon37b86222019-07-17 11:49:00 +0200232 if field == "TYPE":
233 val = findInTable(conn,"TYPE","type",keys["TYPE"],"typeid")
234 keys[field]=val
235 if field == "COMPILER":
236 compilerkind = findInTable(conn,"COMPILERKIND","compiler",row[field],"compilerkindid")
237 compiler = findInCompilerTable(conn,compilerkind,keys["VERSION"])
238 keys[field]=compiler
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200239 compilerid = compiler
Christophe Favergeon37b86222019-07-17 11:49:00 +0200240
241 # Generate sql command
242 start = ""
243 for field in params:
244 sql += " %s\n %d" % (start,row[field])
245 start = ","
246
247 for field in keep:
248 if field in MKSTRFIELD or field in MKDATEFIELD:
249 sql += " %s\n \"%s\"" % (start,keys[field])
250 elif field in keep:
251 sql += " %s\n %d" % (start,keys[field])
252 start = ","
253
254 sql += " )"
255 #print(sql)
256 conn.execute(sql)
257 conn.commit()
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200258 return({'compilerid':compilerid,'platformid':platformid,'coreid':coreid})
259
260def addConfig(conn,config,fullDate):
261 conn.execute("INSERT INTO CONFIG(compilerid,platformid,coreid,date) VALUES(?,?,?,?)" ,(config['compilerid'],config['platformid'],config['coreid'],fullDate))
262 conn.commit()
Christophe Favergeon37b86222019-07-17 11:49:00 +0200263
264def addOneBenchmark(elem,fullPath,db,group):
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100265 if os.path.isfile(fullPath):
266 full=pd.read_csv(fullPath,dtype={'OLDID': str} ,keep_default_na = False)
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200267 fullDate = datetime.datetime.now()
268 full['DATE'] = fullDate
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100269 if group:
270 tableName = group
271 else:
272 tableName = elem.data["class"]
273 conn = sqlite3.connect(db)
Christophe Favergeon512b1482020-02-07 11:25:11 +0100274 createTableIfMissing(conn,elem,tableName,full)
Christophe Favergeon256f2da2019-09-10 14:56:10 +0200275 config = addRows(conn,elem,tableName,full)
276 addConfig(conn,config,fullDate)
Christophe Favergeon74a31ba2019-09-09 09:14:18 +0100277 conn.close()
Christophe Favergeon37b86222019-07-17 11:49:00 +0200278
279
280def addToDB(benchmark,dbpath,elem,group):
281 if not elem.data["deprecated"]:
282 if elem.params:
283 benchPath = os.path.join(benchmark,elem.fullPath(),"fullBenchmark.csv")
284 print("Processing %s" % benchPath)
285 addOneBenchmark(elem,benchPath,dbpath,group)
286
287 for c in elem.children:
288 addToDB(benchmark,dbpath,c,group)
289
290
291
292parser = argparse.ArgumentParser(description='Generate summary benchmarks')
293
Christophe Favergeon512b1482020-02-07 11:25:11 +0100294parser.add_argument('-f', nargs='?',type = str, default="Output.pickle", help="File path")
Christophe Favergeon37b86222019-07-17 11:49:00 +0200295parser.add_argument('-b', nargs='?',type = str, default="FullBenchmark", help="Full Benchmark dir path")
Christophe Favergeon97ce6fd2019-07-29 07:44:23 +0200296#parser.add_argument('-e', action='store_true', help="Embedded test")
Christophe Favergeon37b86222019-07-17 11:49:00 +0200297parser.add_argument('-o', nargs='?',type = str, default="bench.db", help="Benchmark database")
298
299parser.add_argument('others', nargs=argparse.REMAINDER)
300
301args = parser.parse_args()
302
303if args.f is not None:
Christophe Favergeon6f8eee92019-10-09 12:21:27 +0100304 #p = parse.Parser()
Christophe Favergeon37b86222019-07-17 11:49:00 +0200305 # Parse the test description file
Christophe Favergeon6f8eee92019-10-09 12:21:27 +0100306 #root = p.parse(args.f)
307 root=parse.loadRoot(args.f)
Christophe Favergeon37b86222019-07-17 11:49:00 +0200308 d.deprecate(root,args.others)
309 if args.others:
310 group=args.others[0]
311 else:
312 group=None
313 addToDB(args.b,args.o,root,group)
314
315else:
316 parser.print_help()