blob: dcce85daad54a7e6f528350bc15347145995b446 [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 Favergeonc3f455c2020-05-14 09:24:07 +02008
Christophe Favergeonc3f455c2020-05-14 09:24:07 +02009
10
11
12
13
Christophe Favergeon8cb37302020-05-13 13:06:58 +020014# Command to get last runid
15lastID="""SELECT runid FROM RUN ORDER BY runid DESC LIMIT 1
16"""
17
Christophe Favergeone15894e2020-05-14 07:25:53 +020018# Command to get last runid and date
19lastIDAndDate="""SELECT date FROM RUN WHERE runid=?
20"""
21
Christophe Favergeon8cb37302020-05-13 13:06:58 +020022def getLastRunID():
23 r=c.execute(lastID)
24 return(int(r.fetchone()[0]))
25
Christophe Favergeone15894e2020-05-14 07:25:53 +020026def getrunIDDate(forID):
27 r=c.execute(lastIDAndDate,(forID,))
28 return(r.fetchone()[0])
Christophe Favergeon8cb37302020-05-13 13:06:58 +020029
30runid = 1
31
32parser = argparse.ArgumentParser(description='Generate summary benchmarks')
33
34parser.add_argument('-b', nargs='?',type = str, default="bench.db", help="Benchmark database")
35parser.add_argument('-o', nargs='?',type = str, default="full.md", help="Full summary")
36parser.add_argument('-r', action='store_true', help="Regression database")
Christophe Favergeonc3f455c2020-05-14 09:24:07 +020037parser.add_argument('-t', nargs='?',type = str, default="md", help="md,html")
Christophe Favergeon8cb37302020-05-13 13:06:58 +020038
39# For runid or runid range
Christophe Favergeon4fa1e232020-05-15 12:28:17 +020040parser.add_argument('others', nargs=argparse.REMAINDER,help="Run ID")
Christophe Favergeon8cb37302020-05-13 13:06:58 +020041
42args = parser.parse_args()
43
44c = sqlite3.connect(args.b)
45
46if args.others:
47 runid=int(args.others[0])
48else:
49 runid=getLastRunID()
50
51# We extract data only from data tables
52# Those tables below are used for descriptions
Christophe Favergeon4fa1e232020-05-15 12:28:17 +020053REMOVETABLES=['TESTNAME','TESTDATE','RUN','CORE', 'PLATFORM', 'COMPILERKIND', 'COMPILER', 'TYPE', 'CATEGORY', 'CONFIG']
Christophe Favergeon8cb37302020-05-13 13:06:58 +020054
55# This is assuming the database is generated by the regression script
56# So platform is the same for all benchmarks.
57# Category and type is coming from the test name in the yaml
58# So no need to add this information here
59# Name is removed here because it is added at the beginning
Christophe Favergeon4fa1e232020-05-15 12:28:17 +020060REMOVECOLUMNS=['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 +020061
62# Get existing benchmark tables
63def getBenchTables():
64 r=c.execute("SELECT name FROM sqlite_master WHERE type='table'")
65 benchtables=[]
66 for table in r:
67 if not table[0] in REMOVETABLES:
68 benchtables.append(table[0])
69 return(benchtables)
70
71# get existing types in a table
72def getExistingTypes(benchTable):
Christophe Favergeone15894e2020-05-14 07:25:53 +020073 r=c.execute("select distinct typeid from %s order by typeid desc" % benchTable).fetchall()
Christophe Favergeon8cb37302020-05-13 13:06:58 +020074 result=[x[0] for x in r]
75 return(result)
76
77# Get compilers from specific type and table
Christophe Favergeon4fa1e232020-05-15 12:28:17 +020078allCompilers="""select distinct compilerid from %s WHERE typeid=?"""
79
80compilerDesc="""select compiler,version from COMPILER
81 INNER JOIN COMPILERKIND USING(compilerkindid) WHERE compilerid=?"""
Christophe Favergeon8cb37302020-05-13 13:06:58 +020082
83# Get existing compiler in a table for a specific type
84# (In case report is structured by types)
85def getExistingCompiler(benchTable,typeid):
Christophe Favergeon4fa1e232020-05-15 12:28:17 +020086 r=c.execute(allCompilers % benchTable,(typeid,)).fetchall()
87 return([x[0] for x in r])
88
89def getCompilerDesc(compilerid):
90 r=c.execute(compilerDesc,(compilerid,)).fetchone()
Christophe Favergeon8cb37302020-05-13 13:06:58 +020091 return(r)
92
93# Get type name from type id
94def getTypeName(typeid):
95 r=c.execute("select type from TYPE where typeid=?",(typeid,)).fetchone()
96 return(r[0])
97
98# Diff of 2 lists
99def diff(first, second):
100 second = set(second)
101 return [item for item in first if item not in second]
102
103
104# Command to get data for specific compiler
105# and type
106benchCmd="""select %s from %s
107 INNER JOIN CATEGORY USING(categoryid)
108 INNER JOIN PLATFORM USING(platformid)
109 INNER JOIN CORE USING(coreid)
110 INNER JOIN COMPILER USING(compilerid)
111 INNER JOIN COMPILERKIND USING(compilerkindid)
112 INNER JOIN TYPE USING(typeid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200113 INNER JOIN TESTNAME USING(testnameid)
114 WHERE compilerid=? AND typeid = ? AND runid = ?
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200115 """
116
Christophe Favergeon4f750702020-05-13 15:56:15 +0200117
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200118# Command to get test names for specific compiler
119# and type
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200120benchNames="""select distinct name from %s
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200121 INNER JOIN COMPILER USING(compilerid)
122 INNER JOIN COMPILERKIND USING(compilerkindid)
123 INNER JOIN TYPE USING(typeid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200124 INNER JOIN TESTNAME USING(testnameid)
125 WHERE compilerid=? AND typeid = ? AND runid = ?
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200126 """
127
128# Command to get columns for specific table
129benchCmdColumns="""select * from %s
130 INNER JOIN CATEGORY USING(categoryid)
131 INNER JOIN PLATFORM USING(platformid)
132 INNER JOIN CORE USING(coreid)
133 INNER JOIN COMPILER USING(compilerid)
134 INNER JOIN COMPILERKIND USING(compilerkindid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200135 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200136 INNER JOIN TYPE USING(typeid)
137 """
138
139def joinit(iterable, delimiter):
140 it = iter(iterable)
141 yield next(it)
142 for x in it:
143 yield delimiter
144 yield x
145
146# Is not a column name finishing by id
147# (often primary key for thetable)
148def isNotIDColumn(col):
149 if re.match(r'^.*id$',col):
150 return(False)
151 else:
152 return(True)
153
154# Get test names
155# for specific typeid and compiler (for the data)
156def getTestNames(benchTable,comp,typeid):
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200157 vals=(comp,typeid,runid)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200158 result=c.execute(benchNames % benchTable,vals).fetchall()
159 return([x[0] for x in list(result)])
160
Christophe Favergeone15894e2020-05-14 07:25:53 +0200161# Command to get data for specific compiler
162# and type
163nbElemsInBenchAndTypeAndCompilerCmd="""select count(*) from %s
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200164 WHERE compilerid=? AND typeid = ? AND runid = ?
Christophe Favergeone15894e2020-05-14 07:25:53 +0200165 """
166
167nbElemsInBenchAndTypeCmd="""select count(*) from %s
Christophe Favergeone15894e2020-05-14 07:25:53 +0200168 WHERE typeid = ? AND runid = ?
169 """
170
171nbElemsInBenchCmd="""select count(*) from %s
Christophe Favergeone15894e2020-05-14 07:25:53 +0200172 WHERE runid = ?
173 """
174
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200175categoryName="""select distinct category from %s
176 INNER JOIN CATEGORY USING(categoryid)
177 WHERE runid = ?
178 """
179
180def getCategoryName(benchTable,runid):
181 result=c.execute(categoryName % benchTable,(runid,)).fetchone()
182 return(result[0])
183
Christophe Favergeon4f750702020-05-13 15:56:15 +0200184# Get nb elems in a table
Christophe Favergeone15894e2020-05-14 07:25:53 +0200185def getNbElemsInBenchAndTypeAndCompilerCmd(benchTable,comp,typeid):
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200186 vals=(comp,typeid,runid)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200187 result=c.execute(nbElemsInBenchAndTypeAndCompilerCmd % benchTable,vals).fetchone()
188 return(result[0])
189
190def getNbElemsInBenchAndTypeCmd(benchTable,typeid):
191 vals=(typeid,runid)
192 result=c.execute(nbElemsInBenchAndTypeCmd % benchTable,vals).fetchone()
193 return(result[0])
194
195def getNbElemsInBenchCmd(benchTable):
196 vals=(runid,)
197 result=c.execute(nbElemsInBenchCmd % benchTable,vals).fetchone()
Christophe Favergeon4f750702020-05-13 15:56:15 +0200198 return(result[0])
199
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200200# Get names of columns and data for a table
201# for specific typeid and compiler (for the data)
202def getColNamesAndData(benchTable,comp,typeid):
203 cursor=c.cursor()
204 result=cursor.execute(benchCmdColumns % (benchTable))
205 cols= [member[0] for member in cursor.description]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200206 keepCols = ['name'] + [c for c in diff(cols , REMOVECOLUMNS) if isNotIDColumn(c)]
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200207 keepColsStr = "".join(joinit(keepCols,","))
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200208 vals=(comp,typeid,runid)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200209 result=cursor.execute(benchCmd % (keepColsStr,benchTable),vals)
210 vals =np.array([list(x) for x in list(result)])
211 return(keepCols,vals)
212
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200213
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200214
215PARAMS=["NB","NumTaps", "NBA", "NBB", "Factor", "NumStages","VECDIM","NBR","NBC","NBI","IFFT", "BITREV"]
216
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200217def regressionTableFor(name,section,ref,toSort,indexCols,field):
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200218 data=ref.pivot_table(index=indexCols, columns='core',
219 values=[field], aggfunc='first')
220
221 data=data.sort_values(toSort)
222
223 cores = [c[1] for c in list(data.columns)]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200224 columns = diff(indexCols,['name'])
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200225
Christophe Favergeon34d313a2020-05-14 15:09:41 +0200226 dataTable=Table(columns,cores)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200227 section.addTable(dataTable)
228
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200229 dataForFunc=data.loc[name]
230 if type(dataForFunc) is pd.DataFrame:
231 for row in dataForFunc.itertuples():
232 row=list(row)
233 if type(row[0]) is int:
234 row=[row[0]] + row[1:]
235 else:
236 row=list(row[0]) + row[1:]
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200237 if field=="MAXREGCOEF":
238 row=[("%.3f" % x) for x in row]
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200239 dataTable.addRow(row)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200240 else:
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200241 if field=="MAXREGCOEF":
242 dataForFunc=[("%.3f" % x) for x in dataForFunc]
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200243 dataTable.addRow(dataForFunc)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200244
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200245def formatTableByCore(typeSection,testNames,cols,vals):
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200246 if vals.size != 0:
247 ref=pd.DataFrame(vals,columns=cols)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200248 toSort=["name"]
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200249
250 for param in PARAMS:
251 if param in ref.columns:
252 ref[param]=pd.to_numeric(ref[param])
253 toSort.append(param)
254 if args.r:
255 # Regression table
256 ref['MAX']=pd.to_numeric(ref['MAX'])
257 ref['MAXREGCOEF']=pd.to_numeric(ref['MAXREGCOEF'])
258
259 indexCols=diff(cols,['core','Regression','MAXREGCOEF','MAX','version','compiler'])
260 valList = ['Regression']
261 else:
262 ref['CYCLES']=pd.to_numeric(ref['CYCLES'])
263
264 indexCols=diff(cols,['core','CYCLES','version','compiler'])
265 valList = ['CYCLES']
266
267
268
269 for name in testNames:
270 if args.r:
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200271 testSection = Section(name)
272 typeSection.addSection(testSection)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200273
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200274 regressionSection = Section("Regression")
275 testSection.addSection(regressionSection)
276 regressionTableFor(name,regressionSection,ref,toSort,indexCols,'Regression')
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200277
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200278 maxCyclesSection = Section("Max cycles")
279 testSection.addSection(maxCyclesSection)
280 regressionTableFor(name,maxCyclesSection,ref,toSort,indexCols,'MAX')
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200281
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200282 maxRegCoefSection = Section("Max Reg Coef")
283 testSection.addSection(maxRegCoefSection)
284 regressionTableFor(name,maxRegCoefSection,ref,toSort,indexCols,'MAXREGCOEF')
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200285
286 else:
287 data=ref.pivot_table(index=indexCols, columns='core',
288 values=valList, aggfunc='first')
289
290 data=data.sort_values(toSort)
291
292 cores = [c[1] for c in list(data.columns)]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200293 columns = diff(indexCols,['name'])
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200294
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200295 testSection = Section(name)
296 typeSection.addSection(testSection)
297
Christophe Favergeon34d313a2020-05-14 15:09:41 +0200298 dataTable=Table(columns,cores)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200299 testSection.addTable(dataTable)
300
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200301 dataForFunc=data.loc[name]
302 if type(dataForFunc) is pd.DataFrame:
303 for row in dataForFunc.itertuples():
304 row=list(row)
305 if type(row[0]) is int:
306 row=[row[0]] + row[1:]
307 else:
308 row=list(row[0]) + row[1:]
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200309 dataTable.addRow(row)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200310 else:
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200311 dataTable.addRow(dataForFunc)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200312
313# Add a report for each table
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200314def addReportFor(document,runid,benchName):
Christophe Favergeone15894e2020-05-14 07:25:53 +0200315 nbElems = getNbElemsInBenchCmd(benchName)
316 if nbElems > 0:
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200317 categoryName = getCategoryName(benchName,runid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200318 benchSection = Section(categoryName)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200319 document.addSection(benchSection)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200320 print("Process %s\n" % benchName)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200321 allTypes = getExistingTypes(benchName)
322 # Add report for each type
323 for aTypeID in allTypes:
324 nbElems = getNbElemsInBenchAndTypeCmd(benchName,aTypeID)
325 if nbElems > 0:
326 typeName = getTypeName(aTypeID)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200327 typeSection = Section(typeName)
328 benchSection.addSection(typeSection)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200329 ## Add report for each compiler
330 allCompilers = getExistingCompiler(benchName,aTypeID)
331 for compiler in allCompilers:
332 #print(compiler)
333 nbElems = getNbElemsInBenchAndTypeAndCompilerCmd(benchName,compiler,aTypeID)
334 # Print test results for table, type, compiler
335 if nbElems > 0:
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200336 compilerName,version=getCompilerDesc(compiler)
337 compilerSection = Section("%s (%s)" % (compilerName,version))
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200338 typeSection.addSection(compilerSection)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200339 cols,vals=getColNamesAndData(benchName,compiler,aTypeID)
340 names=getTestNames(benchName,compiler,aTypeID)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200341 formatTableByCore(compilerSection,names,cols,vals)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200342
343
344
345
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200346toc=[Hierarchy("BasicMathsBenchmarks"),
347Hierarchy("ComplexMathsBenchmarks"),
348Hierarchy("FastMath"),
349Hierarchy("Filters",
350 [Hierarchy("FIR"),
351 Hierarchy("BIQUAD"),
352 Hierarchy("DECIM"),
353 Hierarchy("MISC")]),
354
355Hierarchy("Support Functions",
356 [Hierarchy("Support"),
357 Hierarchy("SupportBar")]),
358
359Hierarchy("Matrix Operations" ,
360 [Hierarchy("Binary"),
361 Hierarchy("Unary")]),
362Hierarchy("Transform"),
363
364]
365
366processed=[]
367
368def createDoc(document,sections,benchtables):
369 global processed
370 for s in sections:
371 if s.name in benchtables:
372 addReportFor(document,runid,s.name)
373 processed.append(s.name)
374 else:
375 section=Section(s.name)
376 document.addSection(section)
377 createDoc(section,s.sections,benchtables)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200378
379try:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200380 benchtables=getBenchTables()
Christophe Favergeone15894e2020-05-14 07:25:53 +0200381 theDate = getrunIDDate(runid)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200382 document = Document(runid,theDate)
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200383 createDoc(document,toc,benchtables)
384 misc=Section("Miscellaneous")
385 document.addSection(misc)
386 remaining=diff(benchtables,processed)
387 for bench in remaining:
388 addReportFor(misc,runid,bench)
389
390 #for bench in benchtables:
391 # addReportFor(document,bench)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200392 with open(args.o,"w") as output:
393 if args.t=="md":
394 document.accept(Markdown(output))
395 if args.t=="html":
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200396 document.accept(HTML(output,args.r))
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200397
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200398finally:
399 c.close()
400
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200401
402
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200403