#!/usr/bin/python from sys import maxsize import xml.etree.ElementTree as ET import argparse from utils import * def getLink(instrNode, text, arch, tool, linkType, anchor=None): url = '/tmp/html-' + linkType + '/' + arch + '/' + canonicalizeInstrString(instrNode.attrib['string']) + '-' + tool + '.html' if anchor: url += '#' + anchor return '' + text + '' def main(): parser = argparse.ArgumentParser(description='Generates a basic HTML table with the results for a microarchitecture') parser.add_argument("-input", help="Input XML file", default='result.xml') parser.add_argument("-arch", help="Consider only this architecture") args = parser.parse_args() root = ET.parse(args.input) TPSame = 0 TPDiff = 0 with open('instructions.html', "w") as f: f.write('\n' '\n' 'Instructions\n' '\n' '\n' '\n') for XMLExtension in root.iter('extension'): if not XMLExtension.findall('.//measurement'): continue f.write('

' + XMLExtension.attrib['name'] + '

\n' '\n' ' \n' ' \n' ' \n' ' \n' ' \n' ' \n' ' \n' ' \n') for XMLInstr in sorted(XMLExtension.findall('./instruction'), key=lambda x: x.attrib['string']): for resultNode in XMLInstr.findall('./architecture[@name="' + args.arch + '"]/measurement'): f.write(' \n') f.write(' \n') lat = '' latTableEntry = getLatencyTableEntry(resultNode) if latTableEntry is not None: lat = str(latTableEntry[0]) f.write(' \n') TPPorts = float(resultNode.attrib.get('TP_ports', float("inf"))) TPPortsStr = ("{:.2f}".format(TPPorts) if TPPorts < float("inf") else '') f.write(' \n') TPMeasured = min(float(resultNode.attrib.get('TP_loop', float("inf"))), float(resultNode.attrib.get('TP_unrolled', float("inf")))) TPMeasuredStr = ("{:.2f}".format(TPMeasured) if TPMeasured < float("inf") else '') uopsMS = int(resultNode.attrib.get('uops_MS', sys.maxsize)) color = '' if TPPortsStr and TPMeasuredStr and (uopsMS == 0): if abs(TPMeasured - TPPorts) < .02: color = ' bgcolor="green"' TPSame += 1 else: color = ' bgcolor="orange"' TPDiff += 1 f.write(' \n') f.write(' \n') f.write(' \n') f.write(' \n') f.write('
LatTP (ports)TP (m)uopsPorts
' + XMLInstr.attrib['string'] + '' + getLink(XMLInstr, lat, args.arch, 'Measurements', 'lat') + '' + TPPortsStr + '' + getLink(XMLInstr, TPMeasuredStr, args.arch, 'Measurements', 'tp') + '' + resultNode.attrib.get('uops', '') + '' + getLink(XMLInstr, resultNode.attrib.get('ports', ''), args.arch, 'Measurements', 'ports') + '
\n') f.write('\n') f.write('\n') print('TPSame: ' + str(TPSame)) print('TPDiff: ' + str(TPDiff)) print('Result written to instructions.html') if __name__ == "__main__": main()