From 65fa321d63cfd3a38309b7ec8907df5c4a8d26b6 Mon Sep 17 00:00:00 2001 From: "Bjoern B. Brandenburg" Date: Sun, 22 Feb 2009 00:38:14 -0500 Subject: finally usable plotters! --- plot.py | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100755 plot.py (limited to 'plot.py') diff --git a/plot.py b/plot.py new file mode 100755 index 0000000..c0218e9 --- /dev/null +++ b/plot.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python +import defapp +from os.path import splitext, basename +from optparse import make_option as o +from tempfile import NamedTemporaryFile as Tmp + +from gnuplot import gnuplot, FORMATS + +options = [ + o('-f', '--format', action='store', dest='format', type='choice', + choices=FORMATS, help='output format'), + ] + +defaults = { + 'format' : 'show', + 'xrange' : (0.5, 32.5), + 'yrange' : (-0.05, 1.05), + 'xticks' : (0, 2), + 'yticks' : (0, 0.1), + 'title' : None, + 'xlabel' : 'task set utilization cap (prior to inflation)', + 'ylabel' : 'ratio of schedulable task sets', + } + +def decode(name): + params = {} + parts = name.split('_') + for p in parts: + kv = p.split('=') + k = kv[0] + v = kv[1] if len(kv) > 1 else None + params[k] = v + return params + +def get_data_tmpfile(datafile): + """Removes all comments form datafile, stores result in a temp file. + The temp file is returned.""" + count = 0 + f = open(datafile, 'r') + d = Tmp() + for line in f: + if len(line) > 1 and line[0] != '#': + d.write(line) + count += 1 + f.close() + d.flush() + if count > 0: + return d + else: + del d # removes temp file + return None + +def scenario_heading(conf): + dist = 'unknown distribution' + if 'dist' in conf: + if conf['dist'] == 'uni': + dist = 'uniformly distributed' + if 'light' in conf: + dist = dist + ' in [0.001, 0.1]' + elif 'medium' in conf: + dist = dist + ' in [0.1, 0.4]' + elif 'heavy' in conf: + dist = dist + ' in [0.5, 0.9]' + elif conf['dist'] == 'bimo': + dist = 'bimodially distributed' + if 'light' in conf: + dist = dist + 'in [0.001, 0.5] (8/9) and [0.5, 0.9] (1/9)' + elif 'medium' in conf: + dist = dist + 'in [0.001, 0.5] (6/9) and [0.5, 0.9] (3/9)' + elif 'heavy' in conf: + dist = dist + 'in [0.001, 0.5] (4/9) and [0.5, 0.9] (5/9)' + return dist + +class SchedPlotter(defapp.App): + def __init__(self): + defapp.App.__init__(self, options, defaults, no_std_opts=True) + + def plot(self, graphs, title, name, conf): + gnuplot(graphs, title=title, + xlabel=self.options.xlabel, + ylabel=self.options.ylabel + + (' [soft]' if 'soft' in conf else ' [hard]'), + xrange=self.options.xrange, + yrange=self.options.yrange, + xticks=self.options.xticks, + yticks=self.options.yticks, + format=self.options.format, + fname=name) + + def plot_spec(self, tmpfile, name, conf): + title = 'release overhead speculation: ' + scenario_heading(conf) + graphs = [ + (tmpfile, 1, 2, 'G-EDF (100% release)'), + (tmpfile, 1, 3, 'G-EDF ( 75% release)'), + (tmpfile, 1, 4, 'G-EDF ( 50% release)'), + (tmpfile, 1, 5, 'G-EDF ( 25% release)'), + (tmpfile, 1, 6, 'G-EDF ( 0% release)'), + (tmpfile, 1, 7, 'G-EDF (no overheads)'), + ] + self.plot(graphs, title, name, conf) + + def plot_spec2(self, tmpfile, name, conf): + title = 'service processor speculation: ' + scenario_heading(conf) + graphs = [ + (tmpfile, 1, 2, 'G-EDF ( 25% release, 100% rest)'), + (tmpfile, 1, 3, 'G-EDF (100% release, 0% rest)'), + (tmpfile, 1, 4, 'G-EDF (service cpu, 100% preempt)'), + (tmpfile, 1, 5, 'G-EDF (service cpu, 150% preempt)'), + ] + self.plot(graphs, title, name, conf) + + def plot_file(self, datafile): + bname = basename(datafile) + name, ext = splitext(bname) + if ext != '.csv': + self.err("Warning: '%s' doesn't look like a CSV file." + % bname) + conf = decode(name) + tmpfile = get_data_tmpfile(datafile) + if tmpfile: + if 'spec' in conf: + self.plot_spec(tmpfile.name, name, conf) + elif 'spec2' in conf: + self.plot_spec2(tmpfile.name, name, conf) + else: + self.err("Skipped '%s'; unkown experiment type." + % bname) + del tmpfile # removes temp file + else: + self.err("Skipped '%s'; it dosn't appear to contain data." + % bname) + + def default(self, _): + for datafile in self.args: + self.plot_file(datafile) + +if __name__ == "__main__": + SchedPlotter().launch() -- cgit v1.2.2