diff options
author | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-03-21 16:46:51 -0400 |
---|---|---|
committer | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-03-21 16:46:51 -0400 |
commit | e49fb36048adf57c6cd7e65c59af37ad81fba35c (patch) | |
tree | 41be72475dd227abf9769ae8c4f91696b7058b1a | |
parent | 47c9d5df446cd06ae566126135e26cb9279b35f2 (diff) |
Compact csv result files for multiple WSS in single result file
hard_pm_plugin=GSN-EDF_dist=uni_light_wss=1024_ovd=preemption.csv
hard_pm_plugin=GSN-EDF_dist=uni_light_wss=2048_ovd=preemption.csv
hard_pm_plugin=GSN-EDF_dist=uni_light_wss=3072_ovd=preemption.csv
=>
hard_pm_plugin=GSN-EDF_dist=uni_light_wss=1024,2048,3072_ovd=preemption.csv
-rwxr-xr-x | compact_pm_ovd.py | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/compact_pm_ovd.py b/compact_pm_ovd.py new file mode 100755 index 0000000..5024d61 --- /dev/null +++ b/compact_pm_ovd.py | |||
@@ -0,0 +1,111 @@ | |||
1 | #!/usr/bin/env python | ||
2 | |||
3 | from os.path import splitext, basename, dirname | ||
4 | from optparse import OptionParser | ||
5 | |||
6 | def decode(name): | ||
7 | params = {} | ||
8 | parts = name.split('_') | ||
9 | for p in parts: | ||
10 | kv = p.split('=') | ||
11 | k = kv[0] | ||
12 | v = kv[1] if len(kv) > 1 else None | ||
13 | params[k] = v | ||
14 | return params | ||
15 | |||
16 | |||
17 | def build_name(dirname, conf, wss_list): | ||
18 | if dirname == '': | ||
19 | dirname = '.' | ||
20 | outname = dirname + '/' | ||
21 | if 'hard' in conf: | ||
22 | outname += 'hard' | ||
23 | else: | ||
24 | outname += 'soft' | ||
25 | outname += '_pm_plugin=' + conf['plugin'] + '_dist=' + conf['dist'] | ||
26 | # atm we use only uniform for PM (we also use only light, but...) | ||
27 | if 'light' in conf: | ||
28 | outname += '_light' | ||
29 | elif 'medium' in conf: | ||
30 | outname += '_medium' | ||
31 | elif 'heavy' in conf: | ||
32 | outname += '_heavy' | ||
33 | |||
34 | outname += '_wss=' | ||
35 | for wss in wss_list: | ||
36 | if wss != wss_list[len(wss_list) - 1]: | ||
37 | outname += str(wss) + ',' | ||
38 | else: | ||
39 | outname += str(wss) | ||
40 | outname += '_ovd=' + conf['ovd'] + '.csv' | ||
41 | return outname | ||
42 | |||
43 | |||
44 | class WSSCompactor(): | ||
45 | def __init__(self): | ||
46 | self.ovhead_table = {} | ||
47 | self.wss_list = [] | ||
48 | |||
49 | def add_wss(self, wss): | ||
50 | self.wss_list.append(int(wss)) | ||
51 | |||
52 | def read_csv(self, datafile): | ||
53 | csvf = open(datafile, 'r') | ||
54 | # csvf format is: tss, max, avg | ||
55 | for line in csvf: | ||
56 | tmp = line.split(', ') | ||
57 | if tmp[0] in self.ovhead_table.keys(): | ||
58 | self.ovhead_table[tmp[0]] += [tmp[1], tmp[2].rstrip('\n')] | ||
59 | else: | ||
60 | self.ovhead_table[tmp[0]] = [tmp[1], tmp[2].rstrip('\n')] | ||
61 | csvf.close() | ||
62 | |||
63 | def write_csv(self, dirname, conf): | ||
64 | self.wss_list.sort() | ||
65 | outname = build_name(dirname, conf, self.wss_list) | ||
66 | csvf = open(outname, 'w') | ||
67 | csvf.write('# preemption and migration overhead for ' + \ | ||
68 | conf['plugin'] + '\n') | ||
69 | |||
70 | wstr = '# tssize, ' | ||
71 | for wss in self.wss_list: | ||
72 | wstr += 'wss=' + str(wss) + ':(max, avg), ' | ||
73 | csvf.write(wstr[0:-2] + '\n') | ||
74 | |||
75 | tkeys = self.ovhead_table.keys() | ||
76 | for i in range(0,len(tkeys)): | ||
77 | tkeys[i] = int(tkeys[i]) | ||
78 | tkeys.sort() | ||
79 | |||
80 | for key in tkeys: | ||
81 | wstr = str(key) + ', ' | ||
82 | for value in self.ovhead_table[str(key)]: | ||
83 | wstr += value + ', ' | ||
84 | wstr = wstr[0:-2] | ||
85 | csvf.write(wstr + '\n') | ||
86 | |||
87 | csvf.close() | ||
88 | |||
89 | def main(args): | ||
90 | wsscmpctr = WSSCompactor() | ||
91 | for datafile in args: | ||
92 | bname = basename(datafile) | ||
93 | fname, ext = splitext(bname) | ||
94 | if ext != '.csv': | ||
95 | self.err("Warning: '%s' doesn't look like a CSV file." | ||
96 | % bname) | ||
97 | conf = decode(fname) | ||
98 | wsscmpctr.add_wss(conf['wss']) | ||
99 | wsscmpctr.read_csv(datafile) | ||
100 | |||
101 | # assume all files in same directory and same kind of overheads | ||
102 | wsscmpctr.write_csv(dirname(datafile), conf) | ||
103 | |||
104 | if __name__ == "__main__": | ||
105 | usage = "Usage: %prog list-of-file" | ||
106 | parser = OptionParser(usage=usage) | ||
107 | (options, args) = parser.parse_args() | ||
108 | if len(args) < 1: | ||
109 | parser.error("Argument missing") | ||
110 | sys.exit(-1) | ||
111 | main(args) | ||