aboutsummaryrefslogtreecommitdiffstats
path: root/plot_rtas12_betaexp.py
blob: 88be801f8335fa1098b21a059a2edca72d3cc093 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/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}".format(line_width, point_size)),
        (2, "lw {0} ps {1}".format(line_width, point_size)),
        (3, "lw {0} ps {1}".format(line_width, point_size)),
        (4, "lw {0} ps {1}".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 = 'at 1, 100'

    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()