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