summaryrefslogtreecommitdiff
path: root/try-node-chunk-sizes-plot-results
blob: 4ea3a47785506c6ba890cc82922f8c46e86e79c2 (plain)
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
#!/usr/bin/env python

import ConfigParser
import re
import subprocess
import sys


ops = ['backup', 'restore', 'forget']


def parse_size(spec):
    m = re.search('\d+', spec)
    return int(m.group())


def dat_filename(op, node_size):
    return '%s-%s-%d.dat' % (sys.argv[1], op, node_size)


def plotfile(op, node_size):
    return ('"%s" with lines title "node size %d KiB"' %
                (dat_filename(op, node_size), node_size))


for op in ops:
    data = {}

    for filename in sys.argv[2:]:
        cp = ConfigParser.ConfigParser()
        cp.read(filename)
        desc = cp.get('meta', 'description')
        words = desc.split()
        node_size = parse_size(words[0])
        chunk_size = parse_size(words[1])
        secs = cp.getfloat('0', '%s.real' % op)
        data[node_size] = data.get(node_size, []) + [(chunk_size, secs)]

    for node_size in data:
        points = sorted(data[node_size])
        name = dat_filename(op, node_size)
        with open(name, 'w') as f:
            for chunk_size, secs in points:
                f.write('%d %f\n' % (chunk_size, secs))

    gnuplot = '''\
set terminal svg dynamic
set title "%s %s"
set xlabel "chunk size (KiB)"
set ylabel "time (s)"
''' % (sys.argv[1], op)

    gnuplot += ('plot' +
                ', '.join(plotfile(op, x) for x in sorted(data.keys())) +
                '\n')

    script_name = '%s-%s.gnuplot' % (sys.argv[1], op)
    with open(script_name, 'w') as f:
        f.write(gnuplot)
    with open('%s-%s.svg' % (sys.argv[1], op), 'wb') as outp:
        subprocess.check_call(['gnuplot', script_name], stdout=outp)