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