#!/usr/bin/env python from os.path import splitext, basename, dirname from optparse import OptionParser 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 build_name(dirname, conf, wss_list): if dirname == '': dirname = '.' outname = dirname + '/' if 'hard' in conf: outname += 'hard' else: outname += 'soft' outname += '_pm_plugin=' + conf['plugin'] + '_dist=' + conf['dist'] # atm we use only uniform for PM (we also use only light, but...) if 'light' in conf: outname += '_light' elif 'medium' in conf: outname += '_medium' elif 'heavy' in conf: outname += '_heavy' outname += '_wss=' for wss in wss_list: if wss != wss_list[len(wss_list) - 1]: outname += str(wss) + ',' else: outname += str(wss) outname += '_ovd=' + conf['ovd'] + '.csv' return outname class WSSCompactor(): def __init__(self): self.ovhead_table = {} self.wss_list = [] def add_wss(self, wss): self.wss_list.append(int(wss)) def read_csv(self, datafile): csvf = open(datafile, 'r') # csvf format is: tss, max, avg for line in csvf: tmp = line.split(', ') if tmp[0] in self.ovhead_table.keys(): self.ovhead_table[tmp[0]] += [tmp[1], tmp[2].rstrip('\n')] else: self.ovhead_table[tmp[0]] = [tmp[1], tmp[2].rstrip('\n')] csvf.close() def write_csv(self, dirname, conf): self.wss_list.sort() outname = build_name(dirname, conf, self.wss_list) csvf = open(outname, 'w') csvf.write('# preemption and migration overhead for ' + \ conf['plugin'] + '\n') wstr = '# tssize, ' for wss in self.wss_list: wstr += 'wss=' + str(wss) + ':(max, avg), ' csvf.write(wstr[0:-2] + '\n') tkeys = self.ovhead_table.keys() for i in range(0,len(tkeys)): tkeys[i] = int(tkeys[i]) tkeys.sort() for key in tkeys: wstr = str(key) + ', ' for value in self.ovhead_table[str(key)]: wstr += value + ', ' wstr = wstr[0:-2] csvf.write(wstr + '\n') csvf.close() def main(args): wsscmpctr = WSSCompactor() for datafile in args: bname = basename(datafile) fname, ext = splitext(bname) if ext != '.csv': self.err("Warning: '%s' doesn't look like a CSV file." % bname) conf = decode(fname) wsscmpctr.add_wss(conf['wss']) wsscmpctr.read_csv(datafile) # assume all files in same directory and same kind of overheads wsscmpctr.write_csv(dirname(datafile), conf) if __name__ == "__main__": usage = "Usage: %prog list-of-file" parser = OptionParser(usage=usage) (options, args) = parser.parse_args() if len(args) < 1: parser.error("Argument missing") sys.exit(-1) main(args)