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
|
#!/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')
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)]:
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 <list of files, _sorted_ by WSS>"
parser = OptionParser(usage=usage)
(options, args) = parser.parse_args()
if len(args) < 1:
parser.error("Argument missing")
sys.exit(-1)
main(args)
|