Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 1 | # Process the test results |
| 2 | # Test status (like passed, or failed with error code) |
| 3 | |
| 4 | import argparse |
| 5 | import re |
| 6 | import TestScripts.NewParser as parse |
| 7 | import TestScripts.CodeGen |
| 8 | from collections import deque |
| 9 | import os.path |
| 10 | import numpy as np |
| 11 | import pandas as pd |
| 12 | import statsmodels.api as sm |
| 13 | import statsmodels.formula.api as smf |
| 14 | import csv |
| 15 | import TestScripts.Deprecate as d |
| 16 | import sqlite3 |
| 17 | import datetime, time |
| 18 | import re |
| 19 | |
| 20 | # For table creation |
| 21 | MKSTRFIELD=['NAME','Regression'] |
Christophe Favergeon | 74a31ba | 2019-09-09 09:14:18 +0100 | [diff] [blame] | 22 | MKBOOLFIELD=['HARDFP', 'FASTMATH', 'NEON', 'HELIUM','UNROLL', 'ROUNDING','OPTIMIZED'] |
Christophe Favergeon | 5cacf9d | 2019-08-14 10:41:17 +0200 | [diff] [blame] | 23 | MKINTFIELD=['ID','MAX'] |
| 24 | MKREALFIELD=['MAXREGCOEF'] |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 25 | MKDATEFIELD=['DATE'] |
| 26 | MKKEYFIELD=['CATEGORY', 'PLATFORM', 'CORE', 'COMPILER','TYPE'] |
| 27 | MKKEYFIELDID={'CATEGORY':'categoryid', |
| 28 | 'PLATFORM':'platformid', |
| 29 | 'CORE':'coreid', |
| 30 | 'COMPILER':'compilerid', |
| 31 | 'TYPE':'typeid'} |
| 32 | |
| 33 | # For table value extraction |
| 34 | VALSTRFIELD=['NAME','VERSION','Regression'] |
Christophe Favergeon | 74a31ba | 2019-09-09 09:14:18 +0100 | [diff] [blame] | 35 | VALBOOLFIELD=['HARDFP', 'FASTMATH', 'NEON', 'HELIUM','UNROLL', 'ROUNDING','OPTIMIZED'] |
Christophe Favergeon | 5cacf9d | 2019-08-14 10:41:17 +0200 | [diff] [blame] | 36 | VALINTFIELD=['ID', 'MAX'] |
| 37 | VALREALFIELD=['MAXREGCOEF'] |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 38 | VALDATEFIELD=['DATE'] |
| 39 | VALKEYFIELD=['CATEGORY', 'PLATFORM', 'CORE', 'COMPILER','TYPE'] |
| 40 | |
| 41 | def joinit(iterable, delimiter): |
| 42 | it = iter(iterable) |
| 43 | yield next(it) |
| 44 | for x in it: |
| 45 | yield delimiter |
| 46 | yield x |
| 47 | |
| 48 | def 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 | |
| 53 | def diff(first, second): |
| 54 | second = set(second) |
| 55 | return [item for item in first if item not in second] |
| 56 | |
| 57 | def 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 Favergeon | 5cacf9d | 2019-08-14 10:41:17 +0200 | [diff] [blame] | 68 | if field in MKREALFIELD: |
| 69 | colsToKeep.append(field) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 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 | |
| 78 | def 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 Favergeon | 5cacf9d | 2019-08-14 10:41:17 +0200 | [diff] [blame] | 97 | if field in MKREALFIELD: |
| 98 | sql += "%s\n %s REAL" % (start,field) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 99 | 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 |
| 116 | def 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 | |
| 133 | def 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 Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 140 | fullDate = datetime.datetime.now() |
| 141 | conn.execute("INSERT INTO COMPILER(compilerkindid,version,date) VALUES(?,?,?)" ,(kind,version,fullDate)) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 142 | conn.commit() |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 143 | r = conn.execute("select compilerid from COMPILER where compilerkindid=? AND version=? AND date=?" , (kind,version,fullDate)) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 144 | result=r.fetchone() |
| 145 | if result != None: |
| 146 | #print(result) |
| 147 | return(result[0]) |
| 148 | else: |
| 149 | return(None) |
| 150 | |
| 151 | |
| 152 | def addRows(conn,elem,tableName,full): |
| 153 | # List of columns we have in DB which is |
| 154 | # different from the columns in the table |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 155 | compilerid = 0 |
| 156 | platformid = 0 |
| 157 | coreid = 0 |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 158 | 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 Favergeon | 5cacf9d | 2019-08-14 10:41:17 +0200 | [diff] [blame] | 214 | if field in VALREALFIELD: |
| 215 | keys[field]=row[field] |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 216 | 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": |
| 226 | val = findInTable(conn,"CATEGORY","category",row[field],"categoryid") |
| 227 | keys[field]=val |
| 228 | if field == "CORE": |
| 229 | val = findInTable(conn,"CORE","coredef",row[field],"coreid") |
| 230 | keys[field]=val |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 231 | coreid = val |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 232 | if field == "PLATFORM": |
| 233 | val = findInTable(conn,"PLATFORM","platform",row[field],"platformid") |
| 234 | keys[field]=val |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 235 | platformid = val |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 236 | if field == "TYPE": |
| 237 | val = findInTable(conn,"TYPE","type",keys["TYPE"],"typeid") |
| 238 | keys[field]=val |
| 239 | if field == "COMPILER": |
| 240 | compilerkind = findInTable(conn,"COMPILERKIND","compiler",row[field],"compilerkindid") |
| 241 | compiler = findInCompilerTable(conn,compilerkind,keys["VERSION"]) |
| 242 | keys[field]=compiler |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 243 | compilerid = compiler |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 244 | |
| 245 | # Generate sql command |
| 246 | start = "" |
| 247 | for field in params: |
| 248 | sql += " %s\n %d" % (start,row[field]) |
| 249 | start = "," |
| 250 | |
| 251 | for field in keep: |
| 252 | if field in MKSTRFIELD or field in MKDATEFIELD: |
| 253 | sql += " %s\n \"%s\"" % (start,keys[field]) |
| 254 | elif field in keep: |
Christophe Favergeon | 5cacf9d | 2019-08-14 10:41:17 +0200 | [diff] [blame] | 255 | if field in VALREALFIELD: |
| 256 | sql += " %s\n %f" % (start,keys[field]) |
| 257 | else: |
| 258 | sql += " %s\n %d" % (start,keys[field]) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 259 | start = "," |
| 260 | |
| 261 | sql += " )" |
| 262 | #print(sql) |
| 263 | conn.execute(sql) |
| 264 | conn.commit() |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 265 | return({'compilerid':compilerid,'platformid':platformid,'coreid':coreid}) |
| 266 | |
| 267 | def addConfig(conn,config,fullDate): |
| 268 | conn.execute("INSERT INTO CONFIG(compilerid,platformid,coreid,date) VALUES(?,?,?,?)" ,(config['compilerid'],config['platformid'],config['coreid'],fullDate)) |
| 269 | conn.commit() |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 270 | |
| 271 | def addOneBenchmark(elem,fullPath,db,group): |
Christophe Favergeon | 74a31ba | 2019-09-09 09:14:18 +0100 | [diff] [blame] | 272 | if os.path.isfile(fullPath): |
| 273 | full=pd.read_csv(fullPath,dtype={'OLDID': str} ,keep_default_na = False) |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 274 | fullDate = datetime.datetime.now() |
| 275 | full['DATE'] = fullDate |
Christophe Favergeon | 74a31ba | 2019-09-09 09:14:18 +0100 | [diff] [blame] | 276 | if group: |
| 277 | tableName = group |
| 278 | else: |
| 279 | tableName = elem.data["class"] |
| 280 | conn = sqlite3.connect(db) |
| 281 | createTableIfMissing(conn,elem,tableName,full) |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 282 | config = addRows(conn,elem,tableName,full) |
| 283 | addConfig(conn,config,fullDate) |
Christophe Favergeon | 74a31ba | 2019-09-09 09:14:18 +0100 | [diff] [blame] | 284 | conn.close() |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 285 | |
| 286 | |
| 287 | def addToDB(benchmark,dbpath,elem,group): |
| 288 | if not elem.data["deprecated"]: |
| 289 | if elem.params: |
| 290 | benchPath = os.path.join(benchmark,elem.fullPath(),"regression.csv") |
| 291 | print("Processing %s" % benchPath) |
| 292 | addOneBenchmark(elem,benchPath,dbpath,group) |
| 293 | |
| 294 | for c in elem.children: |
| 295 | addToDB(benchmark,dbpath,c,group) |
| 296 | |
| 297 | |
| 298 | |
| 299 | parser = argparse.ArgumentParser(description='Generate summary benchmarks') |
| 300 | |
Christophe Favergeon | 6f8eee9 | 2019-10-09 12:21:27 +0100 | [diff] [blame] | 301 | parser.add_argument('-f', nargs='?',type = str, default="Output.pickle", help="Test description file path") |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 302 | parser.add_argument('-b', nargs='?',type = str, default="FullBenchmark", help="Full Benchmark dir path") |
| 303 | #parser.add_argument('-e', action='store_true', help="Embedded test") |
| 304 | parser.add_argument('-o', nargs='?',type = str, default="reg.db", help="Regression benchmark database") |
| 305 | |
| 306 | parser.add_argument('others', nargs=argparse.REMAINDER) |
| 307 | |
| 308 | args = parser.parse_args() |
| 309 | |
| 310 | if args.f is not None: |
Christophe Favergeon | 6f8eee9 | 2019-10-09 12:21:27 +0100 | [diff] [blame] | 311 | #p = parse.Parser() |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 312 | # Parse the test description file |
Christophe Favergeon | 6f8eee9 | 2019-10-09 12:21:27 +0100 | [diff] [blame] | 313 | #root = p.parse(args.f) |
| 314 | root=parse.loadRoot(args.f) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 315 | d.deprecate(root,args.others) |
| 316 | if args.others: |
| 317 | group=args.others[0] |
| 318 | else: |
| 319 | group=None |
| 320 | addToDB(args.b,args.o,root,group) |
| 321 | |
| 322 | else: |
| 323 | parser.print_help() |