blob: a7b9e9481842f029b5a412c14d4ec07e18d974ad [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 +020045runid = 1
46
47parser = argparse.ArgumentParser(description='Generate summary benchmarks')
48
Christophe Favergeonfeb73932020-05-20 14:48:06 +020049parser.add_argument('-b', nargs='?',type = str, default="bench.db", help="Database")
Christophe Favergeon8cb37302020-05-13 13:06:58 +020050parser.add_argument('-o', nargs='?',type = str, default="full.md", help="Full summary")
51parser.add_argument('-r', action='store_true', help="Regression database")
Christophe Favergeonfe27d872020-07-31 07:20:18 +020052parser.add_argument('-t', nargs='?',type = str, default="md", help="type md or html")
53parser.add_argument('-byc', action='store_true', help="Result oganized by Compiler")
Christophe Favergeon670b1672020-05-28 12:47:58 +020054parser.add_argument('-g', action='store_true', help="Include graphs in regression report")
Christophe Favergeon8cb37302020-05-13 13:06:58 +020055
Christophe Favergeonfe27d872020-07-31 07:20:18 +020056parser.add_argument('-details', action='store_true', help="Details about runids")
57parser.add_argument('-lastid', action='store_true', help="Get last ID")
Christophe Favergeon66de4ac2020-07-31 13:38:09 +020058parser.add_argument('-comments', nargs='?',type = str, default="comments.txt", help="Comment section")
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 Favergeon670b1672020-05-28 12:47:58 +020068 if len(args.others) == 1:
Christophe Favergeon0e0449a2020-07-28 09:44:14 +020069 if re.search(r'[,]',args.others[0]):
70 runidval=tuple([int(x) for x in args.others[0].split(",")])
71 runidCMD=["runid == ?" for x in runidval]
72 runidCMD = "".join(joinit(runidCMD," OR "))
Christophe Favergeon66de4ac2020-07-31 13:38:09 +020073 runidHeader="".join(joinit([str(x) for x in runidval]," , "))
Christophe Favergeon0e0449a2020-07-28 09:44:14 +020074 runidCMD = "(" + runidCMD + ")"
75 else:
76 runid=int(args.others[0])
Christophe Favergeon66de4ac2020-07-31 13:38:09 +020077 runidHeader="%d" % runid
Christophe Favergeon0e0449a2020-07-28 09:44:14 +020078 runidval = (runid,)
Christophe Favergeon670b1672020-05-28 12:47:58 +020079 else:
80 runidCMD = "runid >= ? AND runid <= ?"
81 runid=int(args.others[1])
82 runidLOW=int(args.others[0])
83 runidval = (runidLOW,runid)
Christophe Favergeon66de4ac2020-07-31 13:38:09 +020084 runidHeader="%d <= runid <= %d" % runidval
Christophe Favergeon8cb37302020-05-13 13:06:58 +020085else:
86 runid=getLastRunID()
Christophe Favergeon670b1672020-05-28 12:47:58 +020087 print("Last run ID = %d\n" % runid)
88 runidval=(runid,)
Christophe Favergeon66de4ac2020-07-31 13:38:09 +020089 runidHeader="%d" % runid
Christophe Favergeon8cb37302020-05-13 13:06:58 +020090
Christophe Favergeonfe27d872020-07-31 07:20:18 +020091
Christophe Favergeon8cb37302020-05-13 13:06:58 +020092# We extract data only from data tables
93# Those tables below are used for descriptions
Christophe Favergeon4fa1e232020-05-15 12:28:17 +020094REMOVETABLES=['TESTNAME','TESTDATE','RUN','CORE', 'PLATFORM', 'COMPILERKIND', 'COMPILER', 'TYPE', 'CATEGORY', 'CONFIG']
Christophe Favergeon8cb37302020-05-13 13:06:58 +020095
96# This is assuming the database is generated by the regression script
97# So platform is the same for all benchmarks.
98# Category and type is coming from the test name in the yaml
99# So no need to add this information here
100# Name is removed here because it is added at the beginning
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200101REMOVECOLUMNS=['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 +0200102
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200103REMOVECOLUMNSFORHISTORY=['Regression','MAXREGCOEF','name','type','platform','category','coredef','OPTIMIZED','HARDFP','FASTMATH','NEON','HELIUM','UNROLL','ROUNDING','DATE','compilerkindid','date','categoryid', 'ID', 'platformid', 'coreid', 'compilerid', 'typeid']
104
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200105# Get existing benchmark tables
106def getBenchTables():
107 r=c.execute("SELECT name FROM sqlite_master WHERE type='table'")
108 benchtables=[]
109 for table in r:
110 if not table[0] in REMOVETABLES:
111 benchtables.append(table[0])
112 return(benchtables)
113
114# get existing types in a table
115def getExistingTypes(benchTable):
Christophe Favergeone15894e2020-05-14 07:25:53 +0200116 r=c.execute("select distinct typeid from %s order by typeid desc" % benchTable).fetchall()
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200117 result=[x[0] for x in r]
118 return(result)
119
Christophe Favergeonfe27d872020-07-31 07:20:18 +0200120def getrunIDDetails():
121 tables=getBenchTables()
122 r=[]
123 for table in tables:
124 r += [x[0] for x in c.execute(runIDDetails % (table,runidCMD),runidval).fetchall()]
125 r=list(set(r))
126 print(r)
127
128if args.lastid:
129 quit()
130
131if args.details:
132 getrunIDDetails()
133 quit()
134
135
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200136# Get compilers from specific type and table
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200137allCompilers="""select distinct compilerid from %s WHERE typeid=?"""
138
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200139# Get compilers from specific type and table
140allCores="""select distinct coreid from %s WHERE typeid=?"""
141
142
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200143compilerDesc="""select compiler,version from COMPILER
144 INNER JOIN COMPILERKIND USING(compilerkindid) WHERE compilerid=?"""
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200145
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200146coreDesc="""select core from CORE WHERE coreid=?"""
147
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200148# Get existing compiler in a table for a specific type
149# (In case report is structured by types)
150def getExistingCompiler(benchTable,typeid):
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200151 r=c.execute(allCompilers % benchTable,(typeid,)).fetchall()
152 return([x[0] for x in r])
153
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200154def getExistingCores(benchTable,typeid):
155 r=c.execute(allCores % benchTable,(typeid,)).fetchall()
156 return([x[0] for x in r])
157
158
159
160def getCoreDesc(compilerid):
161 r=c.execute(coreDesc,(compilerid,)).fetchone()
162 return(r)
163
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200164def getCompilerDesc(compilerid):
165 r=c.execute(compilerDesc,(compilerid,)).fetchone()
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200166 return(r)
167
168# Get type name from type id
169def getTypeName(typeid):
170 r=c.execute("select type from TYPE where typeid=?",(typeid,)).fetchone()
171 return(r[0])
172
173# Diff of 2 lists
174def diff(first, second):
175 second = set(second)
176 return [item for item in first if item not in second]
177
178
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200179# Command to get data for specific core
180# and type
181historyCmd="""select %s from %s
182 INNER JOIN CATEGORY USING(categoryid)
183 INNER JOIN PLATFORM USING(platformid)
184 INNER JOIN CORE USING(coreid)
185 INNER JOIN COMPILER USING(compilerid)
186 INNER JOIN COMPILERKIND USING(compilerkindid)
187 INNER JOIN TYPE USING(typeid)
188 INNER JOIN TESTNAME USING(testnameid)
189 WHERE compilerid=? AND coreid=? AND typeid = ? AND ID = ? AND runid > (? - 10)
190 """
191
192compilersForHistory="""select distinct compilerid,compiler,version from %s
193 INNER JOIN COMPILER USING(compilerid)
194 INNER JOIN COMPILERKIND USING(compilerkindid)
195 WHERE coreid=? AND typeid = ? AND ID = ? AND runid > (? - 10)
196 """
197
198# Command to get data for specific core
199# and type
200benchCmdForCore="""select %s from %s
201 INNER JOIN CATEGORY USING(categoryid)
202 INNER JOIN PLATFORM USING(platformid)
203 INNER JOIN CORE USING(coreid)
204 INNER JOIN COMPILER USING(compilerid)
205 INNER JOIN COMPILERKIND USING(compilerkindid)
206 INNER JOIN TYPE USING(typeid)
207 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon670b1672020-05-28 12:47:58 +0200208 WHERE coreid=? AND typeid = ? AND %s
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200209 """
210
211coresForHistory="""select distinct coreid,core from %s
212 INNER JOIN CORE USING(coreid)
213 WHERE compilerid=? AND typeid = ? AND ID = ? AND runid > (? - 10)
214 """
215
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200216# Command to get data for specific compiler
217# and type
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200218benchCmdForCompiler="""select %s from %s
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200219 INNER JOIN CATEGORY USING(categoryid)
220 INNER JOIN PLATFORM USING(platformid)
221 INNER JOIN CORE USING(coreid)
222 INNER JOIN COMPILER USING(compilerid)
223 INNER JOIN COMPILERKIND USING(compilerkindid)
224 INNER JOIN TYPE USING(typeid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200225 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon670b1672020-05-28 12:47:58 +0200226 WHERE compilerid=? AND typeid = ? AND %s
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200227 """
228
229# Command to get test names for specific compiler
230# and type
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200231benchNamesForCore="""select distinct ID,name from %s
232 INNER JOIN COMPILER USING(compilerid)
233 INNER JOIN COMPILERKIND USING(compilerkindid)
234 INNER JOIN TYPE USING(typeid)
235 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon670b1672020-05-28 12:47:58 +0200236 WHERE coreid=? AND typeid = ? AND %s
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200237 """
238# Command to get test names for specific compiler
239# and type
240benchNamesForCompiler="""select distinct ID,name from %s
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200241 INNER JOIN COMPILER USING(compilerid)
242 INNER JOIN COMPILERKIND USING(compilerkindid)
243 INNER JOIN TYPE USING(typeid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200244 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon670b1672020-05-28 12:47:58 +0200245 WHERE compilerid=? AND typeid = ? AND %s
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200246 """
247
248# Command to get columns for specific table
249benchCmdColumns="""select * from %s
250 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)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200255 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200256 INNER JOIN TYPE USING(typeid)
257 """
258
259def joinit(iterable, delimiter):
260 it = iter(iterable)
261 yield next(it)
262 for x in it:
263 yield delimiter
264 yield x
265
266# Is not a column name finishing by id
267# (often primary key for thetable)
268def isNotIDColumn(col):
269 if re.match(r'^.*id$',col):
270 return(False)
271 else:
272 return(True)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200273
274# Get test names
275# for specific typeid and core (for the data)
276def getTestNamesForCore(benchTable,core,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200277 vals=(core,typeid) + runidval
278 result=c.execute(benchNamesForCore % (benchTable,runidCMD),vals).fetchall()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200279 names=[(x[0],x[1]) for x in list(result)]
280 return(names)
281
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200282# Get test names
283# for specific typeid and compiler (for the data)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200284def getTestNamesForCompiler(benchTable,comp,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200285 vals=(comp,typeid) + runidval
286 result=c.execute(benchNamesForCompiler % (benchTable,runidCMD),vals).fetchall()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200287 names=[(x[0],x[1]) for x in list(result)]
288 return(names)
289
290# Command to get data for specific core
291# and type
292nbElemsInBenchAndTypeAndCoreCmd="""select count(*) from %s
Christophe Favergeon670b1672020-05-28 12:47:58 +0200293 WHERE coreid=? AND typeid = ? AND %s
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200294 """
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200295
Christophe Favergeone15894e2020-05-14 07:25:53 +0200296# Command to get data for specific compiler
297# and type
298nbElemsInBenchAndTypeAndCompilerCmd="""select count(*) from %s
Christophe Favergeon670b1672020-05-28 12:47:58 +0200299 WHERE compilerid=? AND typeid = ? AND %s
Christophe Favergeone15894e2020-05-14 07:25:53 +0200300 """
301
302nbElemsInBenchAndTypeCmd="""select count(*) from %s
Christophe Favergeon670b1672020-05-28 12:47:58 +0200303 WHERE typeid = ? AND %s
Christophe Favergeone15894e2020-05-14 07:25:53 +0200304 """
305
306nbElemsInBenchCmd="""select count(*) from %s
Christophe Favergeon670b1672020-05-28 12:47:58 +0200307 WHERE %s
Christophe Favergeone15894e2020-05-14 07:25:53 +0200308 """
309
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200310categoryName="""select distinct category from %s
311 INNER JOIN CATEGORY USING(categoryid)
Christophe Favergeon670b1672020-05-28 12:47:58 +0200312 WHERE %s
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200313 """
314
315def getCategoryName(benchTable,runid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200316 result=c.execute(categoryName % (benchTable,runidCMD),runidval).fetchone()
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200317 return(result[0])
318
Christophe Favergeon4f750702020-05-13 15:56:15 +0200319# Get nb elems in a table
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200320def getNbElemsInBenchAndTypeAndCoreCmd(benchTable,coreid,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200321 vals=(coreid,typeid) + runidval
322 result=c.execute(nbElemsInBenchAndTypeAndCoreCmd % (benchTable,runidCMD),vals).fetchone()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200323 return(result[0])
324
325# Get nb elems in a table
Christophe Favergeone15894e2020-05-14 07:25:53 +0200326def getNbElemsInBenchAndTypeAndCompilerCmd(benchTable,comp,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200327 vals=(comp,typeid) + runidval
328 result=c.execute(nbElemsInBenchAndTypeAndCompilerCmd % (benchTable,runidCMD),vals).fetchone()
Christophe Favergeone15894e2020-05-14 07:25:53 +0200329 return(result[0])
330
331def getNbElemsInBenchAndTypeCmd(benchTable,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200332 vals=(typeid,) + runidval
333 result=c.execute(nbElemsInBenchAndTypeCmd % (benchTable,runidCMD),vals).fetchone()
Christophe Favergeone15894e2020-05-14 07:25:53 +0200334 return(result[0])
335
336def getNbElemsInBenchCmd(benchTable):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200337 result=c.execute(nbElemsInBenchCmd % (benchTable,runidCMD),runidval).fetchone()
Christophe Favergeon4f750702020-05-13 15:56:15 +0200338 return(result[0])
339
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200340# Get names of columns and data for a table
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200341# for specific typeid and coreid (for the data)
342def getColNamesAndHistory(benchTable,compiler,core,typeid,testid):
343 cursor=c.cursor()
344 result=cursor.execute(benchCmdColumns % (benchTable))
345 cols= [member[0] for member in cursor.description]
346 keepCols = ['name','runid'] + [c for c in diff(cols , REMOVECOLUMNSFORHISTORY) if isNotIDColumn(c)]
347 keepColsStr = "".join(joinit(keepCols,","))
348 vals=(compiler,core,typeid,testid,runid)
349 result=cursor.execute(historyCmd % (keepColsStr,benchTable),vals)
350 vals =np.array([list(x) for x in list(result)])
351 return(keepCols,vals)
352
353# Get names of columns and data for a table
354# for specific typeid and coreid (for the data)
355def getColNamesAndDataForCore(benchTable,core,typeid):
356 cursor=c.cursor()
357 result=cursor.execute(benchCmdColumns % (benchTable))
358 cols= [member[0] for member in cursor.description]
359 keepCols = ['name'] + [c for c in diff(cols , REMOVECOLUMNS) if isNotIDColumn(c)]
360 keepColsStr = "".join(joinit(keepCols,","))
Christophe Favergeon670b1672020-05-28 12:47:58 +0200361 vals=(core,typeid) + runidval
362 result=cursor.execute(benchCmdForCore % (keepColsStr,benchTable,runidCMD),vals)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200363 vals =np.array([list(x) for x in list(result)])
364 return(keepCols,vals)
365
366
367# Get names of columns and data for a table
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200368# for specific typeid and compiler (for the data)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200369def getColNamesAndDataForCompiler(benchTable,comp,typeid):
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200370 cursor=c.cursor()
371 result=cursor.execute(benchCmdColumns % (benchTable))
372 cols= [member[0] for member in cursor.description]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200373 keepCols = ['name'] + [c for c in diff(cols , REMOVECOLUMNS) if isNotIDColumn(c)]
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200374 keepColsStr = "".join(joinit(keepCols,","))
Christophe Favergeon670b1672020-05-28 12:47:58 +0200375 vals=(comp,typeid) + runidval
376 result=cursor.execute(benchCmdForCompiler % (keepColsStr,benchTable,runidCMD),vals)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200377 vals =np.array([list(x) for x in list(result)])
378 return(keepCols,vals)
379
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200380
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200381
382PARAMS=["NB","NumTaps", "NBA", "NBB", "Factor", "NumStages","VECDIM","NBR","NBC","NBI","IFFT", "BITREV"]
383
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200384def regressionTableFor(byname,name,section,ref,toSort,indexCols,field):
385 data=ref.pivot_table(index=indexCols, columns=byname,
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200386 values=[field], aggfunc='first')
387
388 data=data.sort_values(toSort)
389
390 cores = [c[1] for c in list(data.columns)]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200391 columns = diff(indexCols,['name'])
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200392
Christophe Favergeon34d313a2020-05-14 15:09:41 +0200393 dataTable=Table(columns,cores)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200394 section.addContent(dataTable)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200395
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200396 dataForFunc=data.loc[name]
397 if type(dataForFunc) is pd.DataFrame:
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200398 bars={'cols':columns,'cores':cores,'data':[]}
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200399 for row in dataForFunc.itertuples():
400 row=list(row)
401 if type(row[0]) is int:
402 row=[row[0]] + row[1:]
403 else:
404 row=list(row[0]) + row[1:]
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200405 if field=="MAXREGCOEF":
Christophe Favergeon670b1672020-05-28 12:47:58 +0200406 newrow = row
407 newrow[len(columns):] = [("%.3f" % x) for x in row[len(columns):]]
408 row=newrow
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200409 dataTable.addRow(row)
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200410 bars['data'].append(row)
411 return(bars)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200412 else:
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200413 if field=="MAXREGCOEF":
414 dataForFunc=[("%.3f" % x) for x in dataForFunc]
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200415 dataTable.addRow(dataForFunc)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200416 return(list(zip(cores,dataForFunc)))
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200417
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200418def formatColumnName(c):
419 return("".join(joinit(c,":")))
420
421def getCoresForHistory(benchTable,compilerid,typeid,testid,runid):
422 vals=(compilerid,typeid,testid,runid)
423 result=c.execute(coresForHistory % benchTable,vals).fetchall()
424 ids=[(x[0],x[1]) for x in list(result)]
425 return(ids)
426
427def getCompilerForHistory(benchTable,coreid,typeid,testid,runid):
428 vals=(coreid,typeid,testid,runid)
429 result=c.execute(compilersForHistory % benchTable,vals).fetchall()
430 ids=[(x[0],x[1],x[2]) for x in list(result)]
431 return(ids)
432
433def getHistory(desc,testid,indexCols):
434 benchName,sectionID,typeid,runid = desc
435
436 #print(benchName)
437 #print(sectionID)
438 #print(typeid)
439 #print(testid)
440 columns = diff(indexCols,['name'])
441 #print(columns)
442 if args.byc:
443 coreid=sectionID
444 compilerids=getCompilerForHistory(benchName,coreid,typeid,testid,runid)
445 series={}
446 for compilerid,compilername,version in compilerids:
447 result=getColNamesAndHistory(benchName,compilerid,coreid,typeid,testid)
448 #print("%s:%s" % (compilername,version))
449 maxpos = result[0].index('MAX')
450 lrunid = result[0].index('runid')
451 r=[[int(x[lrunid]),int(x[maxpos])] for x in result[1:][0]]
452 series[corename]=r
453 hist=History(series,runid)
454 return(hist)
455 else:
456 compilerid=sectionID
457 coreids = getCoresForHistory(benchName,compilerid,typeid,testid,runid)
458 series={}
459 for coreid,corename in coreids:
460 result=getColNamesAndHistory(benchName,compilerid,coreid,typeid,testid)
461 #print(corename)
462 maxpos = result[0].index('MAX')
463 corepos = result[0].index('core')
464 lrunid = result[0].index('runid')
465 r=[[int(x[lrunid]),int(x[maxpos])] for x in result[1:][0]]
466 series[corename]=r
467 hist=History(series,runid)
468 return(hist)
469
470def formatTableBy(desc,byname,section,typeSection,testNames,cols,vals):
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200471 if vals.size != 0:
472 ref=pd.DataFrame(vals,columns=cols)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200473 toSort=["name"]
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200474
475 for param in PARAMS:
476 if param in ref.columns:
477 ref[param]=pd.to_numeric(ref[param])
478 toSort.append(param)
479 if args.r:
480 # Regression table
481 ref['MAX']=pd.to_numeric(ref['MAX'])
482 ref['MAXREGCOEF']=pd.to_numeric(ref['MAXREGCOEF'])
483
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200484 indexCols=diff(cols,byname + ['Regression','MAXREGCOEF','MAX'] + section)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200485 valList = ['Regression']
486 else:
487 ref['CYCLES']=pd.to_numeric(ref['CYCLES'])
488
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200489 indexCols=diff(cols,byname + ['CYCLES'] + section)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200490 valList = ['CYCLES']
491
492
493
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200494 for testid,name in testNames:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200495 if args.r:
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200496 testSection = Section(name)
497 typeSection.addSection(testSection)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200498
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200499 maxCyclesSection = Section("Max cycles")
500 testSection.addSection(maxCyclesSection)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200501 theCycles=regressionTableFor(byname,name,maxCyclesSection,ref,toSort,indexCols,'MAX')
Christophe Favergeon670b1672020-05-28 12:47:58 +0200502 if args.g:
503 if type(theCycles) is dict:
504 nbParams=len(theCycles['cols'])
505 for bar in theCycles['data']:
506 params=bar[0:nbParams]
507 values=bar[nbParams:]
508 title=[("%s=%s" % x) for x in list(zip(theCycles['cols'],params))]
509 title="".join(joinit(title," "))
510 sec=Section(title)
511 maxCyclesSection.addSection(sec)
512 values=list(zip(theCycles['cores'],values))
513 barChart=BarChart(values)
514 sec.addContent(barChart)
515 else:
516 #print(theCycles)
517 sec=Section("Graph")
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200518 maxCyclesSection.addSection(sec)
Christophe Favergeon670b1672020-05-28 12:47:58 +0200519 barChart=BarChart(theCycles)
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200520 sec.addContent(barChart)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200521
Christophe Favergeon670b1672020-05-28 12:47:58 +0200522 #history=getHistory(desc,testid,indexCols)
523 #testSection.addContent(history)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200524
525 regressionSection = Section("Regression")
526 testSection.addSection(regressionSection)
527 regressionTableFor(byname,name,regressionSection,ref,toSort,indexCols,'Regression')
528
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200529
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200530 maxRegCoefSection = Section("Max Reg Coef")
531 testSection.addSection(maxRegCoefSection)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200532 regressionTableFor(byname,name,maxRegCoefSection,ref,toSort,indexCols,'MAXREGCOEF')
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200533
534 else:
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200535 data=ref.pivot_table(index=indexCols, columns=byname,
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200536 values=valList, aggfunc='first')
537
538 data=data.sort_values(toSort)
539
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200540 #print(list(data.columns))
541 columnsID = [formatColumnName(c[1:]) for c in list(data.columns)]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200542 columns = diff(indexCols,['name'])
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200543
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200544 testSection = Section(name)
545 typeSection.addSection(testSection)
546
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200547 dataTable=Table(columns,columnsID)
548 testSection.addContent(dataTable)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200549
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200550 dataForFunc=data.loc[name]
551 if type(dataForFunc) is pd.DataFrame:
552 for row in dataForFunc.itertuples():
553 row=list(row)
554 if type(row[0]) is int:
555 row=[row[0]] + row[1:]
556 else:
557 row=list(row[0]) + row[1:]
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200558 dataTable.addRow(row)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200559 else:
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200560 dataTable.addRow(dataForFunc)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200561
562# Add a report for each table
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200563def addReportFor(document,runid,benchName):
Christophe Favergeone15894e2020-05-14 07:25:53 +0200564 nbElems = getNbElemsInBenchCmd(benchName)
565 if nbElems > 0:
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200566 categoryName = getCategoryName(benchName,runid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200567 benchSection = Section(categoryName)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200568 document.addSection(benchSection)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200569 print("Process %s\n" % benchName)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200570 allTypes = getExistingTypes(benchName)
571 # Add report for each type
572 for aTypeID in allTypes:
573 nbElems = getNbElemsInBenchAndTypeCmd(benchName,aTypeID)
574 if nbElems > 0:
575 typeName = getTypeName(aTypeID)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200576 typeSection = Section(typeName)
577 benchSection.addSection(typeSection)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200578 if args.byc:
579 ## Add report for each core
580 allCores = getExistingCores(benchName,aTypeID)
581 for core in allCores:
582 #print(core)
583 nbElems = getNbElemsInBenchAndTypeAndCoreCmd(benchName,core,aTypeID)
584 # Print test results for table, type, compiler
585 if nbElems > 0:
586 coreName=getCoreDesc(core)
587 coreSection = Section("%s" % coreName)
588 typeSection.addSection(coreSection)
589 cols,vals=getColNamesAndDataForCore(benchName,core,aTypeID)
590 desc=(benchName,core,aTypeID,runid)
591 names=getTestNamesForCore(benchName,core,aTypeID)
592 formatTableBy(desc,['compiler','version'],['core'],coreSection,names,cols,vals)
593 else:
594 ## Add report for each compiler
595 allCompilers = getExistingCompiler(benchName,aTypeID)
596 for compiler in allCompilers:
597 #print(compiler)
598 nbElems = getNbElemsInBenchAndTypeAndCompilerCmd(benchName,compiler,aTypeID)
599 # Print test results for table, type, compiler
600 if nbElems > 0:
601 compilerName,version=getCompilerDesc(compiler)
602 compilerSection = Section("%s (%s)" % (compilerName,version))
603 typeSection.addSection(compilerSection)
604 cols,vals=getColNamesAndDataForCompiler(benchName,compiler,aTypeID)
605 desc=(benchName,compiler,aTypeID,runid)
606 names=getTestNamesForCompiler(benchName,compiler,aTypeID)
607 formatTableBy(desc,['core'],['version','compiler'],compilerSection,names,cols,vals)
608
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200609
610
611
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200612toc=[Hierarchy("BasicMathsBenchmarks"),
613Hierarchy("ComplexMathsBenchmarks"),
614Hierarchy("FastMath"),
615Hierarchy("Filters",
616 [Hierarchy("FIR"),
617 Hierarchy("BIQUAD"),
618 Hierarchy("DECIM"),
619 Hierarchy("MISC")]),
620
621Hierarchy("Support Functions",
622 [Hierarchy("Support"),
623 Hierarchy("SupportBar")]),
624
625Hierarchy("Matrix Operations" ,
626 [Hierarchy("Binary"),
627 Hierarchy("Unary")]),
628Hierarchy("Transform"),
629
630]
631
632processed=[]
633
Christophe Favergeon66de4ac2020-07-31 13:38:09 +0200634def addComments(document):
635 if os.path.exists(args.comments):
636 section=Section("Measurement Context")
637
638 document.addSection(section)
639 para=""
640 with open(args.comments,"r") as r:
641 for l in r:
642 if l.strip():
643 para += l
644 else:
645 section.addContent(Text(para))
646 para=""
647 if para:
648 section.addContent(Text(para))
649
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200650def createDoc(document,sections,benchtables):
651 global processed
652 for s in sections:
653 if s.name in benchtables:
654 addReportFor(document,runid,s.name)
655 processed.append(s.name)
656 else:
657 section=Section(s.name)
658 document.addSection(section)
659 createDoc(section,s.sections,benchtables)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200660
661try:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200662 benchtables=getBenchTables()
Christophe Favergeone15894e2020-05-14 07:25:53 +0200663 theDate = getrunIDDate(runid)
Christophe Favergeon66de4ac2020-07-31 13:38:09 +0200664 document = Document(runidHeader)
665
666 addComments(document)
667
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200668 createDoc(document,toc,benchtables)
Christophe Favergeon66de4ac2020-07-31 13:38:09 +0200669
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200670 misc=Section("Miscellaneous")
671 document.addSection(misc)
672 remaining=diff(benchtables,processed)
673 for bench in remaining:
674 addReportFor(misc,runid,bench)
675
676 #for bench in benchtables:
677 # addReportFor(document,bench)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200678 with open(args.o,"w") as output:
679 if args.t=="md":
680 document.accept(Markdown(output))
681 if args.t=="html":
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200682 document.accept(HTML(output,args.r))
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200683
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200684finally:
685 c.close()
686
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200687
688
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200689