aboutsummaryrefslogtreecommitdiffstats
path: root/plot.py
blob: 698431198a7d695427f930f85502b1062ae36855 (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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
#!/usr/bin/env python
import defapp

import re

from os.path  import splitext, basename
from optparse import make_option as o
from tempfile import NamedTemporaryFile as Tmp

from gnuplot  import gnuplot, FORMATS, Plot, label, curve

options = [
    # output options
    o('-f', '--format', action='store', dest='format', type='choice',
      choices=FORMATS, help='output format'),
    o(None, '--save-script', action='store_true', dest='save_script'),
    o('-p', '--prefix', action='store', dest='prefix'),
    o('-e', '--experiment', action='store', dest='experiment',
      help="override auto-detection of experiment"),

    # formatting options
    # These may or may not be supported by a particular experiment plotter.
    o(None, '--smooth', action='store_true', dest='smooth'),
    o(None, '--paper', action='store_true', dest='paper'),
    o(None, '--wide', action='store_true', dest='wide'),
    o(None, '--column', action='store_true', dest='column'),
    o(None, '--split', action='store_true', dest='split'),
    o(None, '--alternate', action='store_true', dest='alternate'),
    o(None, '--slides', action='store_true', dest='slides'),
    ]

defaults = {
    # output options
    'format' : 'show',
    'experiment' : None,
    'save_script' : False,
    'prefix' : '',

    # formatting options
    'paper'  : False,
    'split'  : False,
    'wide'   : False,
    'alternate' : False,
    'column' : False,
    'slides' : False,
    'smooth' : False,

    # legacy "options" that are not actually options.
    '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, target=None):
    """Removes all comments form datafile, stores result in a temp file.
    The temp file is returned."""
    count = 0
    f = open(datafile, 'r')
    if target:
        d = open(target, 'w')
    else:
        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, want_period=False):
    dist = 'unknown distribution'
    period = None
    if 'dist' in conf:
        if conf['dist'] == 'uni':
            dist = 'utilization uniformly '
            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 'mixed' in conf:
                dist = dist + 'in [0.05, 0.95]'
        elif conf['dist'] == 'bimo':
            dist = 'util. bimodally '
            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)'
        else:
            # try regular expressions
            m = re.match('uni-(\d\.\d+)-(\d\.\d+)', conf['dist'])
            if m:
                dist = "utilization uniformly in [%s, %s]" % (m.group(1), m.group(2))
            m = re.match('bimo-([^-]+)-(\d\.\d+)', conf['dist'])
            if m:
                weight = m.group(1)
                cap    = m.group(2)
                dist = 'util. bimodally '
                if 'light' == weight:
                    dist = dist + 'in [0.001, 0.5] (8/9) and [0.5, %s] (1/9)' % cap
                elif 'medium' == weight:
                    dist = dist + 'in [0.001, 0.5] (6/9) and [0.5, %s] (3/9)' % cap
                elif 'heavy' == weight:
                    dist = dist + 'in [0.001, 0.5] (4/9) and [0.5, %s] (5/9)' % cap
            m = re.match('exp-(\d+)-(\d+)-(\d+)', conf['dist'])
            if m:
                mean   = (float(m.group(1)) / 100)
                period = (m.group(2), m.group(3))
                dist = "util. exponentially in [0, 1] with mean %.2f" % mean

    if want_period:
        if period:
            dist += '; period uniformly in [%s, %s]' % period
        elif '33' in conf:
            dist += '; period uniformly in [3, 33]'
        elif '250' in conf:
            dist += '; period uniformly in [50, 250]'
        else:
            dist += '; period uniformly in [10, 100]'
    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, **xtra):
        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, **xtra)

    def plot_wide(self, graphs, title, name, conf, **xtra):
        tops = 'rounded size 16cm,6.5cm'
        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,
                term_opts=tops,
                **xtra)

# width  = 3.4in
# height = 2.0in

    def plot_column(self, graphs, title, name, conf, **xtra):
        scale = 1.0
        tops = 'color solid  font "Helvetica,8" linewidth 1.0 ' \
               'rounded size %.1fin,%.1fin' % (scale * 7.0, scale * 2.0)
        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,
                key='right bottom' if '250' in conf else 'right top',
                term_opts=tops)


    def plot_paper(self, graphs, title, name, conf, **xtra):
        tops = 'color solid  font "Helvetica,10" linewidth 1.0 rounded size 16cm,8.5cm'
        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,
                key='off',
                style='lines lw 7',
                term_opts=tops)

    def plot_spec(self, tmpfile, name, conf):
        title = 'G-EDF 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)'),
            ]
        if self.options.paper and self.options.format == 'pdf':
            self.plot_paper(graphs, title, name, conf)
        else:
            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_spec3(self, tmpfile, name, conf):
        title = 'linear overhead charge speculation: ' + scenario_heading(conf)
        graphs = [
            (tmpfile, 1, 2, 'G-EDF (100% release)'),
            (tmpfile, 1, 3, 'G-EDF ( 25% release)'),
            (tmpfile, 1, 4, 'G-EDF ( Lin release)'),
            ]
        self.plot(graphs, title, name, conf)

    def plot_spec4(self, tmpfile, name, conf):
        title = 'linear overhead charge speculation: ' + scenario_heading(conf)
        graphs = [
            (tmpfile, 1, 2, 'G-EDF (100% release)'),
            (tmpfile, 1, 3, 'G-EDF-S (100% release, all cpus)'),
            (tmpfile, 1, 4, 'G-EDF-S (100% release, one cpu)'),
            (tmpfile, 1, 5, 'G-EDF (25% release)'),
            (tmpfile, 1, 6, 'G-EDF-S (25% release, all cpus)'),
            (tmpfile, 1, 7, 'G-EDF-S (25% release, one cpu)'),
            ]
        self.plot(graphs, title, name, conf)

    def make_plot(self, fname=None):
        p = Plot()
        p.output = "%s%s.%s" % (self.options.prefix, fname, self.options.format)
        p.format = self.options.format
        return p

    def setup_png(self, plot):
        # standard png options; usually correct; never tweaked for paper
        if self.options.format == 'png':
            plot.font_size = 'large'
            plot.size   = (1024, 768)
            plot.xticks = (0, 1)
            plot.yticks = (0, 0.1)
            plot.default_style = "linespoints"
            return True
        else:
            return False


    def plot_irq(self, tmpfile, name, conf):
        p = self.make_plot(name)

        #### Data.

        titles = ['quantum-centric',
                  'task-centric',
                  'processor-centric',
                  'dedicated processor',
                  'dedicated proc. + timer multiplexing']

        if self.options.alternate:
            extra = '; 20% ISR costs'
            cols = [8, 9, 10, 12, 14]
            p.output = 'alt_' + p.output
        else:
            extra = '; 100% ISR costs'
            cols = [1, 2, 3, 5, 7]

        p.curves += [ curve(fname=tmpfile, xcol=1, ycol=(y + 1), title=t)
                      for (y, t) in zip(cols, titles) ]

        #### Styling.

        if not self.setup_png(p):
            # eps or pdf
            p.rounded_caps = True
            p.font = 'Helvetica'

            if self.options.paper:
                # workaround strange font-size bug
                if self.options.format == 'eps':
                    p.font_size = '9.5pt'
                else:
                    p.font_size = '5pt'
                p.size = ('6.5cm', '5.25cm')
                p.monochrome   = True
                p.dashed_lines = True
                p.key = 'off'

                p.xticks = (0, 2)
                p.yrange = (-0.1, 1.1)
                p.yticks = (0, 0.2)
                p.xlabel = "task set utilization cap (prior to overhead accounting)"
                p.default_style = 'lines lw 2.5'
            else:
                p.font_size = '10'
                p.size = ('20cm', '10cm')
                p.monochrome   = False
                p.dashed_lines = False
                p.key = 'below'

                p.xticks = (0, 1)
                p.yrange = (-0.05, 1.05)
                p.yticks = (0, 0.1)
                p.xlabel = "ucap (prior to inflation)"
                p.default_style = 'lines lw 6'

        p.ylabel = "schedulability " + (' [soft]' if 'soft' in conf else ' [hard]')
        p.xrange = (0.5, 32.5)

        p.title = scenario_heading(conf) + extra
        if not self.options.paper:
            p.title = 'Interrupt accounting under G-EDF: utilization ' + p.title

        if self.options.save_script:
            p.gnuplot_save(p.output + '.plot')
        else:
            p.gnuplot_exec()


    def plot_rtss08(self, tmpfile, name, conf):
        p = self.make_plot(name)

        #### Data.

        titles = ['P-EDF', 'C-EDF', 'G-EDF', 'PFAIR', 'S-PFAIR', 'G-NP-EDF']
        if 'hard' in conf:
            del titles[-1]

        p.curves += [curve(fname=tmpfile, xcol=1, ycol=(y + 2), title=t)
                     for (y, t) in enumerate(titles)]

        #### Styling.

        if not self.setup_png(p):
            # eps or pdf
            if self.options.slides:
                # for Jim's slides
                if self.options.format == 'eps':
                    p.font_size = 'large'
                p.dashed_lines = False
                p.monochrome = False
                p.rounded_caps = True
                p.default_style = 'lines lw 10'
                p.xticks = (0, 1)
                p.yticks = (0, 0.1)
                p.yrange = (-0.05, 1.05)
                p.key = 'below'
                p.xlabel = "task set utilization cap (prior to overhead accounting)"
            else:
                p.rounded_caps = True
                p.font = 'Helvetica'

                p.font_size = '10'
                p.size = ('20cm', '10cm')
                p.monochrome   = False
                p.dashed_lines = True
                p.key = 'below'

                p.xticks = (0, 1)
                p.yrange = (-0.05, 1.05)
                p.yticks = (0, 0.1)
                p.xlabel = "ucap (prior to inflation)"
                p.default_style = 'lines lw 6'

        if self.options.smooth:
            p.default_style += " smooth bezier"

        p.ylabel = "schedulability " + (' [soft]' if 'soft' in conf else ' [hard]')
        if self.options.alternate:
            p.xrange = (0.5, 32.5)
        else:
            p.xrange = (0.5, 32.5)

        p.title = scenario_heading(conf, True)
        if not (self.options.paper or self.options.slides):
            p.title = "RTSS'08 " + p.title

        if self.options.save_script:
            p.gnuplot_save(p.output + '.plot')
        else:
            p.gnuplot_exec()


    def plot_rtss09(self, tmpfile, name, conf):
        title = scenario_heading(conf, want_period=True)
        graphs = [
            (tmpfile, 1, 2, 'G-EDF'),
            (tmpfile, 1, 3, 'CEm'),
            (tmpfile, 1, 4, 'CE1'),
            (tmpfile, 1, 5, 'FEm'),
            (tmpfile, 1, 6, 'FE1'),
            (tmpfile, 1, 7, 'HEm'),
            (tmpfile, 1, 8, 'CQm'),
            (tmpfile, 1, 9, 'CQ1'),
            ]
        staggered = [
            (tmpfile, 1, 10, 'S-CQm'),
            (tmpfile, 1, 11, 'S-CQ1'),
            ]
        if 'hard' in conf:
            graphs += staggered
        if self.options.paper and self.options.format == 'pdf':
            self.plot_paper(graphs, title, name, conf)
        elif self.options.wide and self.options.format == 'pdf':
            self.plot_wide(graphs, title, name, conf)
        else:
            self.plot(graphs, title, name, conf)

    def plot_rtss09_split(self, tmpfile, name, conf):
        title = scenario_heading(conf, want_period=True)
        ideal = (tmpfile, 1, 2, 'G-EDF')

        subgraphs = [
# dedicated vs. non-dedicated
            [(tmpfile, 1, 3, 'CEm'), (tmpfile, 1, 4, 'CE1')],
            [(tmpfile, 1, 5, 'FEm'), (tmpfile, 1, 6, 'FE1')],
            [(tmpfile, 1, 8, 'CQm'), (tmpfile, 1, 9, 'CQ1')],

# fine-grained vs. sequential
            [(tmpfile, 1, 3, 'CEm'), (tmpfile, 1, 5, 'FEm')],
            [(tmpfile, 1, 4, 'CE1'), (tmpfile, 1, 6, 'FE1')],

# hierarchical vs. sequential
             [(tmpfile, 1, 3, 'CEm'), (tmpfile, 1, 7, 'HEm')],

# quantum vs. event
            [(tmpfile, 1, 3, 'CEm'), (tmpfile, 1, 8, 'CQm')],
            [(tmpfile, 1, 6, 'FE1'), (tmpfile, 1, 9, 'CQ1')],
            ]
        staggered = [
# dedicated vs. non-dedicated
            [(tmpfile, 1, 10, 'S-CQm'), (tmpfile, 1, 11, 'S-CQ1')],

# staggered vs. non-staggered
            [(tmpfile, 1, 8, 'CQm'), (tmpfile, 1, 10, 'S-CQm')],
            [(tmpfile, 1, 9, 'CQ1'), (tmpfile, 1, 11, 'S-CQ1')],

# quantum vs. event
            [(tmpfile, 1, 3, 'CEm'), (tmpfile, 1, 10, 'S-CQm')],
            [(tmpfile, 1, 6, 'FE1'), (tmpfile, 1, 11, 'S-CQ1')],

            ]
        if 'hard' in conf:
            subgraphs += staggered
        for g in subgraphs:
            graphs = [ideal] + g
            xname = name + '_' + '-vs-'.join([x[3] for x in g])
            if self.options.paper and self.options.format == 'pdf':
                self.plot_paper(graphs, title, xname, conf)
            elif self.options.wide and self.options.format == 'pdf':
                self.plot_wide(graphs, title, xname, conf)
            else:
                self.plot(graphs, title, xname, conf)

    def plot_ospert10(self, tmpfile, name, conf):
        title = scenario_heading(conf, want_period=True)
        # cumulative graphs
        graphs = [
            (tmpfile, 1, 2, 'G-EDF'),
            (tmpfile, 1, 4, 'C-EDF (L3)'),
            (tmpfile, 1, 6, 'C-EDF (L2)'),
            (tmpfile, 1, 8, 'P-EDF'),
            ]
        # weighted graphs
        graphs_w = [
            (tmpfile, 1, 3, 'G-EDF'),
            (tmpfile, 1, 5, 'C-EDF (L3)'),
            (tmpfile, 1, 7, 'C-EDF (L2)'),
            (tmpfile, 1, 9, 'P-EDF'),
            ]

        self.options.xrange = (-5, 5005)
        self.options.xticks = (0, 250)
        self.options.xlabel = "cache-related preemption/migration delay (in us)"
        for (tag, gs) in [('cumulative', graphs), ('weighted', graphs_w)]:
            xname = name + '_' + tag
            self.options.ylabel = tag + ' schedulability'
            if self.options.paper and self.options.format == 'pdf':
                self.plot_paper(gs, title, xname, conf)
            elif self.options.wide and self.options.format == 'pdf':
                self.plot_wide(gs, title, xname, conf)
            elif self.options.column and self.options.format == 'pdf':
                self.plot_column(gs, title, xname, conf)
            else:
                self.plot(gs, title, xname, conf)

    def plot_semipart(self, tmpfile, name, conf):
        if not 'soft' in conf:
            cedf_titles = [('P-EDF (load)', 3), ('P-EDF (idle)', 4)]
        else:
            cedf_titles = [('C-EDF (load)', 3), ('C-EDF (idle)', 4)]

        edfwm_titles = [
            ('EDF-WM (load)', 5),
            ('EDF-WM (idle)', 6)
            ]

        npsf_titles = [
            ('NPS-F (load, delta=1)',  7),
            ('NPS-F (load, delta=4)',  8),
            ('NPS-F (idle, delta=1)',  9),
            ('NPS-F (idle, delta=4)', 10),
            ]

        cnpsf_titles = [
            ('C-NPS-F (load, delta=1)', 11),
            ('C-NPS-F (load, delta=4)', 12),
            ('C-NPS-F (idle, delta=1)', 13),
            ('C-NPS-F (idle, delta=4)', 14),
             ]

        edffm_titles = [
            ('EDF-fm (load)', 15),
            ('EDF-fm (idle)', 16),
            ]


        if self.options.alternate:
            # NPS-F comparison
            titles = npsf_titles + cnpsf_titles
        else:
            # all
            titles = cedf_titles + edfwm_titles + npsf_titles + cnpsf_titles
            if 'soft' in conf:
                titles += edffm_titles

        p = self.make_plot(name)

        p.title = scenario_heading(conf, True)

        if 'sched' in conf:
            p.ylabel = "ratio of schedulable task sets"
            p.xlabel = "task set utilization cap (prior to overhead accounting)"
            p.xticks = (0, 1)
            p.xrange = (0.95, 24.05)
            p.title  += "; %skB WSS" % conf['key']
            xcol = 2
        elif 'wsched' in conf:
            xcol = 1
            p.xlabel = "working set size (WSS)"
            p.ylabel = "weighted schedulability"
            p.xticks = (0, 64)
        else:
            self.err("What kind of semipart experiment is this?")

        p.curves += [curve(fname=tmpfile, xcol=xcol, ycol=idx, title=t)
                     for (t, idx) in titles]

        p.yrange = (-0.05, 1.05)
        p.yticks = (0, 0.1)

        #### Styling.

        if not self.setup_png(p):
            p.rounded_caps = True
            p.font = 'Helvetica'

            p.font_size = '10'
            p.size = ('20cm', '10cm')
            p.monochrome   = False
            p.dashed_lines = False
            p.key = 'below'
            p.default_style = 'linespoints lw 1'

        if self.options.smooth:
            p.default_style += " smooth bezier"

        p.ylabel += (' [soft]' if 'soft' in conf else ' [hard]')

        if self.options.save_script:
            p.gnuplot_save(p.output + '.plot')
        else:
            p.gnuplot_exec()


    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)
        try:
            if self.options.save_script:
                tmpfile = get_data_tmpfile(datafile, target = "%s.data" % name )
            else:
                tmpfile = get_data_tmpfile(datafile)
        except IOError:
            tmpfile = None
        if tmpfile:
            plotters = {
                'spec'      : self.plot_spec,
                'spec2'     : self.plot_spec2,
                'spec3'     : self.plot_spec3,
                'spec4'     : self.plot_spec4,
                'irq'       : self.plot_irq,
                'rtss08'    : self.plot_rtss08,
                'rtss09'    : self.plot_rtss09_split if self.options.split else self.plot_rtss09,
                'ospert10'  : self.plot_ospert10,
                'rtas11'    : self.plot_semipart,
                }

            if self.options.experiment:
                # override provided
                plot_type = self.options.experiment
            else:
                # no type provided, try each plotter
                for plot_type in plotters:
                    if plot_type in conf:
                        break
                if not plot_type in conf:
                    plot_type = 'unknown'
            if plot_type in plotters:
                plotters[plot_type](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 i, datafile in enumerate(self.args):
            self.out("[%d/%d] Processing %s ..." % (i + 1, len(self.args), datafile))
            self.plot_file(datafile)

if __name__ == "__main__":
    SchedPlotter().launch()