import math from datetime import date NORMALFORMAT=0 BYCFORMAT=1 BYDFORMAT=2 def joinit(iterable, delimiter): it = iter(iterable) yield next(it) for x in it: yield delimiter yield x # To format, in HTML, the cores in the right order. # First we order the categories # Then we order the cores in each category # The final ORDEREDCORES is what is used # to order tjhe values # Since some cores may be missing, each atble display # is computing a rstricted ordered core list with only the available cores. CORTEXCATEGORIES=["Cortex-M","Cortex-R","Cortex-A"] CORECATEGORIES={"Cortex-M":["m0","m4", "m7", "m33" , "m55 scalar", "m55 mve","m55 autovec"], "Cortex-R":["r8","r52"], "Cortex-A":["a32"] } ORDEREDCORES=[] for cat in CORTEXCATEGORIES: cores=[] if cat in CORECATEGORIES: for core in CORECATEGORIES[cat]: cores.append(core) else: print("Error core %s not found" % cat) quit() ORDEREDCORES += cores ORDEREDTYPES=["q7","q15","q31","u32","f16","f32","f64"] class Markdown: def __init__(self,output): self._id=0 self._output = output def visitBarChart(self,data): pass def visitHistory(self,data): pass def visitText(self,text): self._output.write(text) # Write columns in markdown format def writeColumns(self,cols): colStr = "".join(joinit(cols,"|")) self._output.write("|") self._output.write(colStr) self._output.write("|\n") sepStr="".join(joinit([":-:" for x in cols],"|")) self._output.write("|") self._output.write(sepStr) self._output.write("|\n") # Write row in markdown format def writeRow(self,row): row=[str(x) for x in row] rowStr = "".join(joinit(row,"|")) self._output.write("|") self._output.write(rowStr) self._output.write("|\n") def visitTable(self,table): self.writeColumns(table.columns) for row in table.rows: self.writeRow(row) def visitSection(self,section): self._id = self._id + 1 header = "".join(["#" for i in range(self._id)]) self._output.write("%s %s\n" % (header,section.name)) def leaveSection(self,section): self._id = self._id - 1 def visitDocument(self,document): if document.runidHeader: self._output.write("Document generated for run ids : %s\n" % document.runidHeader) def leaveDocument(self,document): pass styleSheet=""" """ script="""""" barscript=""" """ class HTMLToc: def __init__(self,output): self._id=0 self._sectionID = 0 self._output = output def visitTable(self,table): pass def visitBarChart(self,data): pass def visitHistory(self,data): pass def visitText(self,text): pass def visitSection(self,section): self._id = self._id + 1 self._sectionID = self._sectionID + 1 if section.hasChildren: self._output.write("
  • %s\n" % (self._sectionID,section.name)) self._output.write("
  • \n") self._id = self._id - 1 def visitDocument(self,document): self._output.write("

    Table of content

    %s\n" % script) def permutation(ordered,unordered,mode): result=[] restricted=[] order = ORDEREDCORES if mode == BYDFORMAT: order = ORDEREDTYPES for c in order: if c in unordered: restricted.append(c) for c in unordered: result.append(restricted.index(c)) return(result,restricted) def reorder(p,v): result=[0 for x in v] for val,i in zip(v,p): result[i]=val return(result) class HTML: def __init__(self,output,regMode,ratio,reorder): self._id=0 self._sectionID = 0 self._barID = 0 self._histID = 0 self._output = output self._regMode = regMode self._reorder = reorder self._ratioMode = ratio and regMode def visitBarChart(self,bar): data=bar.data datastr = "".join(joinit(["{name:'%s',value:%s}" % x for x in data],",")) #print(datastr) self._output.write("

    \n" % self._barID) self._output.write("""""" % (self._barID,datastr,self._barID,self._barID)) self._barID = self._barID + 1 def _getIndex(self,runids,data): return([[runids.index(x[0]),x[1]] for x in data]) def visitHistory(self,hist): data=hist.data runidstr = "".join(joinit([str(x) for x in hist.runids],",")) serieelems=[] for core in data: serieelems.append("{name: '%s',values: %s}" % (core,self._getIndex(hist.runids,data[core]))) seriestr = "".join(joinit(serieelems,",")) datastr="""{ series: [%s], dates: [%s] };""" %(seriestr,runidstr); #print(datastr) self._output.write("

    \n" % self._histID) self._output.write("""""" % (self._histID,datastr,self._histID,self._histID)) self._histID = self._histID + 1 def visitText(self,text): self._output.write("

    \n") self._output.write(text.text) self._output.write("

    \n") def visitTable(self,table): self._output.write("\n") self._output.write("\n") self._output.write("\n") firstCore = False for col in table.params: firstCore = True self._output.write("\n") if self._reorder == NORMALFORMAT: perm,restricted=permutation(ORDEREDCORES,table.cores,self._reorder) elif self._reorder == BYDFORMAT: perm,restricted=permutation(ORDEREDTYPES,table.cores,self._reorder) else: restricted = table.cores for col in restricted: if firstCore: self._output.write("\n") firstCore = False self._output.write("\n") self._output.write("\n") nbParams = len(table.params) for row in table.rows: self._output.write("\n") i = 0 row=list(row) #print(row) params=row[0:nbParams] values=row[nbParams:] if self._reorder == NORMALFORMAT: row = params + reorder(perm,values) elif self._reorder == BYDFORMAT: row = params + reorder(perm,values) else: row = params + values for elem in row: txt=str(elem) if txt == 'NA': txt = "" + txt + "" if i < nbParams: self._output.write("\n") elif i == nbParams and nbParams != 0: self._output.write("\n") else: self._output.write("\n") i = i + 1 self._output.write("\n") self._output.write("
    ") self._output.write(str(col)) self._output.write("") else: self._output.write("") self._output.write(str(col)) self._output.write("
    ") self._output.write(txt) self._output.write("") self._output.write(txt) self._output.write("") self._output.write(txt) self._output.write("
    \n") def visitSection(self,section): self._id = self._id + 1 self._sectionID = self._sectionID + 1 name = section.name if section.isTest: name = "" + name + "" self._output.write("%s\n" % (self._id,self._sectionID,name,self._id)) def leaveSection(self,section): self._id = self._id - 1 def visitDocument(self,document): self._output.write(""" Benchmarks%s\n""" % styleSheet) if self._regMode and not self._ratioMode: self._output.write("

    ECPS Benchmark Regressions

    \n") elif self._ratioMode: self._output.write("

    ECPS Benchmark Ratios

    \n") else: self._output.write("

    ECPS Benchmark Summary

    \n") if document.runidHeader: self._output.write("

    Document generated for run ids : %s

    \n" % document.runidHeader) today = date.today() d2 = today.strftime("%B %d, %Y") self._output.write("

    Document generated on %s

    \n" % d2) self._output.write(barscript) def leaveDocument(self,document): document.accept(HTMLToc(self._output)) self._output.write("\n")