blob: 3b9daaffe548e53cb65eb56422b6a1f0824eaeb6 [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 Favergeonfe27d872020-07-31 07:20:18 +020058
Christophe Favergeon8cb37302020-05-13 13:06:58 +020059# For runid or runid range
Christophe Favergeon4fa1e232020-05-15 12:28:17 +020060parser.add_argument('others', nargs=argparse.REMAINDER,help="Run ID")
Christophe Favergeon8cb37302020-05-13 13:06:58 +020061
62args = parser.parse_args()
63
64c = sqlite3.connect(args.b)
65
66if args.others:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +020067 vals=[]
68 runidCMD=[]
69 runidHeader=[]
70 for t in args.others:
71 if re.search(r'-',t):
72 bounds=[int(x) for x in t.split("-")]
73 vals += bounds
74 runidHeader += ["%d <= runid <= %d" % tuple(bounds)]
75 runidCMD += ["(runid >= ? AND runid <= ?)"]
76 else:
77 theid=int(t)
78 runidHeader += ["runid == %d" % theid]
79 runidCMD += ["runid == ?"]
80 vals.append(theid)
81
82 runidval = tuple(vals)
83 runidHeader = "".join(joinit(runidHeader," OR "))
84 runidCMD = "".join(joinit(runidCMD," OR "))
Christophe Favergeon8cb37302020-05-13 13:06:58 +020085else:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +020086 theid=getLastRunID()
87 print("Last run ID = %d\n" % theid)
88 runidval=(theid,)
89 runidHeader="%d" % theid
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 Favergeon6ef1bb22020-08-14 12:07:47 +0200116 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 +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
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200140allCores="""select distinct coreid from %s WHERE typeid=? AND (%s)"""
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200141
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):
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200155 vals = (typeid,) + runidval
156 r=c.execute(allCores % (benchTable,runidCMD),vals).fetchall()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200157 return([x[0] for x in r])
158
159
160
161def getCoreDesc(compilerid):
162 r=c.execute(coreDesc,(compilerid,)).fetchone()
163 return(r)
164
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200165def getCompilerDesc(compilerid):
166 r=c.execute(compilerDesc,(compilerid,)).fetchone()
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200167 return(r)
168
169# Get type name from type id
170def getTypeName(typeid):
171 r=c.execute("select type from TYPE where typeid=?",(typeid,)).fetchone()
172 return(r[0])
173
174# Diff of 2 lists
175def diff(first, second):
176 second = set(second)
177 return [item for item in first if item not in second]
178
179
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200180# Command to get data for specific core
181# and type
182historyCmd="""select %s from %s
183 INNER JOIN CATEGORY USING(categoryid)
184 INNER JOIN PLATFORM USING(platformid)
185 INNER JOIN CORE USING(coreid)
186 INNER JOIN COMPILER USING(compilerid)
187 INNER JOIN COMPILERKIND USING(compilerkindid)
188 INNER JOIN TYPE USING(typeid)
189 INNER JOIN TESTNAME USING(testnameid)
190 WHERE compilerid=? AND coreid=? AND typeid = ? AND ID = ? AND runid > (? - 10)
191 """
192
193compilersForHistory="""select distinct compilerid,compiler,version from %s
194 INNER JOIN COMPILER USING(compilerid)
195 INNER JOIN COMPILERKIND USING(compilerkindid)
196 WHERE coreid=? AND typeid = ? AND ID = ? AND runid > (? - 10)
197 """
198
199# Command to get data for specific core
200# and type
201benchCmdForCore="""select %s from %s
202 INNER JOIN CATEGORY USING(categoryid)
203 INNER JOIN PLATFORM USING(platformid)
204 INNER JOIN CORE USING(coreid)
205 INNER JOIN COMPILER USING(compilerid)
206 INNER JOIN COMPILERKIND USING(compilerkindid)
207 INNER JOIN TYPE USING(typeid)
208 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200209 WHERE coreid=? AND typeid = ? AND (%s)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200210 """
211
212coresForHistory="""select distinct coreid,core from %s
213 INNER JOIN CORE USING(coreid)
214 WHERE compilerid=? AND typeid = ? AND ID = ? AND runid > (? - 10)
215 """
216
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200217# Command to get data for specific compiler
218# and type
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200219benchCmdForCompiler="""select %s from %s
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200220 INNER JOIN CATEGORY USING(categoryid)
221 INNER JOIN PLATFORM USING(platformid)
222 INNER JOIN CORE USING(coreid)
223 INNER JOIN COMPILER USING(compilerid)
224 INNER JOIN COMPILERKIND USING(compilerkindid)
225 INNER JOIN TYPE USING(typeid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200226 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200227 WHERE compilerid=? AND typeid = ? AND (%s)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200228 """
229
230# Command to get test names for specific compiler
231# and type
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200232benchNamesForCore="""select distinct ID,name from %s
233 INNER JOIN COMPILER USING(compilerid)
234 INNER JOIN COMPILERKIND USING(compilerkindid)
235 INNER JOIN TYPE USING(typeid)
236 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200237 WHERE coreid=? AND typeid = ? AND (%s)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200238 """
239# Command to get test names for specific compiler
240# and type
241benchNamesForCompiler="""select distinct ID,name from %s
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200242 INNER JOIN COMPILER USING(compilerid)
243 INNER JOIN COMPILERKIND USING(compilerkindid)
244 INNER JOIN TYPE USING(typeid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200245 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200246 WHERE compilerid=? AND typeid = ? AND (%s)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200247 """
248
249# Command to get columns for specific table
250benchCmdColumns="""select * from %s
251 INNER JOIN CATEGORY USING(categoryid)
252 INNER JOIN PLATFORM USING(platformid)
253 INNER JOIN CORE USING(coreid)
254 INNER JOIN COMPILER USING(compilerid)
255 INNER JOIN COMPILERKIND USING(compilerkindid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200256 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200257 INNER JOIN TYPE USING(typeid)
258 """
259
260def joinit(iterable, delimiter):
261 it = iter(iterable)
262 yield next(it)
263 for x in it:
264 yield delimiter
265 yield x
266
267# Is not a column name finishing by id
268# (often primary key for thetable)
269def isNotIDColumn(col):
270 if re.match(r'^.*id$',col):
271 return(False)
272 else:
273 return(True)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200274
275# Get test names
276# for specific typeid and core (for the data)
277def getTestNamesForCore(benchTable,core,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200278 vals=(core,typeid) + runidval
279 result=c.execute(benchNamesForCore % (benchTable,runidCMD),vals).fetchall()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200280 names=[(x[0],x[1]) for x in list(result)]
281 return(names)
282
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200283# Get test names
284# for specific typeid and compiler (for the data)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200285def getTestNamesForCompiler(benchTable,comp,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200286 vals=(comp,typeid) + runidval
287 result=c.execute(benchNamesForCompiler % (benchTable,runidCMD),vals).fetchall()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200288 names=[(x[0],x[1]) for x in list(result)]
289 return(names)
290
291# Command to get data for specific core
292# and type
293nbElemsInBenchAndTypeAndCoreCmd="""select count(*) from %s
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200294 WHERE coreid=? AND typeid = ? AND (%s)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200295 """
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200296
Christophe Favergeone15894e2020-05-14 07:25:53 +0200297# Command to get data for specific compiler
298# and type
299nbElemsInBenchAndTypeAndCompilerCmd="""select count(*) from %s
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200300 WHERE compilerid=? AND typeid = ? AND (%s)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200301 """
302
303nbElemsInBenchAndTypeCmd="""select count(*) from %s
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200304 WHERE typeid = ? AND (%s)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200305 """
306
307nbElemsInBenchCmd="""select count(*) from %s
Christophe Favergeon670b1672020-05-28 12:47:58 +0200308 WHERE %s
Christophe Favergeone15894e2020-05-14 07:25:53 +0200309 """
310
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200311categoryName="""select distinct category from %s
312 INNER JOIN CATEGORY USING(categoryid)
Christophe Favergeon670b1672020-05-28 12:47:58 +0200313 WHERE %s
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200314 """
315
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200316def getCategoryName(benchTable):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200317 result=c.execute(categoryName % (benchTable,runidCMD),runidval).fetchone()
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200318 return(result[0])
319
Christophe Favergeon4f750702020-05-13 15:56:15 +0200320# Get nb elems in a table
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200321def getNbElemsInBenchAndTypeAndCoreCmd(benchTable,coreid,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200322 vals=(coreid,typeid) + runidval
323 result=c.execute(nbElemsInBenchAndTypeAndCoreCmd % (benchTable,runidCMD),vals).fetchone()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200324 return(result[0])
325
326# Get nb elems in a table
Christophe Favergeone15894e2020-05-14 07:25:53 +0200327def getNbElemsInBenchAndTypeAndCompilerCmd(benchTable,comp,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200328 vals=(comp,typeid) + runidval
329 result=c.execute(nbElemsInBenchAndTypeAndCompilerCmd % (benchTable,runidCMD),vals).fetchone()
Christophe Favergeone15894e2020-05-14 07:25:53 +0200330 return(result[0])
331
332def getNbElemsInBenchAndTypeCmd(benchTable,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200333 vals=(typeid,) + runidval
334 result=c.execute(nbElemsInBenchAndTypeCmd % (benchTable,runidCMD),vals).fetchone()
Christophe Favergeone15894e2020-05-14 07:25:53 +0200335 return(result[0])
336
337def getNbElemsInBenchCmd(benchTable):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200338 result=c.execute(nbElemsInBenchCmd % (benchTable,runidCMD),runidval).fetchone()
Christophe Favergeon4f750702020-05-13 15:56:15 +0200339 return(result[0])
340
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200341# Get names of columns and data for a table
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200342# for specific typeid and coreid (for the data)
343def getColNamesAndHistory(benchTable,compiler,core,typeid,testid):
344 cursor=c.cursor()
345 result=cursor.execute(benchCmdColumns % (benchTable))
346 cols= [member[0] for member in cursor.description]
347 keepCols = ['name','runid'] + [c for c in diff(cols , REMOVECOLUMNSFORHISTORY) if isNotIDColumn(c)]
348 keepColsStr = "".join(joinit(keepCols,","))
349 vals=(compiler,core,typeid,testid,runid)
350 result=cursor.execute(historyCmd % (keepColsStr,benchTable),vals)
351 vals =np.array([list(x) for x in list(result)])
352 return(keepCols,vals)
353
354# Get names of columns and data for a table
355# for specific typeid and coreid (for the data)
356def getColNamesAndDataForCore(benchTable,core,typeid):
357 cursor=c.cursor()
358 result=cursor.execute(benchCmdColumns % (benchTable))
359 cols= [member[0] for member in cursor.description]
360 keepCols = ['name'] + [c for c in diff(cols , REMOVECOLUMNS) if isNotIDColumn(c)]
361 keepColsStr = "".join(joinit(keepCols,","))
Christophe Favergeon670b1672020-05-28 12:47:58 +0200362 vals=(core,typeid) + runidval
363 result=cursor.execute(benchCmdForCore % (keepColsStr,benchTable,runidCMD),vals)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200364 vals =np.array([list(x) for x in list(result)])
365 return(keepCols,vals)
366
367
368# Get names of columns and data for a table
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200369# for specific typeid and compiler (for the data)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200370def getColNamesAndDataForCompiler(benchTable,comp,typeid):
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200371 cursor=c.cursor()
372 result=cursor.execute(benchCmdColumns % (benchTable))
373 cols= [member[0] for member in cursor.description]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200374 keepCols = ['name'] + [c for c in diff(cols , REMOVECOLUMNS) if isNotIDColumn(c)]
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200375 keepColsStr = "".join(joinit(keepCols,","))
Christophe Favergeon670b1672020-05-28 12:47:58 +0200376 vals=(comp,typeid) + runidval
377 result=cursor.execute(benchCmdForCompiler % (keepColsStr,benchTable,runidCMD),vals)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200378 vals =np.array([list(x) for x in list(result)])
379 return(keepCols,vals)
380
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200381
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200382
383PARAMS=["NB","NumTaps", "NBA", "NBB", "Factor", "NumStages","VECDIM","NBR","NBC","NBI","IFFT", "BITREV"]
384
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200385def regressionTableFor(byname,name,section,ref,toSort,indexCols,field):
386 data=ref.pivot_table(index=indexCols, columns=byname,
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200387 values=[field], aggfunc='first')
388
389 data=data.sort_values(toSort)
390
391 cores = [c[1] for c in list(data.columns)]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200392 columns = diff(indexCols,['name'])
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200393
Christophe Favergeon34d313a2020-05-14 15:09:41 +0200394 dataTable=Table(columns,cores)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200395 section.addContent(dataTable)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200396
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200397 dataForFunc=data.loc[name]
398 if type(dataForFunc) is pd.DataFrame:
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200399 bars={'cols':columns,'cores':cores,'data':[]}
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200400 for row in dataForFunc.itertuples():
401 row=list(row)
402 if type(row[0]) is int:
403 row=[row[0]] + row[1:]
404 else:
405 row=list(row[0]) + row[1:]
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200406 if field=="MAXREGCOEF":
Christophe Favergeon670b1672020-05-28 12:47:58 +0200407 newrow = row
408 newrow[len(columns):] = [("%.3f" % x) for x in row[len(columns):]]
409 row=newrow
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200410 dataTable.addRow(row)
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200411 bars['data'].append(row)
412 return(bars)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200413 else:
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200414 if field=="MAXREGCOEF":
415 dataForFunc=[("%.3f" % x) for x in dataForFunc]
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200416 dataTable.addRow(dataForFunc)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200417 return(list(zip(cores,dataForFunc)))
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200418
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200419def formatColumnName(c):
420 return("".join(joinit(c,":")))
421
422def getCoresForHistory(benchTable,compilerid,typeid,testid,runid):
423 vals=(compilerid,typeid,testid,runid)
424 result=c.execute(coresForHistory % benchTable,vals).fetchall()
425 ids=[(x[0],x[1]) for x in list(result)]
426 return(ids)
427
428def getCompilerForHistory(benchTable,coreid,typeid,testid,runid):
429 vals=(coreid,typeid,testid,runid)
430 result=c.execute(compilersForHistory % benchTable,vals).fetchall()
431 ids=[(x[0],x[1],x[2]) for x in list(result)]
432 return(ids)
433
434def getHistory(desc,testid,indexCols):
435 benchName,sectionID,typeid,runid = desc
436
437 #print(benchName)
438 #print(sectionID)
439 #print(typeid)
440 #print(testid)
441 columns = diff(indexCols,['name'])
442 #print(columns)
443 if args.byc:
444 coreid=sectionID
445 compilerids=getCompilerForHistory(benchName,coreid,typeid,testid,runid)
446 series={}
447 for compilerid,compilername,version in compilerids:
448 result=getColNamesAndHistory(benchName,compilerid,coreid,typeid,testid)
449 #print("%s:%s" % (compilername,version))
450 maxpos = result[0].index('MAX')
451 lrunid = result[0].index('runid')
452 r=[[int(x[lrunid]),int(x[maxpos])] for x in result[1:][0]]
453 series[corename]=r
454 hist=History(series,runid)
455 return(hist)
456 else:
457 compilerid=sectionID
458 coreids = getCoresForHistory(benchName,compilerid,typeid,testid,runid)
459 series={}
460 for coreid,corename in coreids:
461 result=getColNamesAndHistory(benchName,compilerid,coreid,typeid,testid)
462 #print(corename)
463 maxpos = result[0].index('MAX')
464 corepos = result[0].index('core')
465 lrunid = result[0].index('runid')
466 r=[[int(x[lrunid]),int(x[maxpos])] for x in result[1:][0]]
467 series[corename]=r
468 hist=History(series,runid)
469 return(hist)
470
471def formatTableBy(desc,byname,section,typeSection,testNames,cols,vals):
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200472 if vals.size != 0:
473 ref=pd.DataFrame(vals,columns=cols)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200474 toSort=["name"]
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200475
476 for param in PARAMS:
477 if param in ref.columns:
478 ref[param]=pd.to_numeric(ref[param])
479 toSort.append(param)
480 if args.r:
481 # Regression table
482 ref['MAX']=pd.to_numeric(ref['MAX'])
483 ref['MAXREGCOEF']=pd.to_numeric(ref['MAXREGCOEF'])
484
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200485 indexCols=diff(cols,byname + ['Regression','MAXREGCOEF','MAX'] + section)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200486 valList = ['Regression']
487 else:
488 ref['CYCLES']=pd.to_numeric(ref['CYCLES'])
489
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200490 indexCols=diff(cols,byname + ['CYCLES'] + section)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200491 valList = ['CYCLES']
492
493
494
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200495 for testid,name in testNames:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200496 if args.r:
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200497 testSection = Section(name)
498 typeSection.addSection(testSection)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200499
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200500 maxCyclesSection = Section("Max cycles")
501 testSection.addSection(maxCyclesSection)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200502 theCycles=regressionTableFor(byname,name,maxCyclesSection,ref,toSort,indexCols,'MAX')
Christophe Favergeon670b1672020-05-28 12:47:58 +0200503 if args.g:
504 if type(theCycles) is dict:
505 nbParams=len(theCycles['cols'])
506 for bar in theCycles['data']:
507 params=bar[0:nbParams]
508 values=bar[nbParams:]
509 title=[("%s=%s" % x) for x in list(zip(theCycles['cols'],params))]
510 title="".join(joinit(title," "))
511 sec=Section(title)
512 maxCyclesSection.addSection(sec)
513 values=list(zip(theCycles['cores'],values))
514 barChart=BarChart(values)
515 sec.addContent(barChart)
516 else:
517 #print(theCycles)
518 sec=Section("Graph")
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200519 maxCyclesSection.addSection(sec)
Christophe Favergeon670b1672020-05-28 12:47:58 +0200520 barChart=BarChart(theCycles)
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200521 sec.addContent(barChart)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200522
Christophe Favergeon670b1672020-05-28 12:47:58 +0200523 #history=getHistory(desc,testid,indexCols)
524 #testSection.addContent(history)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200525
526 regressionSection = Section("Regression")
527 testSection.addSection(regressionSection)
528 regressionTableFor(byname,name,regressionSection,ref,toSort,indexCols,'Regression')
529
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200530
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200531 maxRegCoefSection = Section("Max Reg Coef")
532 testSection.addSection(maxRegCoefSection)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200533 regressionTableFor(byname,name,maxRegCoefSection,ref,toSort,indexCols,'MAXREGCOEF')
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200534
535 else:
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200536 data=ref.pivot_table(index=indexCols, columns=byname,
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200537 values=valList, aggfunc='first')
538
539 data=data.sort_values(toSort)
540
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200541 #print(list(data.columns))
542 columnsID = [formatColumnName(c[1:]) for c in list(data.columns)]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200543 columns = diff(indexCols,['name'])
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200544
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200545 testSection = Section(name)
546 typeSection.addSection(testSection)
547
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200548 dataTable=Table(columns,columnsID)
549 testSection.addContent(dataTable)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200550
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200551 dataForFunc=data.loc[name]
552 if type(dataForFunc) is pd.DataFrame:
553 for row in dataForFunc.itertuples():
554 row=list(row)
555 if type(row[0]) is int:
556 row=[row[0]] + row[1:]
557 else:
558 row=list(row[0]) + row[1:]
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200559 dataTable.addRow(row)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200560 else:
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200561 dataTable.addRow(dataForFunc)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200562
563# Add a report for each table
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200564def addReportFor(document,benchName):
Christophe Favergeone15894e2020-05-14 07:25:53 +0200565 nbElems = getNbElemsInBenchCmd(benchName)
566 if nbElems > 0:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200567 categoryName = getCategoryName(benchName)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200568 benchSection = Section(categoryName)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200569 document.addSection(benchSection)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200570 print("Process %s\n" % benchName)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200571 allTypes = getExistingTypes(benchName)
572 # Add report for each type
573 for aTypeID in allTypes:
574 nbElems = getNbElemsInBenchAndTypeCmd(benchName,aTypeID)
575 if nbElems > 0:
576 typeName = getTypeName(aTypeID)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200577 typeSection = Section(typeName)
578 benchSection.addSection(typeSection)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200579 if args.byc:
580 ## Add report for each core
581 allCores = getExistingCores(benchName,aTypeID)
582 for core in allCores:
583 #print(core)
584 nbElems = getNbElemsInBenchAndTypeAndCoreCmd(benchName,core,aTypeID)
585 # Print test results for table, type, compiler
586 if nbElems > 0:
587 coreName=getCoreDesc(core)
588 coreSection = Section("%s" % coreName)
589 typeSection.addSection(coreSection)
590 cols,vals=getColNamesAndDataForCore(benchName,core,aTypeID)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200591 desc=(benchName,core,aTypeID)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200592 names=getTestNamesForCore(benchName,core,aTypeID)
593 formatTableBy(desc,['compiler','version'],['core'],coreSection,names,cols,vals)
594 else:
595 ## Add report for each compiler
596 allCompilers = getExistingCompiler(benchName,aTypeID)
597 for compiler in allCompilers:
598 #print(compiler)
599 nbElems = getNbElemsInBenchAndTypeAndCompilerCmd(benchName,compiler,aTypeID)
600 # Print test results for table, type, compiler
601 if nbElems > 0:
602 compilerName,version=getCompilerDesc(compiler)
603 compilerSection = Section("%s (%s)" % (compilerName,version))
604 typeSection.addSection(compilerSection)
605 cols,vals=getColNamesAndDataForCompiler(benchName,compiler,aTypeID)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200606 desc=(benchName,compiler,aTypeID)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200607 names=getTestNamesForCompiler(benchName,compiler,aTypeID)
608 formatTableBy(desc,['core'],['version','compiler'],compilerSection,names,cols,vals)
609
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200610
611
612
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200613toc=[Hierarchy("BasicMathsBenchmarks"),
614Hierarchy("ComplexMathsBenchmarks"),
615Hierarchy("FastMath"),
616Hierarchy("Filters",
617 [Hierarchy("FIR"),
618 Hierarchy("BIQUAD"),
619 Hierarchy("DECIM"),
620 Hierarchy("MISC")]),
621
622Hierarchy("Support Functions",
623 [Hierarchy("Support"),
624 Hierarchy("SupportBar")]),
625
626Hierarchy("Matrix Operations" ,
627 [Hierarchy("Binary"),
628 Hierarchy("Unary")]),
629Hierarchy("Transform"),
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200630Hierarchy("Stats"),
631Hierarchy("Classical ML",[
632 Hierarchy("Bayes"),
633 Hierarchy("SVM"),
634 Hierarchy("Distance"),
635 ]),
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200636
637]
638
639processed=[]
640
Christophe Favergeon66de4ac2020-07-31 13:38:09 +0200641def addComments(document):
642 if os.path.exists(args.comments):
643 section=Section("Measurement Context")
644
645 document.addSection(section)
646 para=""
647 with open(args.comments,"r") as r:
648 for l in r:
649 if l.strip():
650 para += l
651 else:
652 section.addContent(Text(para))
653 para=""
654 if para:
655 section.addContent(Text(para))
656
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200657def createDoc(document,sections,benchtables):
658 global processed
659 for s in sections:
660 if s.name in benchtables:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200661 addReportFor(document,s.name)
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200662 processed.append(s.name)
663 else:
664 section=Section(s.name)
665 document.addSection(section)
666 createDoc(section,s.sections,benchtables)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200667
668try:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200669 benchtables=getBenchTables()
Christophe Favergeon66de4ac2020-07-31 13:38:09 +0200670 document = Document(runidHeader)
671
672 addComments(document)
673
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200674 createDoc(document,toc,benchtables)
Christophe Favergeon66de4ac2020-07-31 13:38:09 +0200675
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200676 misc=Section("Miscellaneous")
677 document.addSection(misc)
678 remaining=diff(benchtables,processed)
679 for bench in remaining:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200680 addReportFor(misc,bench)
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200681
682 #for bench in benchtables:
683 # addReportFor(document,bench)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200684 with open(args.o,"w") as output:
685 if args.t=="md":
686 document.accept(Markdown(output))
687 if args.t=="html":
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200688 document.accept(HTML(output,args.r))
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200689
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200690finally:
691 c.close()
692
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200693
694
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200695