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'] |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 26 | MKKEYFIELD=['CATEGORY', 'PLATFORM', 'CORE', 'COMPILER','TYPE','RUN'] |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 27 | MKKEYFIELDID={'CATEGORY':'categoryid', |
| 28 | 'PLATFORM':'platformid', |
| 29 | 'CORE':'coreid', |
| 30 | 'COMPILER':'compilerid', |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 31 | 'TYPE':'typeid', |
| 32 | 'RUN':'runid'} |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 33 | |
| 34 | # For table value extraction |
| 35 | VALSTRFIELD=['NAME','VERSION','Regression'] |
Christophe Favergeon | 74a31ba | 2019-09-09 09:14:18 +0100 | [diff] [blame] | 36 | VALBOOLFIELD=['HARDFP', 'FASTMATH', 'NEON', 'HELIUM','UNROLL', 'ROUNDING','OPTIMIZED'] |
Christophe Favergeon | 5cacf9d | 2019-08-14 10:41:17 +0200 | [diff] [blame] | 37 | VALINTFIELD=['ID', 'MAX'] |
| 38 | VALREALFIELD=['MAXREGCOEF'] |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 39 | VALDATEFIELD=['DATE'] |
| 40 | VALKEYFIELD=['CATEGORY', 'PLATFORM', 'CORE', 'COMPILER','TYPE'] |
| 41 | |
| 42 | def joinit(iterable, delimiter): |
| 43 | it = iter(iterable) |
| 44 | yield next(it) |
| 45 | for x in it: |
| 46 | yield delimiter |
| 47 | yield x |
| 48 | |
| 49 | def tableExists(c,tableName): |
| 50 | req=(tableName,) |
| 51 | r=c.execute("SELECT name FROM sqlite_master WHERE type='table' AND name=?",req) |
| 52 | return(r.fetchone() != None) |
| 53 | |
| 54 | def diff(first, second): |
| 55 | second = set(second) |
| 56 | return [item for item in first if item not in second] |
| 57 | |
| 58 | def getColumns(elem,full): |
| 59 | colsToKeep=[] |
| 60 | cols = list(full.columns) |
| 61 | params=diff(elem.params.full , elem.params.summary) |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 62 | common = diff(cols + ["TYPE","RUN"] , ['OLDID'] + params) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 63 | |
| 64 | for field in common: |
| 65 | if field in MKSTRFIELD: |
| 66 | colsToKeep.append(field) |
| 67 | if field in MKINTFIELD: |
| 68 | colsToKeep.append(field) |
Christophe Favergeon | 5cacf9d | 2019-08-14 10:41:17 +0200 | [diff] [blame] | 69 | if field in MKREALFIELD: |
| 70 | colsToKeep.append(field) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 71 | if field in MKKEYFIELD: |
| 72 | colsToKeep.append(field) |
| 73 | if field in MKDATEFIELD: |
| 74 | colsToKeep.append(field) |
| 75 | if field in MKBOOLFIELD: |
| 76 | colsToKeep.append(field) |
| 77 | return(colsToKeep) |
| 78 | |
| 79 | def createTableIfMissing(conn,elem,tableName,full): |
| 80 | if not tableExists(conn,tableName): |
| 81 | sql = "CREATE TABLE %s (" % tableName |
| 82 | cols = list(full.columns) |
| 83 | params=diff(elem.params.full , elem.params.summary) |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 84 | common = diff(cols + ["TYPE","RUN"] , ['OLDID'] + params) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 85 | |
| 86 | sql += "%sid INTEGER PRIMARY KEY" % (tableName) |
| 87 | start = "," |
| 88 | |
| 89 | for field in params: |
| 90 | sql += " %s\n %s INTEGER" % (start,field) |
| 91 | start = "," |
| 92 | |
| 93 | for field in common: |
| 94 | if field in MKSTRFIELD: |
| 95 | sql += "%s\n %s TEXT" % (start,field) |
| 96 | if field in MKINTFIELD: |
| 97 | sql += "%s\n %s INTEGER" % (start,field) |
Christophe Favergeon | 5cacf9d | 2019-08-14 10:41:17 +0200 | [diff] [blame] | 98 | if field in MKREALFIELD: |
| 99 | sql += "%s\n %s REAL" % (start,field) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 100 | if field in MKKEYFIELD: |
| 101 | sql += "%s\n %s INTEGER" % (start,MKKEYFIELDID[field]) |
| 102 | if field in MKDATEFIELD: |
| 103 | sql += "%s\n %s TEXT" % (start,field) |
| 104 | if field in MKBOOLFIELD: |
| 105 | sql += "%s\n %s INTEGER" % (start,field) |
| 106 | start = "," |
| 107 | # Create foreign keys |
| 108 | sql += "%sFOREIGN KEY(typeid) REFERENCES TYPE(typeid)," % start |
| 109 | sql += "FOREIGN KEY(categoryid) REFERENCES CATEGORY(categoryid)," |
| 110 | sql += "FOREIGN KEY(platformid) REFERENCES PLATFORM(platformid)," |
| 111 | sql += "FOREIGN KEY(coreid) REFERENCES CORE(coreid)," |
| 112 | sql += "FOREIGN KEY(compilerid) REFERENCES COMPILER(compilerid)" |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 113 | sql += "FOREIGN KEY(runid) REFERENCES RUN(runid)" |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 114 | sql += " )" |
| 115 | conn.execute(sql) |
| 116 | |
| 117 | # Find the key or add it in a table |
| 118 | def findInTable(conn,table,keystr,strv,key): |
| 119 | #print(sql) |
| 120 | r = conn.execute("select %s from %s where %s=?" % (key,table,keystr),(strv,)) |
| 121 | result=r.fetchone() |
| 122 | if result != None: |
| 123 | return(result[0]) |
| 124 | else: |
| 125 | conn.execute("INSERT INTO %s(%s) VALUES(?)" % (table,keystr),(strv,)) |
| 126 | conn.commit() |
| 127 | r = conn.execute("select %s from %s where %s=?" % (key,table,keystr),(strv,)) |
| 128 | result=r.fetchone() |
| 129 | if result != None: |
| 130 | #print(result) |
| 131 | return(result[0]) |
| 132 | else: |
| 133 | return(None) |
| 134 | |
| 135 | def findInCompilerTable(conn,kind,version): |
| 136 | #print(sql) |
| 137 | r = conn.execute("select compilerid from COMPILER where compilerkindid=? AND version=?" , (kind,version)) |
| 138 | result=r.fetchone() |
| 139 | if result != None: |
| 140 | return(result[0]) |
| 141 | else: |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 142 | fullDate = datetime.datetime.now() |
| 143 | conn.execute("INSERT INTO COMPILER(compilerkindid,version,date) VALUES(?,?,?)" ,(kind,version,fullDate)) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 144 | conn.commit() |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 145 | 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] | 146 | result=r.fetchone() |
| 147 | if result != None: |
| 148 | #print(result) |
| 149 | return(result[0]) |
| 150 | else: |
| 151 | return(None) |
| 152 | |
| 153 | |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 154 | def addRows(conn,elem,tableName,full,runid=0): |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 155 | # List of columns we have in DB which is |
| 156 | # different from the columns in the table |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 157 | compilerid = 0 |
| 158 | platformid = 0 |
| 159 | coreid = 0 |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 160 | keep = getColumns(elem,full) |
| 161 | cols = list(full.columns) |
| 162 | params=diff(elem.params.full , elem.params.summary) |
| 163 | common = diff(["TYPE"] + cols , ['OLDID'] + params) |
| 164 | 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) |
| 173 | #print(full) |
| 174 | for index, row in full.iterrows(): |
| 175 | sql = "INSERT INTO %s(%s) VALUES(" % (tableName,colNames) |
| 176 | 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] |
| 184 | if re.match(r'^.*_f64',name): |
| 185 | keys["TYPE"] = "f64" |
| 186 | if re.match(r'^.*_f32',name): |
| 187 | keys["TYPE"] = "f32" |
| 188 | if re.match(r'^.*_f16',name): |
| 189 | keys["TYPE"] = "f16" |
| 190 | if re.match(r'^.*_q31',name): |
| 191 | keys["TYPE"] = "q31" |
| 192 | if re.match(r'^.*_q15',name): |
| 193 | keys["TYPE"] = "q15" |
| 194 | if re.match(r'^.*_q7',name): |
| 195 | keys["TYPE"] = "q7" |
| 196 | |
| 197 | if re.match(r'^.*_s8',name): |
| 198 | keys["TYPE"] = "s8" |
| 199 | if re.match(r'^.*_u8',name): |
| 200 | keys["TYPE"] = "u8" |
| 201 | if re.match(r'^.*_s16',name): |
| 202 | keys["TYPE"] = "s16" |
| 203 | if re.match(r'^.*_u16',name): |
| 204 | keys["TYPE"] = "u16" |
| 205 | if re.match(r'^.*_s32',name): |
| 206 | keys["TYPE"] = "s32" |
| 207 | if re.match(r'^.*_u32',name): |
| 208 | keys["TYPE"] = "u32" |
| 209 | if re.match(r'^.*_s64',name): |
| 210 | keys["TYPE"] = "s64" |
| 211 | if re.match(r'^.*_u64',name): |
| 212 | keys["TYPE"] = "u64" |
| 213 | |
| 214 | if field in VALINTFIELD: |
| 215 | keys[field]=row[field] |
Christophe Favergeon | 5cacf9d | 2019-08-14 10:41:17 +0200 | [diff] [blame] | 216 | if field in VALREALFIELD: |
| 217 | keys[field]=row[field] |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 218 | if field in VALDATEFIELD: |
| 219 | keys[field]=row[field] |
| 220 | if field in VALBOOLFIELD: |
| 221 | keys[field]=row[field] |
| 222 | |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 223 | keys['RUN']=runid |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 224 | # Get foreign keys and create missing data |
| 225 | for field in common: |
| 226 | if field in VALKEYFIELD: |
| 227 | if field == "CATEGORY": |
Christophe Favergeon | d655645 | 2020-05-12 07:23:54 +0200 | [diff] [blame] | 228 | # Remove type extension to get category name so that |
| 229 | # all types are maped to same category which will |
| 230 | # help for post processing. |
| 231 | testField=re.sub(r'^(.*)[:]([^:]+)(F16|F32|F64|Q31|Q15|Q7)$',r'\1',row[field]) |
| 232 | val = findInTable(conn,"CATEGORY","category",testField,"categoryid") |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 233 | keys[field]=val |
| 234 | if field == "CORE": |
| 235 | val = findInTable(conn,"CORE","coredef",row[field],"coreid") |
| 236 | keys[field]=val |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 237 | coreid = val |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 238 | if field == "PLATFORM": |
| 239 | val = findInTable(conn,"PLATFORM","platform",row[field],"platformid") |
| 240 | keys[field]=val |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 241 | platformid = val |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 242 | if field == "TYPE": |
| 243 | val = findInTable(conn,"TYPE","type",keys["TYPE"],"typeid") |
| 244 | keys[field]=val |
| 245 | if field == "COMPILER": |
| 246 | compilerkind = findInTable(conn,"COMPILERKIND","compiler",row[field],"compilerkindid") |
| 247 | compiler = findInCompilerTable(conn,compilerkind,keys["VERSION"]) |
| 248 | keys[field]=compiler |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 249 | compilerid = compiler |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 250 | |
| 251 | # Generate sql command |
| 252 | start = "" |
| 253 | for field in params: |
| 254 | sql += " %s\n %d" % (start,row[field]) |
| 255 | start = "," |
| 256 | |
| 257 | for field in keep: |
| 258 | if field in MKSTRFIELD or field in MKDATEFIELD: |
| 259 | sql += " %s\n \"%s\"" % (start,keys[field]) |
| 260 | elif field in keep: |
Christophe Favergeon | 5cacf9d | 2019-08-14 10:41:17 +0200 | [diff] [blame] | 261 | if field in VALREALFIELD: |
| 262 | sql += " %s\n %f" % (start,keys[field]) |
| 263 | else: |
| 264 | sql += " %s\n %d" % (start,keys[field]) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 265 | start = "," |
| 266 | |
| 267 | sql += " )" |
| 268 | #print(sql) |
| 269 | conn.execute(sql) |
| 270 | conn.commit() |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 271 | return({'compilerid':compilerid,'platformid':platformid,'coreid':coreid}) |
| 272 | |
| 273 | def addConfig(conn,config,fullDate): |
| 274 | conn.execute("INSERT INTO CONFIG(compilerid,platformid,coreid,date) VALUES(?,?,?,?)" ,(config['compilerid'],config['platformid'],config['coreid'],fullDate)) |
| 275 | conn.commit() |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 276 | |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 277 | def getGroup(a): |
| 278 | return(re.sub(r'^(.+)(F64|F32|F16|Q31|Q15|Q7|U32|U16|U8|S32|S16|S8)$',r'\1',a)) |
| 279 | |
| 280 | def addOneBenchmark(elem,fullPath,db,group,runid): |
Christophe Favergeon | 74a31ba | 2019-09-09 09:14:18 +0100 | [diff] [blame] | 281 | if os.path.isfile(fullPath): |
| 282 | full=pd.read_csv(fullPath,dtype={'OLDID': str} ,keep_default_na = False) |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 283 | fullDate = datetime.datetime.now() |
| 284 | full['DATE'] = fullDate |
Christophe Favergeon | 74a31ba | 2019-09-09 09:14:18 +0100 | [diff] [blame] | 285 | if group: |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 286 | tableName = getGroup(group) |
Christophe Favergeon | 74a31ba | 2019-09-09 09:14:18 +0100 | [diff] [blame] | 287 | else: |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 288 | tableName = getGroup(elem.data["class"]) |
Christophe Favergeon | 74a31ba | 2019-09-09 09:14:18 +0100 | [diff] [blame] | 289 | conn = sqlite3.connect(db) |
| 290 | createTableIfMissing(conn,elem,tableName,full) |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 291 | config = addRows(conn,elem,tableName,full,runid) |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 292 | addConfig(conn,config,fullDate) |
Christophe Favergeon | 74a31ba | 2019-09-09 09:14:18 +0100 | [diff] [blame] | 293 | conn.close() |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 294 | |
| 295 | |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 296 | def addToDB(benchmark,dbpath,elem,group,runid): |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 297 | if not elem.data["deprecated"]: |
| 298 | if elem.params: |
| 299 | benchPath = os.path.join(benchmark,elem.fullPath(),"regression.csv") |
| 300 | print("Processing %s" % benchPath) |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 301 | addOneBenchmark(elem,benchPath,dbpath,group,runid) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 302 | |
| 303 | for c in elem.children: |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 304 | addToDB(benchmark,dbpath,c,group,runid) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 305 | |
| 306 | |
| 307 | |
| 308 | parser = argparse.ArgumentParser(description='Generate summary benchmarks') |
| 309 | |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 310 | parser.add_argument('-f', nargs='?',type = str, default="Output.pickle", help="File path") |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 311 | parser.add_argument('-b', nargs='?',type = str, default="FullBenchmark", help="Full Benchmark dir path") |
| 312 | #parser.add_argument('-e', action='store_true', help="Embedded test") |
| 313 | parser.add_argument('-o', nargs='?',type = str, default="reg.db", help="Regression benchmark database") |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 314 | parser.add_argument('-r', nargs='?',type = int, default=0, help="Run ID") |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 315 | |
| 316 | parser.add_argument('others', nargs=argparse.REMAINDER) |
| 317 | |
| 318 | args = parser.parse_args() |
| 319 | |
| 320 | if args.f is not None: |
Christophe Favergeon | 6f8eee9 | 2019-10-09 12:21:27 +0100 | [diff] [blame] | 321 | #p = parse.Parser() |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 322 | # Parse the test description file |
Christophe Favergeon | 6f8eee9 | 2019-10-09 12:21:27 +0100 | [diff] [blame] | 323 | #root = p.parse(args.f) |
| 324 | root=parse.loadRoot(args.f) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 325 | d.deprecate(root,args.others) |
| 326 | if args.others: |
| 327 | group=args.others[0] |
| 328 | else: |
| 329 | group=None |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 330 | addToDB(args.b,args.o,root,group,args.r) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 331 | |
| 332 | else: |
| 333 | parser.print_help() |