Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 1 | import argparse |
| 2 | import sqlite3 |
| 3 | import re |
| 4 | import pandas as pd |
| 5 | import numpy as np |
| 6 | |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 7 | class Document: |
| 8 | def __init__(self,runid,date): |
| 9 | self._runid = runid |
| 10 | self._date = date |
| 11 | self._sections = [] |
| 12 | |
| 13 | @property |
| 14 | def runid(self): |
| 15 | return(self._runid) |
| 16 | |
| 17 | @property |
| 18 | def date(self): |
| 19 | return(self._date) |
| 20 | |
| 21 | @property |
| 22 | def sections(self): |
| 23 | return(self._sections) |
| 24 | |
| 25 | def addSection(self,section): |
| 26 | self._sections.append(section) |
| 27 | |
| 28 | def accept(self, visitor): |
| 29 | visitor.visitDocument(self) |
| 30 | for element in self._sections: |
| 31 | element.accept(visitor) |
| 32 | visitor.leaveDocument(self) |
| 33 | |
| 34 | class Section: |
| 35 | def __init__(self,name): |
| 36 | self._name=name |
| 37 | self._subsections = [] |
| 38 | self._tables = [] |
| 39 | |
| 40 | def addSection(self,section): |
| 41 | self._subsections.append(section) |
| 42 | |
| 43 | def addTable(self,table): |
| 44 | self._tables.append(table) |
| 45 | |
| 46 | @property |
| 47 | def hasChildren(self): |
| 48 | return(len(self._subsections)>0) |
| 49 | |
| 50 | @property |
| 51 | def name(self): |
| 52 | return(self._name) |
| 53 | |
| 54 | def accept(self, visitor): |
| 55 | visitor.visitSection(self) |
| 56 | for element in self._subsections: |
| 57 | element.accept(visitor) |
| 58 | for element in self._tables: |
| 59 | element.accept(visitor) |
| 60 | visitor.leaveSection(self) |
| 61 | |
| 62 | class Table: |
| 63 | def __init__(self,columns): |
| 64 | self._columns=columns |
| 65 | self._rows=[] |
| 66 | |
| 67 | def addRow(self,row): |
| 68 | self._rows.append(row) |
| 69 | |
| 70 | @property |
| 71 | def columns(self): |
| 72 | return(self._columns) |
| 73 | |
| 74 | @property |
| 75 | def rows(self): |
| 76 | return(self._rows) |
| 77 | |
| 78 | def accept(self, visitor): |
| 79 | visitor.visitTable(self) |
| 80 | |
| 81 | |
| 82 | |
| 83 | class Markdown: |
| 84 | def __init__(self,output): |
| 85 | self._id=0 |
| 86 | self._output = output |
| 87 | |
| 88 | # Write columns in markdown format |
| 89 | def writeColumns(self,cols): |
| 90 | colStr = "".join(joinit(cols,"|")) |
| 91 | self._output.write("|") |
| 92 | self._output.write(colStr) |
| 93 | self._output.write("|\n") |
| 94 | sepStr="".join(joinit([":-:" for x in cols],"|")) |
| 95 | self._output.write("|") |
| 96 | self._output.write(sepStr) |
| 97 | self._output.write("|\n") |
| 98 | |
| 99 | # Write row in markdown format |
| 100 | def writeRow(self,row): |
| 101 | row=[str(x) for x in row] |
| 102 | rowStr = "".join(joinit(row,"|")) |
| 103 | self._output.write("|") |
| 104 | self._output.write(rowStr) |
| 105 | self._output.write("|\n") |
| 106 | |
| 107 | def visitTable(self,table): |
| 108 | self.writeColumns(table.columns) |
| 109 | for row in table.rows: |
| 110 | self.writeRow(row) |
| 111 | |
| 112 | def visitSection(self,section): |
| 113 | self._id = self._id + 1 |
| 114 | header = "".join(["#" for i in range(self._id)]) |
| 115 | output.write("%s %s\n" % (header,section.name)) |
| 116 | |
| 117 | def leaveSection(self,section): |
| 118 | self._id = self._id - 1 |
| 119 | |
| 120 | def visitDocument(self,document): |
| 121 | self._output.write("Run number %d on %s\n" % (document.runid, str(document.date))) |
| 122 | |
| 123 | def leaveDocument(self,document): |
| 124 | pass |
| 125 | |
| 126 | styleSheet=""" |
| 127 | <style type='text/css'> |
| 128 | |
| 129 | #TOC { |
| 130 | position: fixed; |
| 131 | left: 0; |
| 132 | top: 0; |
| 133 | width: 250px; |
| 134 | height: 100%; |
| 135 | overflow:auto; |
| 136 | } |
| 137 | |
| 138 | html { |
| 139 | font-size: 16px; |
| 140 | } |
| 141 | |
| 142 | html, body { |
| 143 | background-color: #f3f2ee; |
| 144 | font-family: "PT Serif", 'Times New Roman', Times, serif; |
| 145 | color: #1f0909; |
| 146 | line-height: 1.5em; |
| 147 | |
| 148 | margin: auto; |
| 149 | margin-left:220px; |
| 150 | } |
| 151 | |
| 152 | |
| 153 | table { |
| 154 | border-collapse: collapse; |
| 155 | border-spacing: 0; |
| 156 | width: 100%; |
| 157 | } |
| 158 | |
| 159 | h1, |
| 160 | h2, |
| 161 | h3, |
| 162 | h4, |
| 163 | h5, |
| 164 | h6 { |
| 165 | font-weight: bold; |
| 166 | } |
| 167 | h1 { |
| 168 | font-size: 1.875em; |
| 169 | line-height: 1.6em; |
| 170 | margin-top: 1em; |
| 171 | } |
| 172 | h2, |
| 173 | h3 { |
| 174 | font-size: 1.3125em; |
| 175 | line-height: 1.15; |
| 176 | margin-top: 2.285714em; |
| 177 | margin-bottom: 1.15em; |
| 178 | } |
| 179 | h4 { |
| 180 | font-size: 1.125em; |
| 181 | margin-top: 2.67em; |
| 182 | } |
| 183 | h5, |
| 184 | h6 { |
| 185 | font-size: 1em; |
| 186 | } |
| 187 | |
| 188 | |
| 189 | table { |
| 190 | margin-bottom: 1.5em; |
| 191 | /*24 / 16*/ |
| 192 | font-size: 1em; |
| 193 | /* width: 100%; */ |
| 194 | } |
| 195 | thead th, |
| 196 | tfoot th { |
| 197 | padding: .25em .25em .25em .4em; |
| 198 | text-transform: uppercase; |
| 199 | } |
| 200 | th { |
| 201 | text-align: left; |
| 202 | } |
| 203 | td { |
| 204 | vertical-align: top; |
| 205 | padding: .25em .25em .25em .4em; |
| 206 | } |
| 207 | |
| 208 | .ty-table-edit { |
| 209 | background-color: transparent; |
| 210 | } |
| 211 | thead { |
| 212 | background-color: #dadada; |
| 213 | } |
| 214 | tr:nth-child(even) { |
| 215 | background: #e8e7e7; |
| 216 | } |
| 217 | |
| 218 | ul, #myUL { |
| 219 | list-style-type: none; |
| 220 | padding-inline-start:10px; |
| 221 | } |
| 222 | |
| 223 | |
| 224 | |
| 225 | /* Remove margins and padding from the parent ul */ |
| 226 | #myUL { |
| 227 | margin: 0; |
| 228 | padding: 0; |
| 229 | } |
| 230 | |
| 231 | /* Style the caret/arrow */ |
| 232 | .caret { |
| 233 | cursor: pointer; |
| 234 | user-select: none; /* Prevent text selection */ |
| 235 | } |
| 236 | |
| 237 | /* Create the caret/arrow with a unicode, and style it */ |
| 238 | .caret::before { |
| 239 | content: "\\25B6"; |
| 240 | color: black; |
| 241 | display: inline-block; |
| 242 | margin-right: 6px; |
| 243 | } |
| 244 | |
| 245 | /* Rotate the caret/arrow icon when clicked on (using JavaScript) */ |
| 246 | .caret-down::before { |
| 247 | transform: rotate(90deg); |
| 248 | } |
| 249 | |
| 250 | /* Hide the nested list */ |
| 251 | .nested { |
| 252 | display: none; |
| 253 | } |
| 254 | |
| 255 | /* Show the nested list when the user clicks on the caret/arrow (with JavaScript) */ |
| 256 | .active { |
| 257 | display: block; |
| 258 | } |
| 259 | |
| 260 | </style> |
| 261 | """ |
| 262 | |
| 263 | script="""<script type="text/javascript"> |
| 264 | var toggler = document.getElementsByClassName("caret"); |
| 265 | var i; |
| 266 | for (i = 0; i < toggler.length; i++) { |
| 267 | toggler[i].addEventListener("click", function() { |
| 268 | this.parentElement.querySelector(".nested").classList.toggle("active"); |
| 269 | this.classList.toggle("caret-down"); |
| 270 | }); |
| 271 | }</script>""" |
| 272 | |
| 273 | |
| 274 | class HTMLToc: |
| 275 | def __init__(self,output): |
| 276 | self._id=0 |
| 277 | self._sectionID = 0 |
| 278 | self._output = output |
| 279 | |
| 280 | |
| 281 | |
| 282 | def visitTable(self,table): |
| 283 | pass |
| 284 | |
| 285 | |
| 286 | def visitSection(self,section): |
| 287 | self._id = self._id + 1 |
| 288 | self._sectionID = self._sectionID + 1 |
| 289 | if section.hasChildren: |
| 290 | self._output.write("<li><span class=\"caret\"><a href=\"#section%d\">%s</a></span>\n" % (self._sectionID,section.name)) |
| 291 | self._output.write("<ul class=\"nested\">\n") |
| 292 | else: |
| 293 | self._output.write("<li><span><a href=\"#section%d\">%s</a></span>\n" % (self._sectionID,section.name)) |
| 294 | |
| 295 | def leaveSection(self,section): |
| 296 | if section.hasChildren: |
| 297 | self._output.write("</ul></li>\n") |
| 298 | |
| 299 | self._id = self._id - 1 |
| 300 | |
| 301 | def visitDocument(self,document): |
| 302 | self._output.write("<div id=\"TOC\"><h1>Table of content</h1><ul id=\"myUL\">\n") |
| 303 | |
| 304 | |
| 305 | def leaveDocument(self,document): |
| 306 | self._output.write("</ul></div>%s\n" % script) |
| 307 | |
| 308 | |
| 309 | class HTML: |
| 310 | def __init__(self,output): |
| 311 | self._id=0 |
| 312 | self._sectionID = 0 |
| 313 | self._output = output |
| 314 | |
| 315 | |
| 316 | |
| 317 | def visitTable(self,table): |
| 318 | output.write("<table>\n") |
| 319 | output.write("<thead>\n") |
| 320 | output.write("<tr>\n") |
| 321 | for col in table.columns: |
| 322 | output.write("<th>") |
| 323 | output.write(str(col)) |
| 324 | output.write("</th>\n") |
| 325 | output.write("</tr>\n") |
| 326 | output.write("</thead>\n") |
| 327 | for row in table.rows: |
| 328 | output.write("<tr>\n") |
| 329 | for elem in row: |
| 330 | output.write("<td>") |
| 331 | output.write(str(elem)) |
| 332 | output.write("</td>\n") |
| 333 | output.write("</tr>\n") |
| 334 | output.write("</table>\n") |
| 335 | |
| 336 | |
| 337 | def visitSection(self,section): |
| 338 | self._id = self._id + 1 |
| 339 | self._sectionID = self._sectionID + 1 |
| 340 | output.write("<h%d id=\"section%d\">%s</h%d>\n" % (self._id,self._sectionID,section.name,self._id)) |
| 341 | |
| 342 | def leaveSection(self,section): |
| 343 | self._id = self._id - 1 |
| 344 | |
| 345 | def visitDocument(self,document): |
| 346 | self._output.write("""<!doctype html> |
| 347 | <html> |
| 348 | <head> |
| 349 | <meta charset='UTF-8'><meta name='viewport' content='width=device-width initial-scale=1'> |
| 350 | <title>Benchmarks</title>%s</head><body>\n""" % styleSheet) |
| 351 | self._output.write("<p>Run number %d on %s</p>\n" % (document.runid, str(document.date))) |
| 352 | |
| 353 | def leaveDocument(self,document): |
| 354 | document.accept(HTMLToc(self._output)) |
| 355 | |
| 356 | self._output.write("</body></html>\n") |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 362 | # Command to get last runid |
| 363 | lastID="""SELECT runid FROM RUN ORDER BY runid DESC LIMIT 1 |
| 364 | """ |
| 365 | |
Christophe Favergeon | e15894e | 2020-05-14 07:25:53 +0200 | [diff] [blame] | 366 | # Command to get last runid and date |
| 367 | lastIDAndDate="""SELECT date FROM RUN WHERE runid=? |
| 368 | """ |
| 369 | |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 370 | def getLastRunID(): |
| 371 | r=c.execute(lastID) |
| 372 | return(int(r.fetchone()[0])) |
| 373 | |
Christophe Favergeon | e15894e | 2020-05-14 07:25:53 +0200 | [diff] [blame] | 374 | def getrunIDDate(forID): |
| 375 | r=c.execute(lastIDAndDate,(forID,)) |
| 376 | return(r.fetchone()[0]) |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 377 | |
| 378 | runid = 1 |
| 379 | |
| 380 | parser = argparse.ArgumentParser(description='Generate summary benchmarks') |
| 381 | |
| 382 | parser.add_argument('-b', nargs='?',type = str, default="bench.db", help="Benchmark database") |
| 383 | parser.add_argument('-o', nargs='?',type = str, default="full.md", help="Full summary") |
| 384 | parser.add_argument('-r', action='store_true', help="Regression database") |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 385 | parser.add_argument('-t', nargs='?',type = str, default="md", help="md,html") |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 386 | |
| 387 | # For runid or runid range |
| 388 | parser.add_argument('others', nargs=argparse.REMAINDER) |
| 389 | |
| 390 | args = parser.parse_args() |
| 391 | |
| 392 | c = sqlite3.connect(args.b) |
| 393 | |
| 394 | if args.others: |
| 395 | runid=int(args.others[0]) |
| 396 | else: |
| 397 | runid=getLastRunID() |
| 398 | |
| 399 | # We extract data only from data tables |
| 400 | # Those tables below are used for descriptions |
| 401 | REMOVETABLES=['RUN','CORE', 'PLATFORM', 'COMPILERKIND', 'COMPILER', 'TYPE', 'CATEGORY', 'CONFIG'] |
| 402 | |
| 403 | # This is assuming the database is generated by the regression script |
| 404 | # So platform is the same for all benchmarks. |
| 405 | # Category and type is coming from the test name in the yaml |
| 406 | # So no need to add this information here |
| 407 | # Name is removed here because it is added at the beginning |
| 408 | REMOVECOLUMNS=['runid','NAME','type','platform','category','coredef','OPTIMIZED','HARDFP','FASTMATH','NEON','HELIUM','UNROLL','ROUNDING','DATE','compilerkindid','date','categoryid', 'ID', 'platformid', 'coreid', 'compilerid', 'typeid'] |
| 409 | |
| 410 | # Get existing benchmark tables |
| 411 | def getBenchTables(): |
| 412 | r=c.execute("SELECT name FROM sqlite_master WHERE type='table'") |
| 413 | benchtables=[] |
| 414 | for table in r: |
| 415 | if not table[0] in REMOVETABLES: |
| 416 | benchtables.append(table[0]) |
| 417 | return(benchtables) |
| 418 | |
| 419 | # get existing types in a table |
| 420 | def getExistingTypes(benchTable): |
Christophe Favergeon | e15894e | 2020-05-14 07:25:53 +0200 | [diff] [blame] | 421 | r=c.execute("select distinct typeid from %s order by typeid desc" % benchTable).fetchall() |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 422 | result=[x[0] for x in r] |
| 423 | return(result) |
| 424 | |
| 425 | # Get compilers from specific type and table |
| 426 | versioncompiler="""select distinct compiler,version from %s |
| 427 | INNER JOIN COMPILER USING(compilerid) |
| 428 | INNER JOIN COMPILERKIND USING(compilerkindid) WHERE typeid=?""" |
| 429 | |
| 430 | # Get existing compiler in a table for a specific type |
| 431 | # (In case report is structured by types) |
| 432 | def getExistingCompiler(benchTable,typeid): |
| 433 | r=c.execute(versioncompiler % benchTable,(typeid,)).fetchall() |
| 434 | return(r) |
| 435 | |
| 436 | # Get type name from type id |
| 437 | def getTypeName(typeid): |
| 438 | r=c.execute("select type from TYPE where typeid=?",(typeid,)).fetchone() |
| 439 | return(r[0]) |
| 440 | |
| 441 | # Diff of 2 lists |
| 442 | def diff(first, second): |
| 443 | second = set(second) |
| 444 | return [item for item in first if item not in second] |
| 445 | |
| 446 | |
| 447 | # Command to get data for specific compiler |
| 448 | # and type |
| 449 | benchCmd="""select %s from %s |
| 450 | INNER JOIN CATEGORY USING(categoryid) |
| 451 | INNER JOIN PLATFORM USING(platformid) |
| 452 | INNER JOIN CORE USING(coreid) |
| 453 | INNER JOIN COMPILER USING(compilerid) |
| 454 | INNER JOIN COMPILERKIND USING(compilerkindid) |
| 455 | INNER JOIN TYPE USING(typeid) |
| 456 | WHERE compiler=? AND VERSION=? AND typeid = ? AND runid = ? |
| 457 | """ |
| 458 | |
Christophe Favergeon | 4f75070 | 2020-05-13 15:56:15 +0200 | [diff] [blame] | 459 | |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 460 | # Command to get test names for specific compiler |
| 461 | # and type |
| 462 | benchNames="""select distinct NAME from %s |
| 463 | INNER JOIN COMPILER USING(compilerid) |
| 464 | INNER JOIN COMPILERKIND USING(compilerkindid) |
| 465 | INNER JOIN TYPE USING(typeid) |
| 466 | WHERE compiler=? AND VERSION=? AND typeid = ? AND runid = ? |
| 467 | """ |
| 468 | |
| 469 | # Command to get columns for specific table |
| 470 | benchCmdColumns="""select * from %s |
| 471 | INNER JOIN CATEGORY USING(categoryid) |
| 472 | INNER JOIN PLATFORM USING(platformid) |
| 473 | INNER JOIN CORE USING(coreid) |
| 474 | INNER JOIN COMPILER USING(compilerid) |
| 475 | INNER JOIN COMPILERKIND USING(compilerkindid) |
| 476 | INNER JOIN TYPE USING(typeid) |
| 477 | """ |
| 478 | |
| 479 | def joinit(iterable, delimiter): |
| 480 | it = iter(iterable) |
| 481 | yield next(it) |
| 482 | for x in it: |
| 483 | yield delimiter |
| 484 | yield x |
| 485 | |
| 486 | # Is not a column name finishing by id |
| 487 | # (often primary key for thetable) |
| 488 | def isNotIDColumn(col): |
| 489 | if re.match(r'^.*id$',col): |
| 490 | return(False) |
| 491 | else: |
| 492 | return(True) |
| 493 | |
| 494 | # Get test names |
| 495 | # for specific typeid and compiler (for the data) |
| 496 | def getTestNames(benchTable,comp,typeid): |
| 497 | vals=(comp[0],comp[1],typeid,runid) |
| 498 | result=c.execute(benchNames % benchTable,vals).fetchall() |
| 499 | return([x[0] for x in list(result)]) |
| 500 | |
Christophe Favergeon | e15894e | 2020-05-14 07:25:53 +0200 | [diff] [blame] | 501 | # Command to get data for specific compiler |
| 502 | # and type |
| 503 | nbElemsInBenchAndTypeAndCompilerCmd="""select count(*) from %s |
| 504 | INNER JOIN CATEGORY USING(categoryid) |
| 505 | INNER JOIN PLATFORM USING(platformid) |
| 506 | INNER JOIN CORE USING(coreid) |
| 507 | INNER JOIN COMPILER USING(compilerid) |
| 508 | INNER JOIN COMPILERKIND USING(compilerkindid) |
| 509 | INNER JOIN TYPE USING(typeid) |
| 510 | WHERE compiler=? AND VERSION=? AND typeid = ? AND runid = ? |
| 511 | """ |
| 512 | |
| 513 | nbElemsInBenchAndTypeCmd="""select count(*) from %s |
| 514 | INNER JOIN CATEGORY USING(categoryid) |
| 515 | INNER JOIN PLATFORM USING(platformid) |
| 516 | INNER JOIN CORE USING(coreid) |
| 517 | INNER JOIN COMPILER USING(compilerid) |
| 518 | INNER JOIN COMPILERKIND USING(compilerkindid) |
| 519 | INNER JOIN TYPE USING(typeid) |
| 520 | WHERE typeid = ? AND runid = ? |
| 521 | """ |
| 522 | |
| 523 | nbElemsInBenchCmd="""select count(*) from %s |
| 524 | INNER JOIN CATEGORY USING(categoryid) |
| 525 | INNER JOIN PLATFORM USING(platformid) |
| 526 | INNER JOIN CORE USING(coreid) |
| 527 | INNER JOIN COMPILER USING(compilerid) |
| 528 | INNER JOIN COMPILERKIND USING(compilerkindid) |
| 529 | INNER JOIN TYPE USING(typeid) |
| 530 | WHERE runid = ? |
| 531 | """ |
| 532 | |
Christophe Favergeon | 4f75070 | 2020-05-13 15:56:15 +0200 | [diff] [blame] | 533 | # Get nb elems in a table |
Christophe Favergeon | e15894e | 2020-05-14 07:25:53 +0200 | [diff] [blame] | 534 | def getNbElemsInBenchAndTypeAndCompilerCmd(benchTable,comp,typeid): |
Christophe Favergeon | 4f75070 | 2020-05-13 15:56:15 +0200 | [diff] [blame] | 535 | vals=(comp[0],comp[1],typeid,runid) |
Christophe Favergeon | e15894e | 2020-05-14 07:25:53 +0200 | [diff] [blame] | 536 | result=c.execute(nbElemsInBenchAndTypeAndCompilerCmd % benchTable,vals).fetchone() |
| 537 | return(result[0]) |
| 538 | |
| 539 | def getNbElemsInBenchAndTypeCmd(benchTable,typeid): |
| 540 | vals=(typeid,runid) |
| 541 | result=c.execute(nbElemsInBenchAndTypeCmd % benchTable,vals).fetchone() |
| 542 | return(result[0]) |
| 543 | |
| 544 | def getNbElemsInBenchCmd(benchTable): |
| 545 | vals=(runid,) |
| 546 | result=c.execute(nbElemsInBenchCmd % benchTable,vals).fetchone() |
Christophe Favergeon | 4f75070 | 2020-05-13 15:56:15 +0200 | [diff] [blame] | 547 | return(result[0]) |
| 548 | |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 549 | # Get names of columns and data for a table |
| 550 | # for specific typeid and compiler (for the data) |
| 551 | def getColNamesAndData(benchTable,comp,typeid): |
| 552 | cursor=c.cursor() |
| 553 | result=cursor.execute(benchCmdColumns % (benchTable)) |
| 554 | cols= [member[0] for member in cursor.description] |
| 555 | keepCols = ['NAME'] + [c for c in diff(cols , REMOVECOLUMNS) if isNotIDColumn(c)] |
| 556 | keepColsStr = "".join(joinit(keepCols,",")) |
| 557 | vals=(comp[0],comp[1],typeid,runid) |
| 558 | result=cursor.execute(benchCmd % (keepColsStr,benchTable),vals) |
| 559 | vals =np.array([list(x) for x in list(result)]) |
| 560 | return(keepCols,vals) |
| 561 | |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 562 | |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 563 | |
| 564 | PARAMS=["NB","NumTaps", "NBA", "NBB", "Factor", "NumStages","VECDIM","NBR","NBC","NBI","IFFT", "BITREV"] |
| 565 | |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 566 | def regressionTableFor(name,section,ref,toSort,indexCols,field): |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 567 | data=ref.pivot_table(index=indexCols, columns='core', |
| 568 | values=[field], aggfunc='first') |
| 569 | |
| 570 | data=data.sort_values(toSort) |
| 571 | |
| 572 | cores = [c[1] for c in list(data.columns)] |
| 573 | columns = diff(indexCols,['NAME']) + cores |
| 574 | |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 575 | dataTable=Table(columns) |
| 576 | section.addTable(dataTable) |
| 577 | |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 578 | dataForFunc=data.loc[name] |
| 579 | if type(dataForFunc) is pd.DataFrame: |
| 580 | for row in dataForFunc.itertuples(): |
| 581 | row=list(row) |
| 582 | if type(row[0]) is int: |
| 583 | row=[row[0]] + row[1:] |
| 584 | else: |
| 585 | row=list(row[0]) + row[1:] |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 586 | dataTable.addRow(row) |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 587 | else: |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 588 | dataTable.addRow(dataForFunc) |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 589 | |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 590 | def formatTableByCore(typeSection,testNames,cols,vals): |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 591 | if vals.size != 0: |
| 592 | ref=pd.DataFrame(vals,columns=cols) |
| 593 | toSort=["NAME"] |
| 594 | |
| 595 | for param in PARAMS: |
| 596 | if param in ref.columns: |
| 597 | ref[param]=pd.to_numeric(ref[param]) |
| 598 | toSort.append(param) |
| 599 | if args.r: |
| 600 | # Regression table |
| 601 | ref['MAX']=pd.to_numeric(ref['MAX']) |
| 602 | ref['MAXREGCOEF']=pd.to_numeric(ref['MAXREGCOEF']) |
| 603 | |
| 604 | indexCols=diff(cols,['core','Regression','MAXREGCOEF','MAX','version','compiler']) |
| 605 | valList = ['Regression'] |
| 606 | else: |
| 607 | ref['CYCLES']=pd.to_numeric(ref['CYCLES']) |
| 608 | |
| 609 | indexCols=diff(cols,['core','CYCLES','version','compiler']) |
| 610 | valList = ['CYCLES'] |
| 611 | |
| 612 | |
| 613 | |
| 614 | for name in testNames: |
| 615 | if args.r: |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 616 | testSection = Section(name) |
| 617 | typeSection.addSection(testSection) |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 618 | |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 619 | regressionSection = Section("Regression") |
| 620 | testSection.addSection(regressionSection) |
| 621 | regressionTableFor(name,regressionSection,ref,toSort,indexCols,'Regression') |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 622 | |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 623 | maxCyclesSection = Section("Max cycles") |
| 624 | testSection.addSection(maxCyclesSection) |
| 625 | regressionTableFor(name,maxCyclesSection,ref,toSort,indexCols,'MAX') |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 626 | |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 627 | maxRegCoefSection = Section("Max Reg Coef") |
| 628 | testSection.addSection(maxRegCoefSection) |
| 629 | regressionTableFor(name,maxRegCoefSection,ref,toSort,indexCols,'MAXREGCOEF') |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 630 | |
| 631 | else: |
| 632 | data=ref.pivot_table(index=indexCols, columns='core', |
| 633 | values=valList, aggfunc='first') |
| 634 | |
| 635 | data=data.sort_values(toSort) |
| 636 | |
| 637 | cores = [c[1] for c in list(data.columns)] |
| 638 | columns = diff(indexCols,['NAME']) + cores |
| 639 | |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 640 | testSection = Section(name) |
| 641 | typeSection.addSection(testSection) |
| 642 | |
| 643 | dataTable=Table(columns) |
| 644 | testSection.addTable(dataTable) |
| 645 | |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 646 | dataForFunc=data.loc[name] |
| 647 | if type(dataForFunc) is pd.DataFrame: |
| 648 | for row in dataForFunc.itertuples(): |
| 649 | row=list(row) |
| 650 | if type(row[0]) is int: |
| 651 | row=[row[0]] + row[1:] |
| 652 | else: |
| 653 | row=list(row[0]) + row[1:] |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 654 | dataTable.addRow(row) |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 655 | else: |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 656 | dataTable.addRow(dataForFunc) |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 657 | |
| 658 | # Add a report for each table |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 659 | def addReportFor(document,benchName): |
Christophe Favergeon | e15894e | 2020-05-14 07:25:53 +0200 | [diff] [blame] | 660 | nbElems = getNbElemsInBenchCmd(benchName) |
| 661 | if nbElems > 0: |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 662 | benchSection = Section(benchName) |
| 663 | document.addSection(benchSection) |
Christophe Favergeon | e15894e | 2020-05-14 07:25:53 +0200 | [diff] [blame] | 664 | print("Process %s\n" % benchName) |
Christophe Favergeon | e15894e | 2020-05-14 07:25:53 +0200 | [diff] [blame] | 665 | allTypes = getExistingTypes(benchName) |
| 666 | # Add report for each type |
| 667 | for aTypeID in allTypes: |
| 668 | nbElems = getNbElemsInBenchAndTypeCmd(benchName,aTypeID) |
| 669 | if nbElems > 0: |
| 670 | typeName = getTypeName(aTypeID) |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 671 | typeSection = Section(typeName) |
| 672 | benchSection.addSection(typeSection) |
Christophe Favergeon | e15894e | 2020-05-14 07:25:53 +0200 | [diff] [blame] | 673 | ## Add report for each compiler |
| 674 | allCompilers = getExistingCompiler(benchName,aTypeID) |
| 675 | for compiler in allCompilers: |
| 676 | #print(compiler) |
| 677 | nbElems = getNbElemsInBenchAndTypeAndCompilerCmd(benchName,compiler,aTypeID) |
| 678 | # Print test results for table, type, compiler |
| 679 | if nbElems > 0: |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 680 | compilerSection = Section("%s (%s)" % compiler) |
| 681 | typeSection.addSection(compilerSection) |
Christophe Favergeon | e15894e | 2020-05-14 07:25:53 +0200 | [diff] [blame] | 682 | cols,vals=getColNamesAndData(benchName,compiler,aTypeID) |
| 683 | names=getTestNames(benchName,compiler,aTypeID) |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 684 | formatTableByCore(compilerSection,names,cols,vals) |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 685 | |
| 686 | |
| 687 | |
| 688 | |
| 689 | |
| 690 | try: |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 691 | benchtables=getBenchTables() |
Christophe Favergeon | e15894e | 2020-05-14 07:25:53 +0200 | [diff] [blame] | 692 | theDate = getrunIDDate(runid) |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 693 | document = Document(runid,theDate) |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 694 | for bench in benchtables: |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 695 | addReportFor(document,bench) |
| 696 | with open(args.o,"w") as output: |
| 697 | if args.t=="md": |
| 698 | document.accept(Markdown(output)) |
| 699 | if args.t=="html": |
| 700 | document.accept(HTML(output)) |
| 701 | |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 702 | finally: |
| 703 | c.close() |
| 704 | |
Christophe Favergeon | c3f455c | 2020-05-14 09:24:07 +0200 | [diff] [blame^] | 705 | |
| 706 | |
Christophe Favergeon | 8cb3730 | 2020-05-13 13:06:58 +0200 | [diff] [blame] | 707 | |