Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +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'] |
Christophe Favergeon | 74a31ba | 2019-09-09 09:14:18 +0100 | [diff] [blame] | 22 | MKBOOLFIELD=['HARDFP', 'FASTMATH', 'NEON', 'HELIUM','UNROLL', 'ROUNDING','OPTIMIZED'] |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 23 | MKINTFIELD=['ID', 'CYCLES'] |
| 24 | MKDATEFIELD=['DATE'] |
| 25 | MKKEYFIELD=['CATEGORY', 'PLATFORM', 'CORE', 'COMPILER','TYPE'] |
| 26 | MKKEYFIELDID={'CATEGORY':'categoryid', |
| 27 | 'PLATFORM':'platformid', |
| 28 | 'CORE':'coreid', |
| 29 | 'COMPILER':'compilerid', |
| 30 | 'TYPE':'typeid'} |
| 31 | |
| 32 | # For table value extraction |
| 33 | VALSTRFIELD=['NAME','VERSION'] |
Christophe Favergeon | 74a31ba | 2019-09-09 09:14:18 +0100 | [diff] [blame] | 34 | VALBOOLFIELD=['HARDFP', 'FASTMATH', 'NEON', 'HELIUM','UNROLL', 'ROUNDING','OPTIMIZED'] |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 35 | VALINTFIELD=['ID', 'CYCLES'] |
| 36 | VALDATEFIELD=['DATE'] |
| 37 | VALKEYFIELD=['CATEGORY', 'PLATFORM', 'CORE', 'COMPILER','TYPE'] |
| 38 | |
| 39 | def joinit(iterable, delimiter): |
| 40 | it = iter(iterable) |
| 41 | yield next(it) |
| 42 | for x in it: |
| 43 | yield delimiter |
| 44 | yield x |
| 45 | |
| 46 | def 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 | |
| 51 | def diff(first, second): |
| 52 | second = set(second) |
| 53 | return [item for item in first if item not in second] |
| 54 | |
| 55 | def getColumns(elem,full): |
| 56 | colsToKeep=[] |
| 57 | cols = list(full.columns) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 58 | params = list(elem.params.full) |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 59 | 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 | |
| 74 | def createTableIfMissing(conn,elem,tableName,full): |
| 75 | if not tableExists(conn,tableName): |
| 76 | sql = "CREATE TABLE %s (" % tableName |
| 77 | cols = list(full.columns) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 78 | params = list(elem.params.full) |
| 79 | common = diff(cols + ["TYPE"] , ['OLDID'] + params) |
Christophe Favergeon | 058b63b | 2019-07-25 10:40:32 +0200 | [diff] [blame] | 80 | |
| 81 | sql += "%sid INTEGER PRIMARY KEY" % (tableName) |
| 82 | start = "," |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 83 | |
| 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 Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 107 | conn.execute(sql) |
| 108 | |
| 109 | # Find the key or add it in a table |
| 110 | def 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 | |
| 127 | def 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 Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 134 | fullDate = datetime.datetime.now() |
| 135 | conn.execute("INSERT INTO COMPILER(compilerkindid,version,date) VALUES(?,?,?)" ,(kind,version,fullDate)) |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 136 | conn.commit() |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 137 | r = conn.execute("select compilerid from COMPILER where compilerkindid=? AND version=? AND date=?" , (kind,version,fullDate)) |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 138 | result=r.fetchone() |
| 139 | if result != None: |
| 140 | #print(result) |
| 141 | return(result[0]) |
| 142 | else: |
| 143 | return(None) |
| 144 | |
| 145 | |
| 146 | def addRows(conn,elem,tableName,full): |
| 147 | # List of columns we have in DB which is |
| 148 | # different from the columns in the table |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 149 | compilerid = 0 |
| 150 | platformid = 0 |
| 151 | coreid = 0 |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 152 | keep = getColumns(elem,full) |
| 153 | cols = list(full.columns) |
Christophe Favergeon | 4a8d9dc | 2019-08-14 08:55:46 +0200 | [diff] [blame] | 154 | params = list(elem.params.full) |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 155 | common = diff(["TYPE"] + cols , ['OLDID'] + params) |
Christophe Favergeon | 058b63b | 2019-07-25 10:40:32 +0200 | [diff] [blame] | 156 | 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 Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 165 | #print(full) |
| 166 | for index, row in full.iterrows(): |
Christophe Favergeon | 058b63b | 2019-07-25 10:40:32 +0200 | [diff] [blame] | 167 | sql = "INSERT INTO %s(%s) VALUES(" % (tableName,colNames) |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 168 | 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 Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 223 | coreid = val |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 224 | if field == "PLATFORM": |
| 225 | val = findInTable(conn,"PLATFORM","platform",row[field],"platformid") |
| 226 | keys[field]=val |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 227 | platformid = val |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 228 | 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 Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 235 | compilerid = compiler |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 236 | |
| 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 Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 254 | return({'compilerid':compilerid,'platformid':platformid,'coreid':coreid}) |
| 255 | |
| 256 | def 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 Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 259 | |
| 260 | def addOneBenchmark(elem,fullPath,db,group): |
Christophe Favergeon | 74a31ba | 2019-09-09 09:14:18 +0100 | [diff] [blame] | 261 | if os.path.isfile(fullPath): |
| 262 | full=pd.read_csv(fullPath,dtype={'OLDID': str} ,keep_default_na = False) |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 263 | fullDate = datetime.datetime.now() |
| 264 | full['DATE'] = fullDate |
Christophe Favergeon | 74a31ba | 2019-09-09 09:14:18 +0100 | [diff] [blame] | 265 | if group: |
| 266 | tableName = group |
| 267 | else: |
| 268 | tableName = elem.data["class"] |
| 269 | conn = sqlite3.connect(db) |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame^] | 270 | createTableIfMissing(conn,elem,tableName,full) |
Christophe Favergeon | 256f2da | 2019-09-10 14:56:10 +0200 | [diff] [blame] | 271 | config = addRows(conn,elem,tableName,full) |
| 272 | addConfig(conn,config,fullDate) |
Christophe Favergeon | 74a31ba | 2019-09-09 09:14:18 +0100 | [diff] [blame] | 273 | conn.close() |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 274 | |
| 275 | |
| 276 | def 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 | |
| 288 | parser = argparse.ArgumentParser(description='Generate summary benchmarks') |
| 289 | |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame^] | 290 | parser.add_argument('-f', nargs='?',type = str, default="Output.pickle", help="File path") |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 291 | parser.add_argument('-b', nargs='?',type = str, default="FullBenchmark", help="Full Benchmark dir path") |
Christophe Favergeon | 97ce6fd | 2019-07-29 07:44:23 +0200 | [diff] [blame] | 292 | #parser.add_argument('-e', action='store_true', help="Embedded test") |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 293 | parser.add_argument('-o', nargs='?',type = str, default="bench.db", help="Benchmark database") |
| 294 | |
| 295 | parser.add_argument('others', nargs=argparse.REMAINDER) |
| 296 | |
| 297 | args = parser.parse_args() |
| 298 | |
| 299 | if args.f is not None: |
Christophe Favergeon | 6f8eee9 | 2019-10-09 12:21:27 +0100 | [diff] [blame] | 300 | #p = parse.Parser() |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 301 | # Parse the test description file |
Christophe Favergeon | 6f8eee9 | 2019-10-09 12:21:27 +0100 | [diff] [blame] | 302 | #root = p.parse(args.f) |
| 303 | root=parse.loadRoot(args.f) |
Christophe Favergeon | 37b8622 | 2019-07-17 11:49:00 +0200 | [diff] [blame] | 304 | 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 | |
| 311 | else: |
| 312 | parser.print_help() |