X-Git-Url: https://git.ozlabs.org/?p=hiprofile;a=blobdiff_plain;f=hiprofile.py;h=c1d1052e2f7513f3f153963c7857f9bff398c343;hp=f6456a4423297eada40b27a5431019dba6d11618;hb=be4f86318de93e331951e9b698a69d9c4c6cd514;hpb=18fd0ce3407d35a7d45854faa5101b11ed794c5b diff --git a/hiprofile.py b/hiprofile.py index f6456a4..c1d1052 100644 --- a/hiprofile.py +++ b/hiprofile.py @@ -6,7 +6,7 @@ import shutil import os import socket from xml.dom.minidom import parse as parseXML -from django.template.loader import render_to_string +from jinja2 import Environment, FileSystemLoader b_id = 0 s_id = 0 @@ -174,7 +174,7 @@ class Binary(object): lambda r: r.count, thresholds['symbol']) self.reference_dict = dict([ (r.name, r) for r in self.references ]) - def annotate(self, report, conn): + def annotate(self, report, conn, options): fn_re = re.compile('^[0-9a-f]+\s+<[^>]+>: /\* (\S+) total:') symbols = [ s for s in self.references if s.name != '(no symbols)' ] @@ -182,7 +182,7 @@ class Binary(object): if not symbols: return - command = ['opannotate', '--source', '--assembly', + command = [options.opannotate, '--source', '--assembly', '--include-file=' + self.name, '-i', ','.join([ s.name for s in symbols ])] @@ -252,9 +252,9 @@ class Report(object): for binary in self.binaries: binary.threshold(thresholds) - def annotate(self, conn): + def annotate(self, conn, options): for binary in self.binaries: - binary.annotate(self, conn) + binary.annotate(self, conn, options) @staticmethod def parse(doc, hostname): @@ -288,8 +288,8 @@ class Report(object): return report @staticmethod - def extract(connection): - fd = connection.execute(['opreport', '--xml']) + def extract(connection, options): + fd = connection.execute([options.opreport, '--xml']) doc = parseXML(fd) if connection.host: @@ -306,24 +306,27 @@ def write_report(report, resourcedir, outdir): os.mkdir(outdir) + # set up template engine + env = Environment(loader = FileSystemLoader(resourcedir), + autoescape = True) + templates = {} + for name in ['report', 'binary', 'symbol']: + templates[name] = env.get_template('%s.html' % name) + # copy required files over files = ['style.css', 'hiprofile.js', 'bar.png', 'jquery-1.3.1.min.js'] for file in files: shutil.copy(os.path.join(resourcedir, file), outdir) - f = open(os.path.join(outdir, 'index.html'), 'w') - f.write(render_to_string('report.html', { 'report': report })) - f.close() + reportfile = os.path.join(outdir, 'index.html') + templates['report'].stream(report = report).dump(reportfile) for binary in report.binaries: - f = open(os.path.join(outdir, binary.filename()), 'w') - f.write(render_to_string('binary.html', - { 'report': report, 'binary': binary })) - f.close() - - for ref in binary.references: - f = open(os.path.join(outdir, ref.filename()), 'w') - f.write(render_to_string('symbol.html', - { 'report': report, 'binary': binary, 'symbol': ref })) - f.close() - + binaryfile = os.path.join(outdir, binary.filename()) + templates['binary'].stream(report = report, binary = binary). \ + dump(binaryfile) + + for symbol in binary.references: + symbolfile = os.path.join(outdir, symbol.filename()) + templates['symbol'].stream(report = report, binary = binary, + symbol = symbol).dump(symbolfile)