blob: a7230350252d34ce6cc4562868a95129bbdbd014 [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 Favergeonfe27d872020-07-31 07:20:18 +0200121def getrunIDDetails():
122 tables=getBenchTables()
123 r=[]
124 for table in tables:
125 r += [x[0] for x in c.execute(runIDDetails % (table,runidCMD),runidval).fetchall()]
126 r=list(set(r))
127 print(r)
128
129if args.lastid:
130 quit()
131
132if args.details:
133 getrunIDDetails()
134 quit()
135
136
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200137# Get compilers from specific type and table
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200138allCompilers="""select distinct compilerid from %s WHERE typeid=?"""
139
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200140# Get compilers from specific type and table
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200141allCores="""select distinct coreid from %s WHERE typeid=? AND (%s)"""
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200142
143
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200144compilerDesc="""select compiler,version from COMPILER
145 INNER JOIN COMPILERKIND USING(compilerkindid) WHERE compilerid=?"""
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200146
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200147coreDesc="""select core from CORE WHERE coreid=?"""
148
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200149# Get existing compiler in a table for a specific type
150# (In case report is structured by types)
151def getExistingCompiler(benchTable,typeid):
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200152 r=c.execute(allCompilers % benchTable,(typeid,)).fetchall()
153 return([x[0] for x in r])
154
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200155def getExistingCores(benchTable,typeid):
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200156 vals = (typeid,) + runidval
157 r=c.execute(allCores % (benchTable,runidCMD),vals).fetchall()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200158 return([x[0] for x in r])
159
160
161
162def getCoreDesc(compilerid):
163 r=c.execute(coreDesc,(compilerid,)).fetchone()
164 return(r)
165
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200166def getCompilerDesc(compilerid):
167 r=c.execute(compilerDesc,(compilerid,)).fetchone()
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200168 return(r)
169
170# Get type name from type id
171def getTypeName(typeid):
172 r=c.execute("select type from TYPE where typeid=?",(typeid,)).fetchone()
173 return(r[0])
174
175# Diff of 2 lists
176def diff(first, second):
177 second = set(second)
178 return [item for item in first if item not in second]
179
180
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200181# Command to get data for specific core
182# and type
183historyCmd="""select %s from %s
184 INNER JOIN CATEGORY USING(categoryid)
185 INNER JOIN PLATFORM USING(platformid)
186 INNER JOIN CORE USING(coreid)
187 INNER JOIN COMPILER USING(compilerid)
188 INNER JOIN COMPILERKIND USING(compilerkindid)
189 INNER JOIN TYPE USING(typeid)
190 INNER JOIN TESTNAME USING(testnameid)
191 WHERE compilerid=? AND coreid=? AND typeid = ? AND ID = ? AND runid > (? - 10)
192 """
193
194compilersForHistory="""select distinct compilerid,compiler,version from %s
195 INNER JOIN COMPILER USING(compilerid)
196 INNER JOIN COMPILERKIND USING(compilerkindid)
197 WHERE coreid=? AND typeid = ? AND ID = ? AND runid > (? - 10)
198 """
199
200# Command to get data for specific core
201# and type
202benchCmdForCore="""select %s from %s
203 INNER JOIN CATEGORY USING(categoryid)
204 INNER JOIN PLATFORM USING(platformid)
205 INNER JOIN CORE USING(coreid)
206 INNER JOIN COMPILER USING(compilerid)
207 INNER JOIN COMPILERKIND USING(compilerkindid)
208 INNER JOIN TYPE USING(typeid)
209 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200210 WHERE coreid=? AND typeid = ? AND (%s)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200211 """
212
213coresForHistory="""select distinct coreid,core from %s
214 INNER JOIN CORE USING(coreid)
215 WHERE compilerid=? AND typeid = ? AND ID = ? AND runid > (? - 10)
216 """
217
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200218# Command to get data for specific compiler
219# and type
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200220benchCmdForCompiler="""select %s from %s
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200221 INNER JOIN CATEGORY USING(categoryid)
222 INNER JOIN PLATFORM USING(platformid)
223 INNER JOIN CORE USING(coreid)
224 INNER JOIN COMPILER USING(compilerid)
225 INNER JOIN COMPILERKIND USING(compilerkindid)
226 INNER JOIN TYPE USING(typeid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200227 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200228 WHERE compilerid=? AND typeid = ? AND (%s)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200229 """
230
231# Command to get test names for specific compiler
232# and type
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200233benchNamesForCore="""select distinct ID,name from %s
234 INNER JOIN COMPILER USING(compilerid)
235 INNER JOIN COMPILERKIND USING(compilerkindid)
236 INNER JOIN TYPE USING(typeid)
237 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200238 WHERE coreid=? AND typeid = ? AND (%s)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200239 """
240# Command to get test names for specific compiler
241# and type
242benchNamesForCompiler="""select distinct ID,name from %s
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200243 INNER JOIN COMPILER USING(compilerid)
244 INNER JOIN COMPILERKIND USING(compilerkindid)
245 INNER JOIN TYPE USING(typeid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200246 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200247 WHERE compilerid=? AND typeid = ? AND (%s)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200248 """
249
250# Command to get columns for specific table
251benchCmdColumns="""select * from %s
252 INNER JOIN CATEGORY USING(categoryid)
253 INNER JOIN PLATFORM USING(platformid)
254 INNER JOIN CORE USING(coreid)
255 INNER JOIN COMPILER USING(compilerid)
256 INNER JOIN COMPILERKIND USING(compilerkindid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200257 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200258 INNER JOIN TYPE USING(typeid)
259 """
260
261def joinit(iterable, delimiter):
262 it = iter(iterable)
263 yield next(it)
264 for x in it:
265 yield delimiter
266 yield x
267
268# Is not a column name finishing by id
269# (often primary key for thetable)
270def isNotIDColumn(col):
271 if re.match(r'^.*id$',col):
272 return(False)
273 else:
274 return(True)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200275
276# Get test names
277# for specific typeid and core (for the data)
278def getTestNamesForCore(benchTable,core,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200279 vals=(core,typeid) + runidval
280 result=c.execute(benchNamesForCore % (benchTable,runidCMD),vals).fetchall()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200281 names=[(x[0],x[1]) for x in list(result)]
282 return(names)
283
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200284# Get test names
285# for specific typeid and compiler (for the data)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200286def getTestNamesForCompiler(benchTable,comp,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200287 vals=(comp,typeid) + runidval
288 result=c.execute(benchNamesForCompiler % (benchTable,runidCMD),vals).fetchall()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200289 names=[(x[0],x[1]) for x in list(result)]
290 return(names)
291
292# Command to get data for specific core
293# and type
294nbElemsInBenchAndTypeAndCoreCmd="""select count(*) from %s
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200295 WHERE coreid=? AND typeid = ? AND (%s)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200296 """
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200297
Christophe Favergeone15894e2020-05-14 07:25:53 +0200298# Command to get data for specific compiler
299# and type
300nbElemsInBenchAndTypeAndCompilerCmd="""select count(*) from %s
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200301 WHERE compilerid=? AND typeid = ? AND (%s)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200302 """
303
304nbElemsInBenchAndTypeCmd="""select count(*) from %s
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200305 WHERE typeid = ? AND (%s)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200306 """
307
308nbElemsInBenchCmd="""select count(*) from %s
Christophe Favergeon670b1672020-05-28 12:47:58 +0200309 WHERE %s
Christophe Favergeone15894e2020-05-14 07:25:53 +0200310 """
311
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200312categoryName="""select distinct category from %s
313 INNER JOIN CATEGORY USING(categoryid)
Christophe Favergeon670b1672020-05-28 12:47:58 +0200314 WHERE %s
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200315 """
316
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200317def getCategoryName(benchTable):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200318 result=c.execute(categoryName % (benchTable,runidCMD),runidval).fetchone()
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200319 return(result[0])
320
Christophe Favergeon4f750702020-05-13 15:56:15 +0200321# Get nb elems in a table
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200322def getNbElemsInBenchAndTypeAndCoreCmd(benchTable,coreid,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200323 vals=(coreid,typeid) + runidval
324 result=c.execute(nbElemsInBenchAndTypeAndCoreCmd % (benchTable,runidCMD),vals).fetchone()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200325 return(result[0])
326
327# Get nb elems in a table
Christophe Favergeone15894e2020-05-14 07:25:53 +0200328def getNbElemsInBenchAndTypeAndCompilerCmd(benchTable,comp,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200329 vals=(comp,typeid) + runidval
330 result=c.execute(nbElemsInBenchAndTypeAndCompilerCmd % (benchTable,runidCMD),vals).fetchone()
Christophe Favergeone15894e2020-05-14 07:25:53 +0200331 return(result[0])
332
333def getNbElemsInBenchAndTypeCmd(benchTable,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200334 vals=(typeid,) + runidval
335 result=c.execute(nbElemsInBenchAndTypeCmd % (benchTable,runidCMD),vals).fetchone()
Christophe Favergeone15894e2020-05-14 07:25:53 +0200336 return(result[0])
337
338def getNbElemsInBenchCmd(benchTable):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200339 result=c.execute(nbElemsInBenchCmd % (benchTable,runidCMD),runidval).fetchone()
Christophe Favergeon4f750702020-05-13 15:56:15 +0200340 return(result[0])
341
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200342# Get names of columns and data for a table
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200343# for specific typeid and coreid (for the data)
344def getColNamesAndHistory(benchTable,compiler,core,typeid,testid):
345 cursor=c.cursor()
346 result=cursor.execute(benchCmdColumns % (benchTable))
347 cols= [member[0] for member in cursor.description]
348 keepCols = ['name','runid'] + [c for c in diff(cols , REMOVECOLUMNSFORHISTORY) if isNotIDColumn(c)]
349 keepColsStr = "".join(joinit(keepCols,","))
350 vals=(compiler,core,typeid,testid,runid)
351 result=cursor.execute(historyCmd % (keepColsStr,benchTable),vals)
352 vals =np.array([list(x) for x in list(result)])
353 return(keepCols,vals)
354
355# Get names of columns and data for a table
356# for specific typeid and coreid (for the data)
357def getColNamesAndDataForCore(benchTable,core,typeid):
358 cursor=c.cursor()
359 result=cursor.execute(benchCmdColumns % (benchTable))
360 cols= [member[0] for member in cursor.description]
361 keepCols = ['name'] + [c for c in diff(cols , REMOVECOLUMNS) if isNotIDColumn(c)]
362 keepColsStr = "".join(joinit(keepCols,","))
Christophe Favergeon670b1672020-05-28 12:47:58 +0200363 vals=(core,typeid) + runidval
364 result=cursor.execute(benchCmdForCore % (keepColsStr,benchTable,runidCMD),vals)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200365 vals =np.array([list(x) for x in list(result)])
366 return(keepCols,vals)
367
368
369# Get names of columns and data for a table
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200370# for specific typeid and compiler (for the data)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200371def getColNamesAndDataForCompiler(benchTable,comp,typeid):
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200372 cursor=c.cursor()
373 result=cursor.execute(benchCmdColumns % (benchTable))
374 cols= [member[0] for member in cursor.description]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200375 keepCols = ['name'] + [c for c in diff(cols , REMOVECOLUMNS) if isNotIDColumn(c)]
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200376 keepColsStr = "".join(joinit(keepCols,","))
Christophe Favergeon670b1672020-05-28 12:47:58 +0200377 vals=(comp,typeid) + runidval
378 result=cursor.execute(benchCmdForCompiler % (keepColsStr,benchTable,runidCMD),vals)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200379 vals =np.array([list(x) for x in list(result)])
380 return(keepCols,vals)
381
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200382
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200383
384PARAMS=["NB","NumTaps", "NBA", "NBB", "Factor", "NumStages","VECDIM","NBR","NBC","NBI","IFFT", "BITREV"]
385
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200386def regressionTableFor(byname,name,section,ref,toSort,indexCols,field):
387 data=ref.pivot_table(index=indexCols, columns=byname,
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200388 values=[field], aggfunc='first')
389
390 data=data.sort_values(toSort)
391
392 cores = [c[1] for c in list(data.columns)]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200393 columns = diff(indexCols,['name'])
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200394
Christophe Favergeon34d313a2020-05-14 15:09:41 +0200395 dataTable=Table(columns,cores)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200396 section.addContent(dataTable)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200397
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200398 dataForFunc=data.loc[name]
399 if type(dataForFunc) is pd.DataFrame:
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200400 bars={'cols':columns,'cores':cores,'data':[]}
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200401 for row in dataForFunc.itertuples():
402 row=list(row)
403 if type(row[0]) is int:
404 row=[row[0]] + row[1:]
405 else:
406 row=list(row[0]) + row[1:]
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200407 if field=="MAXREGCOEF":
Christophe Favergeon670b1672020-05-28 12:47:58 +0200408 newrow = row
409 newrow[len(columns):] = [("%.3f" % x) for x in row[len(columns):]]
410 row=newrow
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200411 dataTable.addRow(row)
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200412 bars['data'].append(row)
413 return(bars)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200414 else:
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200415 if field=="MAXREGCOEF":
416 dataForFunc=[("%.3f" % x) for x in dataForFunc]
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200417 dataTable.addRow(dataForFunc)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200418 return(list(zip(cores,dataForFunc)))
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200419
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200420def formatColumnName(c):
421 return("".join(joinit(c,":")))
422
423def getCoresForHistory(benchTable,compilerid,typeid,testid,runid):
424 vals=(compilerid,typeid,testid,runid)
425 result=c.execute(coresForHistory % benchTable,vals).fetchall()
426 ids=[(x[0],x[1]) for x in list(result)]
427 return(ids)
428
429def getCompilerForHistory(benchTable,coreid,typeid,testid,runid):
430 vals=(coreid,typeid,testid,runid)
431 result=c.execute(compilersForHistory % benchTable,vals).fetchall()
432 ids=[(x[0],x[1],x[2]) for x in list(result)]
433 return(ids)
434
435def getHistory(desc,testid,indexCols):
436 benchName,sectionID,typeid,runid = desc
437
438 #print(benchName)
439 #print(sectionID)
440 #print(typeid)
441 #print(testid)
442 columns = diff(indexCols,['name'])
443 #print(columns)
444 if args.byc:
445 coreid=sectionID
446 compilerids=getCompilerForHistory(benchName,coreid,typeid,testid,runid)
447 series={}
448 for compilerid,compilername,version in compilerids:
449 result=getColNamesAndHistory(benchName,compilerid,coreid,typeid,testid)
450 #print("%s:%s" % (compilername,version))
451 maxpos = result[0].index('MAX')
452 lrunid = result[0].index('runid')
453 r=[[int(x[lrunid]),int(x[maxpos])] for x in result[1:][0]]
454 series[corename]=r
455 hist=History(series,runid)
456 return(hist)
457 else:
458 compilerid=sectionID
459 coreids = getCoresForHistory(benchName,compilerid,typeid,testid,runid)
460 series={}
461 for coreid,corename in coreids:
462 result=getColNamesAndHistory(benchName,compilerid,coreid,typeid,testid)
463 #print(corename)
464 maxpos = result[0].index('MAX')
465 corepos = result[0].index('core')
466 lrunid = result[0].index('runid')
467 r=[[int(x[lrunid]),int(x[maxpos])] for x in result[1:][0]]
468 series[corename]=r
469 hist=History(series,runid)
470 return(hist)
471
472def formatTableBy(desc,byname,section,typeSection,testNames,cols,vals):
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200473 if vals.size != 0:
474 ref=pd.DataFrame(vals,columns=cols)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200475 toSort=["name"]
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200476
477 for param in PARAMS:
478 if param in ref.columns:
479 ref[param]=pd.to_numeric(ref[param])
480 toSort.append(param)
481 if args.r:
482 # Regression table
483 ref['MAX']=pd.to_numeric(ref['MAX'])
484 ref['MAXREGCOEF']=pd.to_numeric(ref['MAXREGCOEF'])
485
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200486 indexCols=diff(cols,byname + ['Regression','MAXREGCOEF','MAX'] + section)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200487 valList = ['Regression']
488 else:
489 ref['CYCLES']=pd.to_numeric(ref['CYCLES'])
490
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200491 indexCols=diff(cols,byname + ['CYCLES'] + section)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200492 valList = ['CYCLES']
493
494
495
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200496 for testid,name in testNames:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200497 if args.r:
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200498 testSection = Section(name)
499 typeSection.addSection(testSection)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200500
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200501 maxCyclesSection = Section("Max cycles")
502 testSection.addSection(maxCyclesSection)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200503 theCycles=regressionTableFor(byname,name,maxCyclesSection,ref,toSort,indexCols,'MAX')
Christophe Favergeon670b1672020-05-28 12:47:58 +0200504 if args.g:
505 if type(theCycles) is dict:
506 nbParams=len(theCycles['cols'])
507 for bar in theCycles['data']:
508 params=bar[0:nbParams]
509 values=bar[nbParams:]
510 title=[("%s=%s" % x) for x in list(zip(theCycles['cols'],params))]
511 title="".join(joinit(title," "))
512 sec=Section(title)
513 maxCyclesSection.addSection(sec)
514 values=list(zip(theCycles['cores'],values))
515 barChart=BarChart(values)
516 sec.addContent(barChart)
517 else:
518 #print(theCycles)
519 sec=Section("Graph")
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200520 maxCyclesSection.addSection(sec)
Christophe Favergeon670b1672020-05-28 12:47:58 +0200521 barChart=BarChart(theCycles)
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200522 sec.addContent(barChart)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200523
Christophe Favergeon670b1672020-05-28 12:47:58 +0200524 #history=getHistory(desc,testid,indexCols)
525 #testSection.addContent(history)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200526
527 regressionSection = Section("Regression")
528 testSection.addSection(regressionSection)
529 regressionTableFor(byname,name,regressionSection,ref,toSort,indexCols,'Regression')
530
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200531
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200532 maxRegCoefSection = Section("Max Reg Coef")
533 testSection.addSection(maxRegCoefSection)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200534 regressionTableFor(byname,name,maxRegCoefSection,ref,toSort,indexCols,'MAXREGCOEF')
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200535
536 else:
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200537 data=ref.pivot_table(index=indexCols, columns=byname,
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200538 values=valList, aggfunc='first')
539
540 data=data.sort_values(toSort)
541
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200542 #print(list(data.columns))
543 columnsID = [formatColumnName(c[1:]) for c in list(data.columns)]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200544 columns = diff(indexCols,['name'])
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200545
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200546 testSection = Section(name)
547 typeSection.addSection(testSection)
548
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200549 dataTable=Table(columns,columnsID)
550 testSection.addContent(dataTable)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200551
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200552 dataForFunc=data.loc[name]
553 if type(dataForFunc) is pd.DataFrame:
554 for row in dataForFunc.itertuples():
555 row=list(row)
556 if type(row[0]) is int:
557 row=[row[0]] + row[1:]
558 else:
559 row=list(row[0]) + row[1:]
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200560 dataTable.addRow(row)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200561 else:
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200562 dataTable.addRow(dataForFunc)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200563
564# Add a report for each table
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200565def addReportFor(document,benchName):
Christophe Favergeone15894e2020-05-14 07:25:53 +0200566 nbElems = getNbElemsInBenchCmd(benchName)
567 if nbElems > 0:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200568 categoryName = getCategoryName(benchName)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200569 benchSection = Section(categoryName)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200570 document.addSection(benchSection)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200571 print("Process %s\n" % benchName)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200572 allTypes = getExistingTypes(benchName)
573 # Add report for each type
574 for aTypeID in allTypes:
575 nbElems = getNbElemsInBenchAndTypeCmd(benchName,aTypeID)
576 if nbElems > 0:
577 typeName = getTypeName(aTypeID)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200578 typeSection = Section(typeName)
579 benchSection.addSection(typeSection)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200580 if args.byc:
581 ## Add report for each core
582 allCores = getExistingCores(benchName,aTypeID)
583 for core in allCores:
584 #print(core)
585 nbElems = getNbElemsInBenchAndTypeAndCoreCmd(benchName,core,aTypeID)
586 # Print test results for table, type, compiler
587 if nbElems > 0:
588 coreName=getCoreDesc(core)
589 coreSection = Section("%s" % coreName)
590 typeSection.addSection(coreSection)
591 cols,vals=getColNamesAndDataForCore(benchName,core,aTypeID)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200592 desc=(benchName,core,aTypeID)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200593 names=getTestNamesForCore(benchName,core,aTypeID)
594 formatTableBy(desc,['compiler','version'],['core'],coreSection,names,cols,vals)
595 else:
596 ## Add report for each compiler
597 allCompilers = getExistingCompiler(benchName,aTypeID)
598 for compiler in allCompilers:
599 #print(compiler)
600 nbElems = getNbElemsInBenchAndTypeAndCompilerCmd(benchName,compiler,aTypeID)
601 # Print test results for table, type, compiler
602 if nbElems > 0:
603 compilerName,version=getCompilerDesc(compiler)
604 compilerSection = Section("%s (%s)" % (compilerName,version))
605 typeSection.addSection(compilerSection)
606 cols,vals=getColNamesAndDataForCompiler(benchName,compiler,aTypeID)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200607 desc=(benchName,compiler,aTypeID)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200608 names=getTestNamesForCompiler(benchName,compiler,aTypeID)
609 formatTableBy(desc,['core'],['version','compiler'],compilerSection,names,cols,vals)
610
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200611
612
613
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200614toc=[Hierarchy("BasicMathsBenchmarks"),
615Hierarchy("ComplexMathsBenchmarks"),
616Hierarchy("FastMath"),
617Hierarchy("Filters",
618 [Hierarchy("FIR"),
619 Hierarchy("BIQUAD"),
620 Hierarchy("DECIM"),
621 Hierarchy("MISC")]),
622
623Hierarchy("Support Functions",
624 [Hierarchy("Support"),
625 Hierarchy("SupportBar")]),
626
627Hierarchy("Matrix Operations" ,
628 [Hierarchy("Binary"),
629 Hierarchy("Unary")]),
630Hierarchy("Transform"),
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200631Hierarchy("Stats"),
632Hierarchy("Classical ML",[
633 Hierarchy("Bayes"),
634 Hierarchy("SVM"),
635 Hierarchy("Distance"),
636 ]),
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200637
638]
639
640processed=[]
641
Christophe Favergeon66de4ac2020-07-31 13:38:09 +0200642def addComments(document):
643 if os.path.exists(args.comments):
644 section=Section("Measurement Context")
645
646 document.addSection(section)
647 para=""
648 with open(args.comments,"r") as r:
649 for l in r:
650 if l.strip():
651 para += l
652 else:
653 section.addContent(Text(para))
654 para=""
655 if para:
656 section.addContent(Text(para))
657
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200658def createDoc(document,sections,benchtables):
659 global processed
660 for s in sections:
661 if s.name in benchtables:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200662 addReportFor(document,s.name)
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200663 processed.append(s.name)
664 else:
665 section=Section(s.name)
666 document.addSection(section)
667 createDoc(section,s.sections,benchtables)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200668
669try:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200670 benchtables=getBenchTables()
Christophe Favergeon66de4ac2020-07-31 13:38:09 +0200671 document = Document(runidHeader)
672
673 addComments(document)
674
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200675 createDoc(document,toc,benchtables)
Christophe Favergeon66de4ac2020-07-31 13:38:09 +0200676
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200677 misc=Section("Miscellaneous")
678 document.addSection(misc)
679 remaining=diff(benchtables,processed)
680 for bench in remaining:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200681 addReportFor(misc,bench)
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200682
683 #for bench in benchtables:
684 # addReportFor(document,bench)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200685 with open(args.o,"w") as output:
686 if args.t=="md":
687 document.accept(Markdown(output))
688 if args.t=="html":
Christophe Favergeonf1a87802020-08-17 07:36:05 +0200689 reorder=True
690 if args.byc:
691 reorder=False
692 document.accept(HTML(output,args.r,reorder))
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200693
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200694finally:
695 c.close()
696
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200697
698
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200699