#!/usr/bin/env python from os.path import splitext, basename, dirname from optparse import OptionParser from plot import decode def build_name(dirname, conf, wss_list): if dirname == '': dirname = '.' outname = dirname + '/' 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('# ' + conf['plugin'] + ' ' + conf['ovd'] + '\n') wstr = '# tssize, ' for wss in self.wss_list: wstr += 'wss=' + str(wss) + ':(max, avg), ' csvf.write(wstr[0:-2] + '\n') for key in sorted(self.ovhead_table.keys(), key=int): wstr = key + ', ' for value in self.ovhead_table[key]: if float(value) > 0: wstr += value + ', ' else: wstr += '0.00000, ' 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 " parser = OptionParser(usage=usage) (options, args) = parser.parse_args() if len(args) < 1: parser.error("Argument missing") sys.exit(-1) main(args)