#!/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)