blob: 31643e56a9e36b3d1c4176d0614db4af1112ba79 [file] [log] [blame]
Christophe Favergeon8cb37302020-05-13 13:06:58 +02001import argparse
2import sqlite3
3import re
4import pandas as pd
5import numpy as np
Christophe Favergeoned0eab82020-05-18 08:43:38 +02006from TestScripts.doc.Structure import *
7from TestScripts.doc.Format import *
Christophe Favergeon66de4ac2020-07-31 13:38:09 +02008import os.path
Christophe Favergeonc3f455c2020-05-14 09:24:07 +02009
Christophe Favergeon670b1672020-05-28 12:47:58 +020010runidCMD = "runid = ?"
Christophe Favergeonc3f455c2020-05-14 09:24:07 +020011
Christophe Favergeon8cb37302020-05-13 13:06:58 +020012# Command to get last runid
13lastID="""SELECT runid FROM RUN ORDER BY runid DESC LIMIT 1
14"""
15
Christophe Favergeone15894e2020-05-14 07:25:53 +020016# Command to get last runid and date
17lastIDAndDate="""SELECT date FROM RUN WHERE runid=?
18"""
19
Christophe Favergeonfe27d872020-07-31 07:20:18 +020020# Command to get last runid
21runIDDetails="""SELECT distinct core FROM %s
22INNER JOIN CORE USING(coreid)
23WHERE %s
24"""
25
Christophe Favergeon0e0449a2020-07-28 09:44:14 +020026def joinit(iterable, delimiter):
27 # Intersperse a delimiter between element of a list
28 it = iter(iterable)
29 yield next(it)
30 for x in it:
31 yield delimiter
32 yield x
33
34
Christophe Favergeon8cb37302020-05-13 13:06:58 +020035def getLastRunID():
36 r=c.execute(lastID)
37 return(int(r.fetchone()[0]))
38
Christophe Favergeone15894e2020-05-14 07:25:53 +020039def getrunIDDate(forID):
40 r=c.execute(lastIDAndDate,(forID,))
41 return(r.fetchone()[0])
Christophe Favergeon8cb37302020-05-13 13:06:58 +020042
Christophe Favergeonfe27d872020-07-31 07:20:18 +020043
44
Christophe Favergeon8cb37302020-05-13 13:06:58 +020045
46parser = argparse.ArgumentParser(description='Generate summary benchmarks')
47
Christophe Favergeonfeb73932020-05-20 14:48:06 +020048parser.add_argument('-b', nargs='?',type = str, default="bench.db", help="Database")
Christophe Favergeon8cb37302020-05-13 13:06:58 +020049parser.add_argument('-o', nargs='?',type = str, default="full.md", help="Full summary")
50parser.add_argument('-r', action='store_true', help="Regression database")
Christophe Favergeonfe27d872020-07-31 07:20:18 +020051parser.add_argument('-t', nargs='?',type = str, default="md", help="type md or html")
52parser.add_argument('-byc', action='store_true', help="Result oganized by Compiler")
Christophe Favergeon670b1672020-05-28 12:47:58 +020053parser.add_argument('-g', action='store_true', help="Include graphs in regression report")
Christophe Favergeon8cb37302020-05-13 13:06:58 +020054
Christophe Favergeonfe27d872020-07-31 07:20:18 +020055parser.add_argument('-details', action='store_true', help="Details about runids")
56parser.add_argument('-lastid', action='store_true', help="Get last ID")
Christophe Favergeon66de4ac2020-07-31 13:38:09 +020057parser.add_argument('-comments', nargs='?',type = str, default="comments.txt", help="Comment section")
Christophe Favergeonf1a87802020-08-17 07:36:05 +020058parser.add_argument('-byd', action='store_true', help="Result oganized by datatype")
Christophe Favergeonfe27d872020-07-31 07:20:18 +020059
Christophe Favergeon8cb37302020-05-13 13:06:58 +020060# For runid or runid range
Christophe Favergeon4fa1e232020-05-15 12:28:17 +020061parser.add_argument('others', nargs=argparse.REMAINDER,help="Run ID")
Christophe Favergeon8cb37302020-05-13 13:06:58 +020062
63args = parser.parse_args()
64
65c = sqlite3.connect(args.b)
66
67if args.others:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +020068 vals=[]
69 runidCMD=[]
70 runidHeader=[]
71 for t in args.others:
72 if re.search(r'-',t):
73 bounds=[int(x) for x in t.split("-")]
74 vals += bounds
75 runidHeader += ["%d <= runid <= %d" % tuple(bounds)]
76 runidCMD += ["(runid >= ? AND runid <= ?)"]
77 else:
78 theid=int(t)
79 runidHeader += ["runid == %d" % theid]
80 runidCMD += ["runid == ?"]
81 vals.append(theid)
82
83 runidval = tuple(vals)
84 runidHeader = "".join(joinit(runidHeader," OR "))
85 runidCMD = "".join(joinit(runidCMD," OR "))
Christophe Favergeon8cb37302020-05-13 13:06:58 +020086else:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +020087 theid=getLastRunID()
88 print("Last run ID = %d\n" % theid)
89 runidval=(theid,)
90 runidHeader="%d" % theid
Christophe Favergeon8cb37302020-05-13 13:06:58 +020091
Christophe Favergeonfe27d872020-07-31 07:20:18 +020092
Christophe Favergeon8cb37302020-05-13 13:06:58 +020093# We extract data only from data tables
94# Those tables below are used for descriptions
Christophe Favergeon4fa1e232020-05-15 12:28:17 +020095REMOVETABLES=['TESTNAME','TESTDATE','RUN','CORE', 'PLATFORM', 'COMPILERKIND', 'COMPILER', 'TYPE', 'CATEGORY', 'CONFIG']
Christophe Favergeon8cb37302020-05-13 13:06:58 +020096
97# This is assuming the database is generated by the regression script
98# So platform is the same for all benchmarks.
99# Category and type is coming from the test name in the yaml
100# So no need to add this information here
101# Name is removed here because it is added at the beginning
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200102REMOVECOLUMNS=['runid','name','type','platform','category','coredef','OPTIMIZED','HARDFP','FASTMATH','NEON','HELIUM','UNROLL','ROUNDING','DATE','compilerkindid','date','categoryid', 'ID', 'platformid', 'coreid', 'compilerid', 'typeid']
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200103
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200104REMOVECOLUMNSFORHISTORY=['Regression','MAXREGCOEF','name','type','platform','category','coredef','OPTIMIZED','HARDFP','FASTMATH','NEON','HELIUM','UNROLL','ROUNDING','DATE','compilerkindid','date','categoryid', 'ID', 'platformid', 'coreid', 'compilerid', 'typeid']
105
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200106# Get existing benchmark tables
107def getBenchTables():
108 r=c.execute("SELECT name FROM sqlite_master WHERE type='table'")
109 benchtables=[]
110 for table in r:
111 if not table[0] in REMOVETABLES:
112 benchtables.append(table[0])
113 return(benchtables)
114
115# get existing types in a table
116def getExistingTypes(benchTable):
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200117 r=c.execute("select distinct typeid from %s WHERE %s order by typeid desc " % (benchTable,runidCMD),runidval).fetchall()
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200118 result=[x[0] for x in r]
119 return(result)
120
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200121# Get existing cores in a table
122def getAllExistingCores(benchTable):
123 r=c.execute("select distinct coreid from %s WHERE %s order by coreid desc " % (benchTable,runidCMD),runidval).fetchall()
124 result=[x[0] for x in r]
125 return(result)
126
Christophe Favergeonfe27d872020-07-31 07:20:18 +0200127def getrunIDDetails():
128 tables=getBenchTables()
129 r=[]
130 for table in tables:
131 r += [x[0] for x in c.execute(runIDDetails % (table,runidCMD),runidval).fetchall()]
132 r=list(set(r))
133 print(r)
134
135if args.lastid:
136 quit()
137
138if args.details:
139 getrunIDDetails()
140 quit()
141
142
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200143# Get compilers from specific type and table
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200144allCompilers="""select distinct compilerid from %s WHERE typeid=?"""
145
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200146# Get compilers from specific type and table
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200147allCompilerForCore="""select distinct compilerid from %s WHERE coreid=?"""
148
149# Get compilers from specific type and table
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200150allCores="""select distinct coreid from %s WHERE typeid=? AND (%s)"""
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200151
152
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200153compilerDesc="""select compiler,version from COMPILER
154 INNER JOIN COMPILERKIND USING(compilerkindid) WHERE compilerid=?"""
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200155
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200156coreDesc="""select core from CORE WHERE coreid=?"""
157
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200158# Get existing compiler in a table for a specific type
159# (In case report is structured by types)
160def getExistingCompiler(benchTable,typeid):
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200161 r=c.execute(allCompilers % benchTable,(typeid,)).fetchall()
162 return([x[0] for x in r])
163
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200164
165# Get existing compiler in a table for a specific core
166# (In case report is structured by core)
167def getExistingCompilerForCore(benchTable,coreid):
168 r=c.execute(allCompilerForCore % benchTable,(coreid,)).fetchall()
169 return([x[0] for x in r])
170
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200171def getExistingCores(benchTable,typeid):
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200172 vals = (typeid,) + runidval
173 r=c.execute(allCores % (benchTable,runidCMD),vals).fetchall()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200174 return([x[0] for x in r])
175
176
177
178def getCoreDesc(compilerid):
179 r=c.execute(coreDesc,(compilerid,)).fetchone()
180 return(r)
181
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200182def getCompilerDesc(compilerid):
183 r=c.execute(compilerDesc,(compilerid,)).fetchone()
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200184 return(r)
185
186# Get type name from type id
187def getTypeName(typeid):
188 r=c.execute("select type from TYPE where typeid=?",(typeid,)).fetchone()
189 return(r[0])
190
191# Diff of 2 lists
192def diff(first, second):
193 second = set(second)
194 return [item for item in first if item not in second]
195
196
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200197# Command to get data for specific compiler
198# and type
199benchCmdForCoreCompiler="""select %s from %s
200 INNER JOIN CATEGORY USING(categoryid)
201 INNER JOIN PLATFORM USING(platformid)
202 INNER JOIN CORE USING(coreid)
203 INNER JOIN COMPILER USING(compilerid)
204 INNER JOIN COMPILERKIND USING(compilerkindid)
205 INNER JOIN TYPE USING(typeid)
206 INNER JOIN TESTNAME USING(testnameid)
207 WHERE coreid=? AND compilerid = ? AND (%s)
208 """
209
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200210# Command to get data for specific core
211# and type
212historyCmd="""select %s from %s
213 INNER JOIN CATEGORY USING(categoryid)
214 INNER JOIN PLATFORM USING(platformid)
215 INNER JOIN CORE USING(coreid)
216 INNER JOIN COMPILER USING(compilerid)
217 INNER JOIN COMPILERKIND USING(compilerkindid)
218 INNER JOIN TYPE USING(typeid)
219 INNER JOIN TESTNAME USING(testnameid)
220 WHERE compilerid=? AND coreid=? AND typeid = ? AND ID = ? AND runid > (? - 10)
221 """
222
223compilersForHistory="""select distinct compilerid,compiler,version from %s
224 INNER JOIN COMPILER USING(compilerid)
225 INNER JOIN COMPILERKIND USING(compilerkindid)
226 WHERE coreid=? AND typeid = ? AND ID = ? AND runid > (? - 10)
227 """
228
229# Command to get data for specific core
230# and type
231benchCmdForCore="""select %s from %s
232 INNER JOIN CATEGORY USING(categoryid)
233 INNER JOIN PLATFORM USING(platformid)
234 INNER JOIN CORE USING(coreid)
235 INNER JOIN COMPILER USING(compilerid)
236 INNER JOIN COMPILERKIND USING(compilerkindid)
237 INNER JOIN TYPE USING(typeid)
238 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200239 WHERE coreid=? AND typeid = ? AND (%s)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200240 """
241
242coresForHistory="""select distinct coreid,core from %s
243 INNER JOIN CORE USING(coreid)
244 WHERE compilerid=? AND typeid = ? AND ID = ? AND runid > (? - 10)
245 """
246
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200247# Command to get data for specific compiler
248# and type
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200249benchCmdForCompiler="""select %s from %s
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200250 INNER JOIN CATEGORY USING(categoryid)
251 INNER JOIN PLATFORM USING(platformid)
252 INNER JOIN CORE USING(coreid)
253 INNER JOIN COMPILER USING(compilerid)
254 INNER JOIN COMPILERKIND USING(compilerkindid)
255 INNER JOIN TYPE USING(typeid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200256 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200257 WHERE compilerid=? AND typeid = ? AND (%s)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200258 """
259
260# Command to get test names for specific compiler
261# and type
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200262benchNamesForCore="""select distinct name from %s
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200263 INNER JOIN COMPILER USING(compilerid)
264 INNER JOIN COMPILERKIND USING(compilerkindid)
265 INNER JOIN TYPE USING(typeid)
266 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200267 WHERE coreid=? AND typeid = ? AND (%s)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200268 """
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200269
270# Command to get test names for specific core
271# and compiler
272benchNamesForCoreCompiler="""select distinct name from %s
273 INNER JOIN COMPILER USING(compilerid)
274 INNER JOIN COMPILERKIND USING(compilerkindid)
275 INNER JOIN TYPE USING(typeid)
276 INNER JOIN TESTNAME USING(testnameid)
277 WHERE coreid=? AND compilerid = ? AND (%s)
278 """
279
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200280# Command to get test names for specific compiler
281# and type
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200282benchNamesForCompiler="""select distinct name from %s
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200283 INNER JOIN COMPILER USING(compilerid)
284 INNER JOIN COMPILERKIND USING(compilerkindid)
285 INNER JOIN TYPE USING(typeid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200286 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200287 WHERE compilerid=? AND typeid = ? AND (%s)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200288 """
289
290# Command to get columns for specific table
291benchCmdColumns="""select * from %s
292 INNER JOIN CATEGORY USING(categoryid)
293 INNER JOIN PLATFORM USING(platformid)
294 INNER JOIN CORE USING(coreid)
295 INNER JOIN COMPILER USING(compilerid)
296 INNER JOIN COMPILERKIND USING(compilerkindid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200297 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200298 INNER JOIN TYPE USING(typeid)
299 """
300
301def joinit(iterable, delimiter):
302 it = iter(iterable)
303 yield next(it)
304 for x in it:
305 yield delimiter
306 yield x
307
308# Is not a column name finishing by id
309# (often primary key for thetable)
310def isNotIDColumn(col):
311 if re.match(r'^.*id$',col):
312 return(False)
313 else:
314 return(True)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200315
316# Get test names
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200317# for specific core and compiler (for the data)
318def getTestNamesForCoreCompiler(benchTable,compilerid,core):
319 vals=(core,compilerid) + runidval
320 result=c.execute(benchNamesForCoreCompiler % (benchTable,runidCMD),vals).fetchall()
321 names=[x[0] for x in list(result)]
322 return(names)
323
324# Get test names
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200325# for specific typeid and core (for the data)
326def getTestNamesForCore(benchTable,core,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200327 vals=(core,typeid) + runidval
328 result=c.execute(benchNamesForCore % (benchTable,runidCMD),vals).fetchall()
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200329 names=[x[0] for x in list(result)]
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200330 return(names)
331
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200332# Get test names
333# for specific typeid and compiler (for the data)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200334def getTestNamesForCompiler(benchTable,comp,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200335 vals=(comp,typeid) + runidval
336 result=c.execute(benchNamesForCompiler % (benchTable,runidCMD),vals).fetchall()
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200337 names=[x[0] for x in list(result)]
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200338 return(names)
339
340# Command to get data for specific core
341# and type
342nbElemsInBenchAndTypeAndCoreCmd="""select count(*) from %s
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200343 WHERE coreid=? AND typeid = ? AND (%s)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200344 """
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200345
Christophe Favergeone15894e2020-05-14 07:25:53 +0200346# Command to get data for specific compiler
347# and type
348nbElemsInBenchAndTypeAndCompilerCmd="""select count(*) from %s
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200349 WHERE compilerid=? AND typeid = ? AND (%s)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200350 """
351
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200352# Command to get data for specific compiler
353# and type
354nbElemsInBenchAndCoreAndCompilerCmd="""select count(*) from %s
355 WHERE compilerid=? AND coreid = ? AND (%s)
356 """
357
Christophe Favergeone15894e2020-05-14 07:25:53 +0200358nbElemsInBenchAndTypeCmd="""select count(*) from %s
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200359 WHERE typeid = ? AND (%s)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200360 """
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200361nbElemsInBenchAndCoreCmd="""select count(*) from %s
362 WHERE coreid = ? AND (%s)
363 """
Christophe Favergeone15894e2020-05-14 07:25:53 +0200364
365nbElemsInBenchCmd="""select count(*) from %s
Christophe Favergeon670b1672020-05-28 12:47:58 +0200366 WHERE %s
Christophe Favergeone15894e2020-05-14 07:25:53 +0200367 """
368
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200369categoryName="""select distinct category from %s
370 INNER JOIN CATEGORY USING(categoryid)
Christophe Favergeon670b1672020-05-28 12:47:58 +0200371 WHERE %s
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200372 """
373
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200374def getCategoryName(benchTable):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200375 result=c.execute(categoryName % (benchTable,runidCMD),runidval).fetchone()
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200376 return(result[0])
377
Christophe Favergeon4f750702020-05-13 15:56:15 +0200378# Get nb elems in a table
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200379def getNbElemsInBenchAndTypeAndCoreCmd(benchTable,coreid,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200380 vals=(coreid,typeid) + runidval
381 result=c.execute(nbElemsInBenchAndTypeAndCoreCmd % (benchTable,runidCMD),vals).fetchone()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200382 return(result[0])
383
384# Get nb elems in a table
Christophe Favergeone15894e2020-05-14 07:25:53 +0200385def getNbElemsInBenchAndTypeAndCompilerCmd(benchTable,comp,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200386 vals=(comp,typeid) + runidval
387 result=c.execute(nbElemsInBenchAndTypeAndCompilerCmd % (benchTable,runidCMD),vals).fetchone()
Christophe Favergeone15894e2020-05-14 07:25:53 +0200388 return(result[0])
389
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200390# Get nb elems in a table
391def getNbElemsInBenchAndCoreAndCompilerCmd(benchTable,comp,coreid):
392 vals=(comp,coreid) + runidval
393 result=c.execute(nbElemsInBenchAndCoreAndCompilerCmd % (benchTable,runidCMD),vals).fetchone()
394 return(result[0])
395
Christophe Favergeone15894e2020-05-14 07:25:53 +0200396def getNbElemsInBenchAndTypeCmd(benchTable,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200397 vals=(typeid,) + runidval
398 result=c.execute(nbElemsInBenchAndTypeCmd % (benchTable,runidCMD),vals).fetchone()
Christophe Favergeone15894e2020-05-14 07:25:53 +0200399 return(result[0])
400
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200401def getNbElemsInBenchAndCoreCmd(benchTable,coreid):
402 vals=(coreid,) + runidval
403 result=c.execute(nbElemsInBenchAndCoreCmd % (benchTable,runidCMD),vals).fetchone()
404 return(result[0])
405
Christophe Favergeone15894e2020-05-14 07:25:53 +0200406def getNbElemsInBenchCmd(benchTable):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200407 result=c.execute(nbElemsInBenchCmd % (benchTable,runidCMD),runidval).fetchone()
Christophe Favergeon4f750702020-05-13 15:56:15 +0200408 return(result[0])
409
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200410# Get names of columns and data for a table
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200411# for specific typeid and coreid (for the data)
412def getColNamesAndHistory(benchTable,compiler,core,typeid,testid):
413 cursor=c.cursor()
414 result=cursor.execute(benchCmdColumns % (benchTable))
415 cols= [member[0] for member in cursor.description]
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200416 keepCols = ['name'] + [c for c in diff(cols , REMOVECOLUMNSFORHISTORY) if isNotIDColumn(c)]
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200417 keepColsStr = "".join(joinit(keepCols,","))
418 vals=(compiler,core,typeid,testid,runid)
419 result=cursor.execute(historyCmd % (keepColsStr,benchTable),vals)
420 vals =np.array([list(x) for x in list(result)])
421 return(keepCols,vals)
422
423# Get names of columns and data for a table
424# for specific typeid and coreid (for the data)
425def getColNamesAndDataForCore(benchTable,core,typeid):
426 cursor=c.cursor()
427 result=cursor.execute(benchCmdColumns % (benchTable))
428 cols= [member[0] for member in cursor.description]
429 keepCols = ['name'] + [c for c in diff(cols , REMOVECOLUMNS) if isNotIDColumn(c)]
430 keepColsStr = "".join(joinit(keepCols,","))
Christophe Favergeon670b1672020-05-28 12:47:58 +0200431 vals=(core,typeid) + runidval
432 result=cursor.execute(benchCmdForCore % (keepColsStr,benchTable,runidCMD),vals)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200433 vals =np.array([list(x) for x in list(result)])
434 return(keepCols,vals)
435
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200436# Get names of columns and data for a table
437# for specific coreid and compilerid (for the data)
438def getColNamesAndDataForCoreCompiler(benchTable,compilerid,core):
439 cursor=c.cursor()
440 result=cursor.execute(benchCmdColumns % (benchTable))
441 cols= [member[0] for member in cursor.description]
442 keepCols = ['name','type'] + [c for c in diff(cols , REMOVECOLUMNS) if isNotIDColumn(c)]
443 keepColsStr = "".join(joinit(keepCols,","))
444 vals=(core,compilerid) + runidval
445 result=cursor.execute(benchCmdForCoreCompiler % (keepColsStr,benchTable,runidCMD),vals)
446 vals =np.array([list(x) for x in list(result)])
447 return(keepCols,vals)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200448
449# Get names of columns and data for a table
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200450# for specific typeid and compiler (for the data)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200451def getColNamesAndDataForCompiler(benchTable,comp,typeid):
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200452 cursor=c.cursor()
453 result=cursor.execute(benchCmdColumns % (benchTable))
454 cols= [member[0] for member in cursor.description]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200455 keepCols = ['name'] + [c for c in diff(cols , REMOVECOLUMNS) if isNotIDColumn(c)]
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200456 keepColsStr = "".join(joinit(keepCols,","))
Christophe Favergeon670b1672020-05-28 12:47:58 +0200457 vals=(comp,typeid) + runidval
458 result=cursor.execute(benchCmdForCompiler % (keepColsStr,benchTable,runidCMD),vals)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200459 vals =np.array([list(x) for x in list(result)])
460 return(keepCols,vals)
461
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200462
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200463
464PARAMS=["NB","NumTaps", "NBA", "NBB", "Factor", "NumStages","VECDIM","NBR","NBC","NBI","IFFT", "BITREV"]
465
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200466def regressionTableFor(byname,name,section,ref,toSort,indexCols,field):
467 data=ref.pivot_table(index=indexCols, columns=byname,
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200468 values=[field], aggfunc='first')
469
470 data=data.sort_values(toSort)
471
472 cores = [c[1] for c in list(data.columns)]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200473 columns = diff(indexCols,['name'])
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200474
Christophe Favergeon34d313a2020-05-14 15:09:41 +0200475 dataTable=Table(columns,cores)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200476 section.addContent(dataTable)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200477
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200478 dataForFunc=data.loc[name]
479 if type(dataForFunc) is pd.DataFrame:
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200480 bars={'cols':columns,'cores':cores,'data':[]}
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200481 for row in dataForFunc.itertuples():
482 row=list(row)
483 if type(row[0]) is int:
484 row=[row[0]] + row[1:]
485 else:
486 row=list(row[0]) + row[1:]
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200487 if field=="MAXREGCOEF":
Christophe Favergeon670b1672020-05-28 12:47:58 +0200488 newrow = row
489 newrow[len(columns):] = [("%.3f" % x) for x in row[len(columns):]]
490 row=newrow
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200491 dataTable.addRow(row)
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200492 bars['data'].append(row)
493 return(bars)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200494 else:
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200495 if field=="MAXREGCOEF":
496 dataForFunc=[("%.3f" % x) for x in dataForFunc]
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200497 dataTable.addRow(dataForFunc)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200498 return(list(zip(cores,dataForFunc)))
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200499
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200500def formatColumnName(c):
501 return("".join(joinit(c,":")))
502
503def getCoresForHistory(benchTable,compilerid,typeid,testid,runid):
504 vals=(compilerid,typeid,testid,runid)
505 result=c.execute(coresForHistory % benchTable,vals).fetchall()
506 ids=[(x[0],x[1]) for x in list(result)]
507 return(ids)
508
509def getCompilerForHistory(benchTable,coreid,typeid,testid,runid):
510 vals=(coreid,typeid,testid,runid)
511 result=c.execute(compilersForHistory % benchTable,vals).fetchall()
512 ids=[(x[0],x[1],x[2]) for x in list(result)]
513 return(ids)
514
515def getHistory(desc,testid,indexCols):
516 benchName,sectionID,typeid,runid = desc
517
518 #print(benchName)
519 #print(sectionID)
520 #print(typeid)
521 #print(testid)
522 columns = diff(indexCols,['name'])
523 #print(columns)
524 if args.byc:
525 coreid=sectionID
526 compilerids=getCompilerForHistory(benchName,coreid,typeid,testid,runid)
527 series={}
528 for compilerid,compilername,version in compilerids:
529 result=getColNamesAndHistory(benchName,compilerid,coreid,typeid,testid)
530 #print("%s:%s" % (compilername,version))
531 maxpos = result[0].index('MAX')
532 lrunid = result[0].index('runid')
533 r=[[int(x[lrunid]),int(x[maxpos])] for x in result[1:][0]]
534 series[corename]=r
535 hist=History(series,runid)
536 return(hist)
537 else:
538 compilerid=sectionID
539 coreids = getCoresForHistory(benchName,compilerid,typeid,testid,runid)
540 series={}
541 for coreid,corename in coreids:
542 result=getColNamesAndHistory(benchName,compilerid,coreid,typeid,testid)
543 #print(corename)
544 maxpos = result[0].index('MAX')
545 corepos = result[0].index('core')
546 lrunid = result[0].index('runid')
547 r=[[int(x[lrunid]),int(x[maxpos])] for x in result[1:][0]]
548 series[corename]=r
549 hist=History(series,runid)
550 return(hist)
551
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200552def convertRowToInt(r):
553 result=[]
554 for e in r:
555 if type(e) is float:
556 result.append(int(e))
557 else:
558 result.append(e)
559
560 return(result)
561
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200562def formatTableBy(desc,byname,section,typeSection,testNames,cols,vals):
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200563 if vals.size != 0:
564 ref=pd.DataFrame(vals,columns=cols)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200565 toSort=["name"]
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200566
567 for param in PARAMS:
568 if param in ref.columns:
569 ref[param]=pd.to_numeric(ref[param])
570 toSort.append(param)
571 if args.r:
572 # Regression table
573 ref['MAX']=pd.to_numeric(ref['MAX'])
574 ref['MAXREGCOEF']=pd.to_numeric(ref['MAXREGCOEF'])
575
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200576 indexCols=diff(cols,byname + ['Regression','MAXREGCOEF','MAX'] + section)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200577 valList = ['Regression']
578 else:
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200579 ref['CYCLES']=pd.to_numeric(ref['CYCLES']).round(decimals=0)
580
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200581 indexCols=diff(cols,byname + ['CYCLES'] + section)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200582 valList = ['CYCLES']
583
584
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200585 for name in testNames:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200586 if args.r:
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200587 testSection = Section(name)
588 typeSection.addSection(testSection)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200589
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200590 maxCyclesSection = Section("Max cycles")
591 testSection.addSection(maxCyclesSection)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200592 theCycles=regressionTableFor(byname,name,maxCyclesSection,ref,toSort,indexCols,'MAX')
Christophe Favergeon670b1672020-05-28 12:47:58 +0200593 if args.g:
594 if type(theCycles) is dict:
595 nbParams=len(theCycles['cols'])
596 for bar in theCycles['data']:
597 params=bar[0:nbParams]
598 values=bar[nbParams:]
599 title=[("%s=%s" % x) for x in list(zip(theCycles['cols'],params))]
600 title="".join(joinit(title," "))
601 sec=Section(title)
602 maxCyclesSection.addSection(sec)
603 values=list(zip(theCycles['cores'],values))
604 barChart=BarChart(values)
605 sec.addContent(barChart)
606 else:
607 #print(theCycles)
608 sec=Section("Graph")
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200609 maxCyclesSection.addSection(sec)
Christophe Favergeon670b1672020-05-28 12:47:58 +0200610 barChart=BarChart(theCycles)
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200611 sec.addContent(barChart)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200612
Christophe Favergeon670b1672020-05-28 12:47:58 +0200613 #history=getHistory(desc,testid,indexCols)
614 #testSection.addContent(history)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200615
616 regressionSection = Section("Regression")
617 testSection.addSection(regressionSection)
618 regressionTableFor(byname,name,regressionSection,ref,toSort,indexCols,'Regression')
619
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200620
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200621 maxRegCoefSection = Section("Max Reg Coef")
622 testSection.addSection(maxRegCoefSection)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200623 regressionTableFor(byname,name,maxRegCoefSection,ref,toSort,indexCols,'MAXREGCOEF')
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200624
625 else:
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200626 data=ref.pivot_table(index=indexCols, columns=byname,
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200627 values=valList, aggfunc='first')
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200628
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200629 data=data.sort_values(toSort)
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200630
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200631 #print(list(data.columns))
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200632
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200633 testSection = Section(name)
634 typeSection.addSection(testSection)
635
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200636 dataForFunc=data.loc[name]
637 dataForFunc = dataForFunc.dropna(axis=1)
638
639 columnsID = [formatColumnName(c[1:]) for c in list(dataForFunc.columns)]
640 columns = diff(indexCols,['name'])
641
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200642 dataTable=Table(columns,columnsID)
643 testSection.addContent(dataTable)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200644
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200645
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200646 if type(dataForFunc) is pd.DataFrame:
647 for row in dataForFunc.itertuples():
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200648 if type(row[0]) is int:
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200649 row=list([row[0]] + list(row[1:]))
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200650 else:
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200651 row=list(row[0]) + list(row[1:])
652 dataTable.addRow(convertRowToInt(row))
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200653 else:
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200654 dataTable.addRow(convertRowToInt(dataForFunc))
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200655
656# Add a report for each table
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200657def addReportFor(document,benchName):
Christophe Favergeone15894e2020-05-14 07:25:53 +0200658 nbElems = getNbElemsInBenchCmd(benchName)
659 if nbElems > 0:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200660 categoryName = getCategoryName(benchName)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200661 benchSection = Section(categoryName)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200662 document.addSection(benchSection)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200663 print("Process %s\n" % benchName)
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200664 if args.byd:
665 allCores=getAllExistingCores(benchName)
666 for aCoreID in allCores:
667 nbElems = getNbElemsInBenchAndCoreCmd(benchName,aCoreID)
668 if nbElems > 0:
669 coreName=getCoreDesc(aCoreID)
670 coreSection = Section("%s" % coreName)
671 benchSection.addSection(coreSection)
672 allCompilers = getExistingCompilerForCore(benchName,aCoreID)
673 for compiler in allCompilers:
674 #print(compiler)
675 nbElems = getNbElemsInBenchAndCoreAndCompilerCmd(benchName,compiler,aCoreID)
676
677 # Print test results for table, type, compiler
678 if nbElems > 0:
679 compilerName,version=getCompilerDesc(compiler)
680 compilerSection = Section("%s (%s)" % (compilerName,version))
681 coreSection.addSection(compilerSection)
682 cols,vals=getColNamesAndDataForCoreCompiler(benchName,compiler,aCoreID)
683 desc=(benchName,compiler,aCoreID)
684 names=getTestNamesForCoreCompiler(benchName,compiler,aCoreID)
685
686 formatTableBy(desc,['type'],['core','version','compiler'],compilerSection,names,cols,vals)
687
688 else:
689 allTypes = getExistingTypes(benchName)
690 # Add report for each type
691 for aTypeID in allTypes:
692 nbElems = getNbElemsInBenchAndTypeCmd(benchName,aTypeID)
693 if nbElems > 0:
694 typeName = getTypeName(aTypeID)
695 typeSection = Section(typeName)
696 benchSection.addSection(typeSection)
697 if args.byc:
698 ## Add report for each core
699 allCores = getExistingCores(benchName,aTypeID)
700 for core in allCores:
701 #print(core)
702 nbElems = getNbElemsInBenchAndTypeAndCoreCmd(benchName,core,aTypeID)
703 # Print test results for table, type, compiler
704 if nbElems > 0:
705 coreName=getCoreDesc(core)
706 coreSection = Section("%s" % coreName)
707 typeSection.addSection(coreSection)
708 cols,vals=getColNamesAndDataForCore(benchName,core,aTypeID)
709 desc=(benchName,core,aTypeID)
710 names=getTestNamesForCore(benchName,core,aTypeID)
711 formatTableBy(desc,['compiler','version'],['core'],coreSection,names,cols,vals)
712 else:
713 ## Add report for each compiler
714 allCompilers = getExistingCompiler(benchName,aTypeID)
715 for compiler in allCompilers:
716 #print(compiler)
717 nbElems = getNbElemsInBenchAndTypeAndCompilerCmd(benchName,compiler,aTypeID)
718 # Print test results for table, type, compiler
719 if nbElems > 0:
720 compilerName,version=getCompilerDesc(compiler)
721 compilerSection = Section("%s (%s)" % (compilerName,version))
722 typeSection.addSection(compilerSection)
723 cols,vals=getColNamesAndDataForCompiler(benchName,compiler,aTypeID)
724 desc=(benchName,compiler,aTypeID)
725 names=getTestNamesForCompiler(benchName,compiler,aTypeID)
726 formatTableBy(desc,['core'],['version','compiler'],compilerSection,names,cols,vals)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200727
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200728
729
730
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200731toc=[Hierarchy("BasicMathsBenchmarks"),
732Hierarchy("ComplexMathsBenchmarks"),
733Hierarchy("FastMath"),
734Hierarchy("Filters",
735 [Hierarchy("FIR"),
736 Hierarchy("BIQUAD"),
737 Hierarchy("DECIM"),
738 Hierarchy("MISC")]),
739
740Hierarchy("Support Functions",
741 [Hierarchy("Support"),
742 Hierarchy("SupportBar")]),
743
744Hierarchy("Matrix Operations" ,
745 [Hierarchy("Binary"),
746 Hierarchy("Unary")]),
747Hierarchy("Transform"),
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200748Hierarchy("Stats"),
749Hierarchy("Classical ML",[
750 Hierarchy("Bayes"),
751 Hierarchy("SVM"),
752 Hierarchy("Distance"),
753 ]),
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200754
755]
756
757processed=[]
758
Christophe Favergeon66de4ac2020-07-31 13:38:09 +0200759def addComments(document):
760 if os.path.exists(args.comments):
761 section=Section("Measurement Context")
762
763 document.addSection(section)
764 para=""
765 with open(args.comments,"r") as r:
766 for l in r:
767 if l.strip():
768 para += l
769 else:
770 section.addContent(Text(para))
771 para=""
772 if para:
773 section.addContent(Text(para))
774
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200775def createDoc(document,sections,benchtables):
776 global processed
777 for s in sections:
778 if s.name in benchtables:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200779 addReportFor(document,s.name)
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200780 processed.append(s.name)
781 else:
782 section=Section(s.name)
783 document.addSection(section)
784 createDoc(section,s.sections,benchtables)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200785
786try:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200787 benchtables=getBenchTables()
Christophe Favergeon66de4ac2020-07-31 13:38:09 +0200788 document = Document(runidHeader)
789
790 addComments(document)
791
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200792 createDoc(document,toc,benchtables)
Christophe Favergeon66de4ac2020-07-31 13:38:09 +0200793
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200794 misc=Section("Miscellaneous")
795 document.addSection(misc)
796 remaining=diff(benchtables,processed)
797 for bench in remaining:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200798 addReportFor(misc,bench)
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200799
800 #for bench in benchtables:
801 # addReportFor(document,bench)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200802 with open(args.o,"w") as output:
803 if args.t=="md":
804 document.accept(Markdown(output))
805 if args.t=="html":
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200806 reorder=NORMALFORMAT
Christophe Favergeonf1a87802020-08-17 07:36:05 +0200807 if args.byc:
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200808 reorder=BYCFORMAT
809 if args.byd:
810 reorder=BYDFORMAT
Christophe Favergeonf1a87802020-08-17 07:36:05 +0200811 document.accept(HTML(output,args.r,reorder))
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200812
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200813finally:
814 c.close()
815
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200816
817
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200818