From 45b90e26e24c2cbe643a7c84f2af7cb657a684b6 Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Mon, 12 Jan 2009 15:36:37 +0000 Subject: [PATCH] Add expedite-cmp to create nice comparison tables for expedite results. Python script that outputs both console and html comparison sheets/table for results, a good run is: expedite -e x11 -a > expedite-x11.log expedite -e xr -a > expedite-xr.log expedite -e gl -a > expedite-gl.log # text, with colors! expedite-cmp -p expedite-x11.log expedite-xr.log expedite-gl.log # html expedite-cmp -p -r html expedite-x11.log expedite-xr.log expedite-gl.log > expedite-cmp.html SVN revision: 38553 --- src/bin/Makefile.am | 1 + src/bin/expedite-cmp | 212 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 213 insertions(+) create mode 100755 src/bin/expedite-cmp diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index cb1b952..d58a14d 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -14,6 +14,7 @@ AM_CPPFLAGS = \ @EVIL_CFLAGS@ bin_PROGRAMS = expedite +bin_SCRIPTS = expedite-cmp expedite_SOURCES = \ main.c main.h \ diff --git a/src/bin/expedite-cmp b/src/bin/expedite-cmp new file mode 100755 index 0000000..3b1e1b9 --- /dev/null +++ b/src/bin/expedite-cmp @@ -0,0 +1,212 @@ +#!/usr/bin/env python + +import sys +import os +import os.path +import csv +from optparse import OptionParser + +parser = OptionParser(usage="%prog [options] .. ", + description="""\ +Generate reports comparing two or more outputs of expedite. + +Just run expedite and save output to a file and then feed them to this +program. The first file is used as base for comparison and other files +will print relative improvements. +""") +parser.add_option("-e", "--accepted-error", + help=("maximum error to accept as percentage 0.0-1.0. " + "[default=%default]"), + action="store", type="float", default=0.05) +parser.add_option("-r", "--report", + help=("kind of report to use. One of text or html. " + "[default=%default]"), + action="store", type="choice", default="text", + choices=["text", "html"]) +parser.add_option("-p", "--percentual", + help=("show percentual instead of raw numbers for " + "non-reference values."), + action="store_true", default=False) +parser.add_option("-C", "--no-color", dest="color", + help="do not use color in reports.", + action="store_false", default=True) + +options, files = parser.parse_args() +if len(files) < 2: + raise SystemExit("need at least 2 files to compare") + + +ref_f = files[0] +others_f = files[1:] + +max_test_name = 0 +data = {} +tests = [] +for f in files: + d = data[f] = {} + for row in csv.reader(open(f)): + t = row[1].strip() + if f == ref_f: + tests.append(t) + d[t] = float(row[0]) + max_test_name = max(len(t), max_test_name) + +def report_text(): + test_name_fmt = "%%%ds:" % max_test_name + + print test_name_fmt % "\\", + for f in files: + n, e = os.path.splitext(f) + print "%7.7s" % n[-7:], + print + + if options.color and os.environ.get("TERM", "") == "xterm": + color_good = "\033[1;32m" + color_bad = "\033[1;31m" + color_equal = "\033[1;30m" + color_reset = "\033[0m" + else: + color_good = "" + color_bad = "" + color_equal = "" + color_reset = "" + + + def print_row(test): + print test_name_fmt % test, + ref_val = data[ref_f][test] + print "%7.2f" % ref_val, + for f in others_f: + try: + val = data[f][test] + except KeyError: + print "-?????-", + continue + + percent = (val - ref_val) / ref_val + if percent < -options.accepted_error: + c = color_bad + elif percent > options.accepted_error: + c = color_good + else: + c = color_equal + + if options.percentual: + print "%s%+6.1f%%%s" % (c, (percent * 100), color_reset), + else: + print "%s%7.2f%s" % (c, val, color_reset), + + print + + for t in tests: + print_row(t) + + +def report_html(): + import time + + fnames = [os.path.basename(f) for f in files] + print """\ + + + + + + expedite comparison sheet: %(files)s + + + +

Comparison sheet for %(files)s, created at %(date)s.

+ + + + \ +""" % {"files": ", ".join(fnames), + "date": time.asctime(), + } + + for f in fnames: + print """\ + \ +""" % f + print """\ + + + \ +""" + + def print_row(test): + ref_val = data[ref_f][test] + print """\ + + + \ +""" % (test, ref_val) + + for f in others_f: + try: + val = data[f][test] + except KeyError: + print """\ + \ +""" + continue + + percent = (val - ref_val) / ref_val + if percent < -options.accepted_error: + c = 'bad' + elif percent > options.accepted_error: + c = 'good' + else: + c = 'equal' + + if options.percentual: + v = "%+6.1f%%" % (percent * 100) + else: + v = "%7.2f" % val + + print """\ + \ +""" % (c, v) + + print """\ + \ +""" + + for t in tests: + print_row(t) + + print """\ + +
\\%s
%s%7.2f-?????-%s
+ + +""" + +if options.report == "text": + report_text() +elif options.report == "html": + report_html()