blob: a73975a5eb4d3b4a727e3debbb2cc5ab876904fa [file] [log] [blame]
Christophe Favergeon8cb37302020-05-13 13:06:58 +02001import argparse
2import sqlite3
3import re
4import pandas as pd
5import numpy as np
6
Christophe Favergeon34d313a2020-05-14 15:09:41 +02007remapNames={
Christophe Favergeon34d313a2020-05-14 15:09:41 +02008}
9
10def convertSectionName(s):
11 if s in remapNames:
12 return(remapNames[s])
13 else:
14 return(s)
15
Christophe Favergeonc3f455c2020-05-14 09:24:07 +020016class Document:
17 def __init__(self,runid,date):
18 self._runid = runid
19 self._date = date
20 self._sections = []
21
22 @property
23 def runid(self):
24 return(self._runid)
25
26 @property
27 def date(self):
28 return(self._date)
29
30 @property
31 def sections(self):
32 return(self._sections)
33
34 def addSection(self,section):
35 self._sections.append(section)
36
37 def accept(self, visitor):
38 visitor.visitDocument(self)
39 for element in self._sections:
40 element.accept(visitor)
41 visitor.leaveDocument(self)
42
43class Section:
44 def __init__(self,name):
Christophe Favergeon34d313a2020-05-14 15:09:41 +020045 self._name=convertSectionName(name)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +020046 self._subsections = []
47 self._tables = []
48
49 def addSection(self,section):
50 self._subsections.append(section)
51
52 def addTable(self,table):
53 self._tables.append(table)
54
55 @property
56 def hasChildren(self):
57 return(len(self._subsections)>0)
58
59 @property
60 def name(self):
61 return(self._name)
62
63 def accept(self, visitor):
64 visitor.visitSection(self)
65 for element in self._subsections:
66 element.accept(visitor)
67 for element in self._tables:
68 element.accept(visitor)
69 visitor.leaveSection(self)
70
71class Table:
Christophe Favergeon34d313a2020-05-14 15:09:41 +020072 def __init__(self,params,cores):
73 self._params=params
74 self._cores=cores
Christophe Favergeonc3f455c2020-05-14 09:24:07 +020075 self._rows=[]
76
77 def addRow(self,row):
78 self._rows.append(row)
79
80 @property
81 def columns(self):
Christophe Favergeon34d313a2020-05-14 15:09:41 +020082 return(self._params + self._cores)
83
84 @property
85 def params(self):
86 return(self._params)
87
88 @property
89 def cores(self):
90 return(self._cores)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +020091
92 @property
93 def rows(self):
94 return(self._rows)
95
96 def accept(self, visitor):
97 visitor.visitTable(self)
98
99
100
101class Markdown:
102 def __init__(self,output):
103 self._id=0
104 self._output = output
105
106 # Write columns in markdown format
107 def writeColumns(self,cols):
108 colStr = "".join(joinit(cols,"|"))
109 self._output.write("|")
110 self._output.write(colStr)
111 self._output.write("|\n")
112 sepStr="".join(joinit([":-:" for x in cols],"|"))
113 self._output.write("|")
114 self._output.write(sepStr)
115 self._output.write("|\n")
116
117 # Write row in markdown format
118 def writeRow(self,row):
119 row=[str(x) for x in row]
120 rowStr = "".join(joinit(row,"|"))
121 self._output.write("|")
122 self._output.write(rowStr)
123 self._output.write("|\n")
124
125 def visitTable(self,table):
126 self.writeColumns(table.columns)
127 for row in table.rows:
128 self.writeRow(row)
129
130 def visitSection(self,section):
131 self._id = self._id + 1
132 header = "".join(["#" for i in range(self._id)])
133 output.write("%s %s\n" % (header,section.name))
134
135 def leaveSection(self,section):
136 self._id = self._id - 1
137
138 def visitDocument(self,document):
139 self._output.write("Run number %d on %s\n" % (document.runid, str(document.date)))
140
141 def leaveDocument(self,document):
142 pass
143
144styleSheet="""
145<style type='text/css'>
146
147#TOC {
148 position: fixed;
149 left: 0;
150 top: 0;
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200151 width: 280px;
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200152 height: 100%;
153 overflow:auto;
Christophe Favergeon34d313a2020-05-14 15:09:41 +0200154 margin-top:5px;
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200155 margin-bottom:10px;
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200156}
157
158html {
159 font-size: 16px;
160}
161
162html, body {
163 background-color: #f3f2ee;
164 font-family: "PT Serif", 'Times New Roman', Times, serif;
165 color: #1f0909;
166 line-height: 1.5em;
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200167}
168
Christophe Favergeon34d313a2020-05-14 15:09:41 +0200169body {
170 margin: auto;
171 margin-top:0px;
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200172 margin-left:280px;
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200173
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200174}
175
176h1,
177h2,
178h3,
179h4,
180h5,
181h6 {
182 font-weight: bold;
183}
184h1 {
185 font-size: 1.875em;
Christophe Favergeon34d313a2020-05-14 15:09:41 +0200186 margin-top:5px;
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200187}
Christophe Favergeon34d313a2020-05-14 15:09:41 +0200188h2 {
189 font-size: 1.3125em;
190}
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200191h3 {
192 font-size: 1.3125em;
Christophe Favergeon34d313a2020-05-14 15:09:41 +0200193 margin-left:1em;
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200194}
195h4 {
196 font-size: 1.125em;
Christophe Favergeon34d313a2020-05-14 15:09:41 +0200197 margin-left:1em;
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200198}
199h5,
200h6 {
201 font-size: 1em;
202}
203
Christophe Favergeon34d313a2020-05-14 15:09:41 +0200204#TOC h1 {
205 margin-top:0em;
206 margin-left:0.5em;
207}
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200208
209table {
210 margin-bottom: 1.5em;
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200211 font-size: 1em;
Christophe Favergeon34d313a2020-05-14 15:09:41 +0200212 width: 100%;
213 border-collapse: collapse;
214 border-spacing: 0;
215 width: 100%;
216 margin-left:1em;
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200217}
218thead th,
219tfoot th {
220 padding: .25em .25em .25em .4em;
221 text-transform: uppercase;
222}
223th {
224 text-align: left;
225}
226td {
227 vertical-align: top;
228 padding: .25em .25em .25em .4em;
229}
230
231.ty-table-edit {
232 background-color: transparent;
233}
234thead {
235 background-color: #dadada;
236}
237tr:nth-child(even) {
238 background: #e8e7e7;
239}
240
241ul, #myUL {
242 list-style-type: none;
243 padding-inline-start:10px;
244}
245
246
247
248/* Remove margins and padding from the parent ul */
249#myUL {
250 margin: 0;
251 padding: 0;
252}
253
254/* Style the caret/arrow */
255.caret {
256 cursor: pointer;
257 user-select: none; /* Prevent text selection */
258}
259
260/* Create the caret/arrow with a unicode, and style it */
261.caret::before {
262 content: "\\25B6";
263 color: black;
264 display: inline-block;
265 margin-right: 6px;
266}
267
268/* Rotate the caret/arrow icon when clicked on (using JavaScript) */
269.caret-down::before {
270 transform: rotate(90deg);
271}
272
273/* Hide the nested list */
274.nested {
275 display: none;
276}
277
278/* Show the nested list when the user clicks on the caret/arrow (with JavaScript) */
279.active {
280 display: block;
281}
282
283</style>
284"""
285
286script="""<script type="text/javascript">
287var toggler = document.getElementsByClassName("caret");
288var i;
289for (i = 0; i < toggler.length; i++) {
290 toggler[i].addEventListener("click", function() {
291 this.parentElement.querySelector(".nested").classList.toggle("active");
292 this.classList.toggle("caret-down");
293 });
294}</script>"""
295
296
297class HTMLToc:
298 def __init__(self,output):
299 self._id=0
300 self._sectionID = 0
301 self._output = output
302
303
304
305 def visitTable(self,table):
306 pass
307
308
309 def visitSection(self,section):
310 self._id = self._id + 1
311 self._sectionID = self._sectionID + 1
312 if section.hasChildren:
313 self._output.write("<li><span class=\"caret\"><a href=\"#section%d\">%s</a></span>\n" % (self._sectionID,section.name))
314 self._output.write("<ul class=\"nested\">\n")
315 else:
316 self._output.write("<li><span><a href=\"#section%d\">%s</a></span>\n" % (self._sectionID,section.name))
317
318 def leaveSection(self,section):
319 if section.hasChildren:
320 self._output.write("</ul></li>\n")
321
322 self._id = self._id - 1
323
324 def visitDocument(self,document):
325 self._output.write("<div id=\"TOC\"><h1>Table of content</h1><ul id=\"myUL\">\n")
326
327
328 def leaveDocument(self,document):
329 self._output.write("</ul></div>%s\n" % script)
330
331
332class HTML:
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200333 def __init__(self,output,regMode):
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200334 self._id=0
335 self._sectionID = 0
336 self._output = output
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200337 self._regMode = regMode
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200338
339
340
341 def visitTable(self,table):
342 output.write("<table>\n")
343 output.write("<thead>\n")
344 output.write("<tr>\n")
345 for col in table.columns:
346 output.write("<th>")
347 output.write(str(col))
348 output.write("</th>\n")
349 output.write("</tr>\n")
350 output.write("</thead>\n")
351 for row in table.rows:
352 output.write("<tr>\n")
353 for elem in row:
354 output.write("<td>")
355 output.write(str(elem))
356 output.write("</td>\n")
357 output.write("</tr>\n")
358 output.write("</table>\n")
359
360
361 def visitSection(self,section):
362 self._id = self._id + 1
363 self._sectionID = self._sectionID + 1
364 output.write("<h%d id=\"section%d\">%s</h%d>\n" % (self._id,self._sectionID,section.name,self._id))
365
366 def leaveSection(self,section):
367 self._id = self._id - 1
368
369 def visitDocument(self,document):
370 self._output.write("""<!doctype html>
371<html>
372<head>
373<meta charset='UTF-8'><meta name='viewport' content='width=device-width initial-scale=1'>
374<title>Benchmarks</title>%s</head><body>\n""" % styleSheet)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200375 if self._regMode:
376 self._output.write("<h1>ECPS Benchmark Regressions</h1>\n")
377 else:
378 self._output.write("<h1>ECPS Benchmark Summary</h1>\n")
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200379 self._output.write("<p>Run number %d on %s</p>\n" % (document.runid, str(document.date)))
380
381 def leaveDocument(self,document):
382 document.accept(HTMLToc(self._output))
383
384 self._output.write("</body></html>\n")
385
386
387
388
389
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200390# Command to get last runid
391lastID="""SELECT runid FROM RUN ORDER BY runid DESC LIMIT 1
392"""
393
Christophe Favergeone15894e2020-05-14 07:25:53 +0200394# Command to get last runid and date
395lastIDAndDate="""SELECT date FROM RUN WHERE runid=?
396"""
397
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200398def getLastRunID():
399 r=c.execute(lastID)
400 return(int(r.fetchone()[0]))
401
Christophe Favergeone15894e2020-05-14 07:25:53 +0200402def getrunIDDate(forID):
403 r=c.execute(lastIDAndDate,(forID,))
404 return(r.fetchone()[0])
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200405
406runid = 1
407
408parser = argparse.ArgumentParser(description='Generate summary benchmarks')
409
410parser.add_argument('-b', nargs='?',type = str, default="bench.db", help="Benchmark database")
411parser.add_argument('-o', nargs='?',type = str, default="full.md", help="Full summary")
412parser.add_argument('-r', action='store_true', help="Regression database")
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200413parser.add_argument('-t', nargs='?',type = str, default="md", help="md,html")
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200414
415# For runid or runid range
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200416parser.add_argument('others', nargs=argparse.REMAINDER,help="Run ID")
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200417
418args = parser.parse_args()
419
420c = sqlite3.connect(args.b)
421
422if args.others:
423 runid=int(args.others[0])
424else:
425 runid=getLastRunID()
426
427# We extract data only from data tables
428# Those tables below are used for descriptions
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200429REMOVETABLES=['TESTNAME','TESTDATE','RUN','CORE', 'PLATFORM', 'COMPILERKIND', 'COMPILER', 'TYPE', 'CATEGORY', 'CONFIG']
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200430
431# This is assuming the database is generated by the regression script
432# So platform is the same for all benchmarks.
433# Category and type is coming from the test name in the yaml
434# So no need to add this information here
435# Name is removed here because it is added at the beginning
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200436REMOVECOLUMNS=['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 +0200437
438# Get existing benchmark tables
439def getBenchTables():
440 r=c.execute("SELECT name FROM sqlite_master WHERE type='table'")
441 benchtables=[]
442 for table in r:
443 if not table[0] in REMOVETABLES:
444 benchtables.append(table[0])
445 return(benchtables)
446
447# get existing types in a table
448def getExistingTypes(benchTable):
Christophe Favergeone15894e2020-05-14 07:25:53 +0200449 r=c.execute("select distinct typeid from %s order by typeid desc" % benchTable).fetchall()
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200450 result=[x[0] for x in r]
451 return(result)
452
453# Get compilers from specific type and table
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200454allCompilers="""select distinct compilerid from %s WHERE typeid=?"""
455
456compilerDesc="""select compiler,version from COMPILER
457 INNER JOIN COMPILERKIND USING(compilerkindid) WHERE compilerid=?"""
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200458
459# Get existing compiler in a table for a specific type
460# (In case report is structured by types)
461def getExistingCompiler(benchTable,typeid):
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200462 r=c.execute(allCompilers % benchTable,(typeid,)).fetchall()
463 return([x[0] for x in r])
464
465def getCompilerDesc(compilerid):
466 r=c.execute(compilerDesc,(compilerid,)).fetchone()
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200467 return(r)
468
469# Get type name from type id
470def getTypeName(typeid):
471 r=c.execute("select type from TYPE where typeid=?",(typeid,)).fetchone()
472 return(r[0])
473
474# Diff of 2 lists
475def diff(first, second):
476 second = set(second)
477 return [item for item in first if item not in second]
478
479
480# Command to get data for specific compiler
481# and type
482benchCmd="""select %s from %s
483 INNER JOIN CATEGORY USING(categoryid)
484 INNER JOIN PLATFORM USING(platformid)
485 INNER JOIN CORE USING(coreid)
486 INNER JOIN COMPILER USING(compilerid)
487 INNER JOIN COMPILERKIND USING(compilerkindid)
488 INNER JOIN TYPE USING(typeid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200489 INNER JOIN TESTNAME USING(testnameid)
490 WHERE compilerid=? AND typeid = ? AND runid = ?
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200491 """
492
Christophe Favergeon4f750702020-05-13 15:56:15 +0200493
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200494# Command to get test names for specific compiler
495# and type
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200496benchNames="""select distinct name from %s
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200497 INNER JOIN COMPILER USING(compilerid)
498 INNER JOIN COMPILERKIND USING(compilerkindid)
499 INNER JOIN TYPE USING(typeid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200500 INNER JOIN TESTNAME USING(testnameid)
501 WHERE compilerid=? AND typeid = ? AND runid = ?
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200502 """
503
504# Command to get columns for specific table
505benchCmdColumns="""select * from %s
506 INNER JOIN CATEGORY USING(categoryid)
507 INNER JOIN PLATFORM USING(platformid)
508 INNER JOIN CORE USING(coreid)
509 INNER JOIN COMPILER USING(compilerid)
510 INNER JOIN COMPILERKIND USING(compilerkindid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200511 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200512 INNER JOIN TYPE USING(typeid)
513 """
514
515def joinit(iterable, delimiter):
516 it = iter(iterable)
517 yield next(it)
518 for x in it:
519 yield delimiter
520 yield x
521
522# Is not a column name finishing by id
523# (often primary key for thetable)
524def isNotIDColumn(col):
525 if re.match(r'^.*id$',col):
526 return(False)
527 else:
528 return(True)
529
530# Get test names
531# for specific typeid and compiler (for the data)
532def getTestNames(benchTable,comp,typeid):
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200533 vals=(comp,typeid,runid)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200534 result=c.execute(benchNames % benchTable,vals).fetchall()
535 return([x[0] for x in list(result)])
536
Christophe Favergeone15894e2020-05-14 07:25:53 +0200537# Command to get data for specific compiler
538# and type
539nbElemsInBenchAndTypeAndCompilerCmd="""select count(*) from %s
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200540 WHERE compilerid=? AND typeid = ? AND runid = ?
Christophe Favergeone15894e2020-05-14 07:25:53 +0200541 """
542
543nbElemsInBenchAndTypeCmd="""select count(*) from %s
Christophe Favergeone15894e2020-05-14 07:25:53 +0200544 WHERE typeid = ? AND runid = ?
545 """
546
547nbElemsInBenchCmd="""select count(*) from %s
Christophe Favergeone15894e2020-05-14 07:25:53 +0200548 WHERE runid = ?
549 """
550
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200551categoryName="""select distinct category from %s
552 INNER JOIN CATEGORY USING(categoryid)
553 WHERE runid = ?
554 """
555
556def getCategoryName(benchTable,runid):
557 result=c.execute(categoryName % benchTable,(runid,)).fetchone()
558 return(result[0])
559
Christophe Favergeon4f750702020-05-13 15:56:15 +0200560# Get nb elems in a table
Christophe Favergeone15894e2020-05-14 07:25:53 +0200561def getNbElemsInBenchAndTypeAndCompilerCmd(benchTable,comp,typeid):
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200562 vals=(comp,typeid,runid)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200563 result=c.execute(nbElemsInBenchAndTypeAndCompilerCmd % benchTable,vals).fetchone()
564 return(result[0])
565
566def getNbElemsInBenchAndTypeCmd(benchTable,typeid):
567 vals=(typeid,runid)
568 result=c.execute(nbElemsInBenchAndTypeCmd % benchTable,vals).fetchone()
569 return(result[0])
570
571def getNbElemsInBenchCmd(benchTable):
572 vals=(runid,)
573 result=c.execute(nbElemsInBenchCmd % benchTable,vals).fetchone()
Christophe Favergeon4f750702020-05-13 15:56:15 +0200574 return(result[0])
575
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200576# Get names of columns and data for a table
577# for specific typeid and compiler (for the data)
578def getColNamesAndData(benchTable,comp,typeid):
579 cursor=c.cursor()
580 result=cursor.execute(benchCmdColumns % (benchTable))
581 cols= [member[0] for member in cursor.description]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200582 keepCols = ['name'] + [c for c in diff(cols , REMOVECOLUMNS) if isNotIDColumn(c)]
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200583 keepColsStr = "".join(joinit(keepCols,","))
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200584 vals=(comp,typeid,runid)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200585 result=cursor.execute(benchCmd % (keepColsStr,benchTable),vals)
586 vals =np.array([list(x) for x in list(result)])
587 return(keepCols,vals)
588
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200589
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200590
591PARAMS=["NB","NumTaps", "NBA", "NBB", "Factor", "NumStages","VECDIM","NBR","NBC","NBI","IFFT", "BITREV"]
592
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200593def regressionTableFor(name,section,ref,toSort,indexCols,field):
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200594 data=ref.pivot_table(index=indexCols, columns='core',
595 values=[field], aggfunc='first')
596
597 data=data.sort_values(toSort)
598
599 cores = [c[1] for c in list(data.columns)]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200600 columns = diff(indexCols,['name'])
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200601
Christophe Favergeon34d313a2020-05-14 15:09:41 +0200602 dataTable=Table(columns,cores)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200603 section.addTable(dataTable)
604
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200605 dataForFunc=data.loc[name]
606 if type(dataForFunc) is pd.DataFrame:
607 for row in dataForFunc.itertuples():
608 row=list(row)
609 if type(row[0]) is int:
610 row=[row[0]] + row[1:]
611 else:
612 row=list(row[0]) + row[1:]
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200613 dataTable.addRow(row)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200614 else:
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200615 dataTable.addRow(dataForFunc)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200616
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200617def formatTableByCore(typeSection,testNames,cols,vals):
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200618 if vals.size != 0:
619 ref=pd.DataFrame(vals,columns=cols)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200620 toSort=["name"]
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200621
622 for param in PARAMS:
623 if param in ref.columns:
624 ref[param]=pd.to_numeric(ref[param])
625 toSort.append(param)
626 if args.r:
627 # Regression table
628 ref['MAX']=pd.to_numeric(ref['MAX'])
629 ref['MAXREGCOEF']=pd.to_numeric(ref['MAXREGCOEF'])
630
631 indexCols=diff(cols,['core','Regression','MAXREGCOEF','MAX','version','compiler'])
632 valList = ['Regression']
633 else:
634 ref['CYCLES']=pd.to_numeric(ref['CYCLES'])
635
636 indexCols=diff(cols,['core','CYCLES','version','compiler'])
637 valList = ['CYCLES']
638
639
640
641 for name in testNames:
642 if args.r:
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200643 testSection = Section(name)
644 typeSection.addSection(testSection)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200645
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200646 regressionSection = Section("Regression")
647 testSection.addSection(regressionSection)
648 regressionTableFor(name,regressionSection,ref,toSort,indexCols,'Regression')
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200649
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200650 maxCyclesSection = Section("Max cycles")
651 testSection.addSection(maxCyclesSection)
652 regressionTableFor(name,maxCyclesSection,ref,toSort,indexCols,'MAX')
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200653
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200654 maxRegCoefSection = Section("Max Reg Coef")
655 testSection.addSection(maxRegCoefSection)
656 regressionTableFor(name,maxRegCoefSection,ref,toSort,indexCols,'MAXREGCOEF')
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200657
658 else:
659 data=ref.pivot_table(index=indexCols, columns='core',
660 values=valList, aggfunc='first')
661
662 data=data.sort_values(toSort)
663
664 cores = [c[1] for c in list(data.columns)]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200665 columns = diff(indexCols,['name'])
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200666
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200667 testSection = Section(name)
668 typeSection.addSection(testSection)
669
Christophe Favergeon34d313a2020-05-14 15:09:41 +0200670 dataTable=Table(columns,cores)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200671 testSection.addTable(dataTable)
672
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200673 dataForFunc=data.loc[name]
674 if type(dataForFunc) is pd.DataFrame:
675 for row in dataForFunc.itertuples():
676 row=list(row)
677 if type(row[0]) is int:
678 row=[row[0]] + row[1:]
679 else:
680 row=list(row[0]) + row[1:]
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200681 dataTable.addRow(row)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200682 else:
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200683 dataTable.addRow(dataForFunc)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200684
685# Add a report for each table
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200686def addReportFor(document,benchName):
Christophe Favergeone15894e2020-05-14 07:25:53 +0200687 nbElems = getNbElemsInBenchCmd(benchName)
688 if nbElems > 0:
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200689 categoryName = getCategoryName(benchName,document.runid)
690 benchSection = Section(categoryName)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200691 document.addSection(benchSection)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200692 print("Process %s\n" % benchName)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200693 allTypes = getExistingTypes(benchName)
694 # Add report for each type
695 for aTypeID in allTypes:
696 nbElems = getNbElemsInBenchAndTypeCmd(benchName,aTypeID)
697 if nbElems > 0:
698 typeName = getTypeName(aTypeID)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200699 typeSection = Section(typeName)
700 benchSection.addSection(typeSection)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200701 ## Add report for each compiler
702 allCompilers = getExistingCompiler(benchName,aTypeID)
703 for compiler in allCompilers:
704 #print(compiler)
705 nbElems = getNbElemsInBenchAndTypeAndCompilerCmd(benchName,compiler,aTypeID)
706 # Print test results for table, type, compiler
707 if nbElems > 0:
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200708 compilerName,version=getCompilerDesc(compiler)
709 compilerSection = Section("%s (%s)" % (compilerName,version))
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200710 typeSection.addSection(compilerSection)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200711 cols,vals=getColNamesAndData(benchName,compiler,aTypeID)
712 names=getTestNames(benchName,compiler,aTypeID)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200713 formatTableByCore(compilerSection,names,cols,vals)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200714
715
716
717
718
719try:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200720 benchtables=getBenchTables()
Christophe Favergeone15894e2020-05-14 07:25:53 +0200721 theDate = getrunIDDate(runid)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200722 document = Document(runid,theDate)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200723 for bench in benchtables:
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200724 addReportFor(document,bench)
725 with open(args.o,"w") as output:
726 if args.t=="md":
727 document.accept(Markdown(output))
728 if args.t=="html":
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200729 document.accept(HTML(output,args.r))
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200730
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200731finally:
732 c.close()
733
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200734
735
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200736