#!/usr/bin/env python import sys import optparse from plot import Plot from gnuplot import curve COLS = {'beta-mean': 0, 'rel-rt-max-b': 1, 'rel-rt-mean-b': 2, 'misses-b': 3, 'new-misses-b': 4, 'rel-rt-max-c': 5, 'rel-rt-mean-c': 6, 'misses-c': 7, 'new-misses-c': 8, 'mean-misses-c': 9, 'miss-ratio-b': 10, 'miss-ratio-c': 11} def parse_args(): p = optparse.OptionParser(description='make graphs') p.add_option('--paper', dest='paper', action='store_true', default=False) return p.parse_args() def col(key): """Get the column in the data set.""" return COLS[key] def g_col(key): """Gnuplot is 1-indexed.""" return 1 + col(key) def get_y_label(metric): LABELS = {'rel-rt-max': 'relative response time maximum', 'rel-rt-mean': 'relative response time mean', 'miss-ratio': 'deadline miss ratio'} return LABELS[metric] def set_plot_opts(opts, p): p.rounded_caps = True p.font = 'Helvetica' if opts.paper: ext = 'pdf' p.size = ('8.5cm', '5.25cm') line_width = 1.5 point_size = 0.3 p.font_size = '5pt' else: ext = 'png' p.size = (1024, 768) line_width = 3.0 point_size = 1.5 p.font_size = 'font "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf" 18' p.output = '{0}.{1}'.format(p.output, ext) p.format = ext p.default_style = 'linespoints lw 2.5' p.default_style += ' smooth bezier' p.monochrome = False p.ylog = True p.key = 'off' p.line_styles = [ (1, 'lw {0} ps {1} lc rgbcolor "#ff0000"'.format(line_width, point_size)), (2, 'lw {0} ps {1} lc rgbcolor "#000000"'.format(line_width, point_size)), (3, 'lw {0} ps {1} lc rgbcolor "#0000ff"'.format(line_width, point_size)), (4, 'lw {0} ps {1} lc rgbcolor "#ff00ff"'.format(line_width, point_size))] for i, c in enumerate(p.curves): c.style = "linespoints ls %d" % (i + 1) def plot_metric(opts, dat_dir, metric, coin_prob, xr=None, for_jim=False): """Plot metric for each level, enforcement pair at the specified probability. """ # each coin value gets a plot p = Plot() p.output = '{0}/beta-exp-metric={1}-prob={2}'.format( dat_dir, metric, str(coin_prob).replace('.', '')) if xr is not None: p.output = '{0}_zoom=1'.format(p.output) if for_jim: p.output = '{0}-forjim=1'.format(p.output) for (level, enforcement) in [(l, e) for l in ('c', 'b') for e in (1, 0)]: fname = '{0}/beta_be={1}_prob={2}.csv'.format(dat_dir, enforcement, coin_prob) ycol = g_col('{0}-{1}'.format(metric, level)) if enforcement == 1: ti ='{0} {1}'.format(level.upper(), 'enforcement') else: ti ='{0} {1}'.format(level.upper(), 'no enforcement') c = curve(fname=fname, xcol=g_col('beta-mean'), ycol=ycol, title=ti) p.curves += [c] p.xlabel = 'beta mean with probability {0}'.format(coin_prob) p.ylabel = get_y_label(metric) set_plot_opts(opts, p) if xr is not None: p.xrange = xr # special formatting cases if -1 != metric.find('ratio'): p.ylog = False p.yrange = (-0.01, 1.01) if (metric == 'rel-rt-mean' and coin_prob == 0.1 and xr is None): #p.key = 'on tmargin center horizontal maxcolumns 2' pass if for_jim: p.title = 'relative response time mean, 10% abberant' p.key = 'top left' if xr is None: p.key = 'at 1, 10' p.gnuplot_exec() def main(): opts, files = parse_args() if len(files) < 1: print >>sys.stderr, "missing directory" sys.exit(1) data_dir = files[0] COIN_VALS = [0.1, 0.5] for coin_val in COIN_VALS: plot_metric(opts, data_dir, 'rel-rt-mean', coin_val) plot_metric(opts, data_dir, 'rel-rt-mean', coin_val, xr=(0.02, 0.11)) plot_metric(opts, data_dir, 'miss-ratio', coin_val) # not in paper plot_metric(opts, data_dir, 'rel-rt-max', coin_val) # for jim plot_metric(opts, data_dir, 'rel-rt-mean', 0.1, for_jim=True) plot_metric(opts, data_dir, 'rel-rt-mean', 0.1, xr=(0.02, 0.11), for_jim=True) if __name__ == '__main__': main()